fix: types of nj15
This commit is contained in:
@@ -67,12 +67,13 @@ export class AuthServerService {
|
||||
return true;
|
||||
}
|
||||
|
||||
static setUserCookie(userData: UserData): void {
|
||||
static async setUserCookie(userData: UserData): Promise<void> {
|
||||
// Encode user data in base64
|
||||
const encodedUserData = Buffer.from(JSON.stringify(userData)).toString("base64");
|
||||
|
||||
// Set cookie with user data
|
||||
cookies().set("stripUser", encodedUserData, {
|
||||
const cookieStore = await cookies();
|
||||
cookieStore.set("stripUser", encodedUserData, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
sameSite: "lax",
|
||||
@@ -81,8 +82,9 @@ export class AuthServerService {
|
||||
});
|
||||
}
|
||||
|
||||
static getCurrentUser(): UserData | null {
|
||||
const userCookie = cookies().get("stripUser");
|
||||
static async getCurrentUser(): Promise<UserData | null> {
|
||||
const cookieStore = await cookies();
|
||||
const userCookie = cookieStore.get("stripUser");
|
||||
|
||||
if (!userCookie) {
|
||||
return null;
|
||||
|
||||
@@ -8,8 +8,8 @@ import { AppError } from "../../utils/errors";
|
||||
import type { User, KomgaConfigData, TTLConfigData, KomgaConfig, TTLConfig } from "@/types/komga";
|
||||
|
||||
export class ConfigDBService {
|
||||
private static getCurrentUser(): User {
|
||||
const user: User | null = AuthServerService.getCurrentUser();
|
||||
private static async getCurrentUser(): Promise<User> {
|
||||
const user: User | null = await AuthServerService.getCurrentUser();
|
||||
if (!user) {
|
||||
throw new AppError(ERROR_CODES.AUTH.UNAUTHENTICATED);
|
||||
}
|
||||
@@ -18,7 +18,7 @@ export class ConfigDBService {
|
||||
|
||||
static async saveConfig(data: KomgaConfigData): Promise<KomgaConfig> {
|
||||
try {
|
||||
const user: User | null = this.getCurrentUser();
|
||||
const user: User | null = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
const authHeader: string = Buffer.from(`${data.username}:${data.password}`).toString(
|
||||
@@ -51,7 +51,7 @@ export class ConfigDBService {
|
||||
|
||||
static async getConfig(): Promise<KomgaConfig | null> {
|
||||
try {
|
||||
const user: User | null = this.getCurrentUser();
|
||||
const user: User | null = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
return DebugService.measureMongoOperation("getConfig", async () => {
|
||||
@@ -68,7 +68,7 @@ export class ConfigDBService {
|
||||
|
||||
static async getTTLConfig(): Promise<TTLConfig | null> {
|
||||
try {
|
||||
const user: User | null = this.getCurrentUser();
|
||||
const user: User | null = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
return DebugService.measureMongoOperation("getTTLConfig", async () => {
|
||||
@@ -85,7 +85,7 @@ export class ConfigDBService {
|
||||
|
||||
static async saveTTLConfig(data: TTLConfigData): Promise<TTLConfig> {
|
||||
try {
|
||||
const user: User | null = this.getCurrentUser();
|
||||
const user: User | null = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
return DebugService.measureMongoOperation("saveTTLConfig", async () => {
|
||||
|
||||
@@ -25,8 +25,8 @@ export interface RequestTiming {
|
||||
}
|
||||
|
||||
export class DebugService {
|
||||
private static getCurrentUserId(): string {
|
||||
const user = AuthServerService.getCurrentUser();
|
||||
private static async getCurrentUserId(): Promise<string> {
|
||||
const user = await AuthServerService.getCurrentUser();
|
||||
if (!user) {
|
||||
throw new AppError(ERROR_CODES.AUTH.UNAUTHENTICATED);
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ export class FavoriteService {
|
||||
}
|
||||
}
|
||||
|
||||
private static getCurrentUser(): User {
|
||||
const user = AuthServerService.getCurrentUser();
|
||||
private static async getCurrentUser(): Promise<User> {
|
||||
const user = await AuthServerService.getCurrentUser();
|
||||
if (!user) {
|
||||
throw new AppError(ERROR_CODES.AUTH.UNAUTHENTICATED);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ export class FavoriteService {
|
||||
*/
|
||||
static async isFavorite(seriesId: string): Promise<boolean> {
|
||||
try {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
return DebugService.measureMongoOperation("isFavorite", async () => {
|
||||
@@ -50,7 +50,7 @@ export class FavoriteService {
|
||||
*/
|
||||
static async addToFavorites(seriesId: string): Promise<void> {
|
||||
try {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
await DebugService.measureMongoOperation("addToFavorites", async () => {
|
||||
@@ -72,7 +72,7 @@ export class FavoriteService {
|
||||
*/
|
||||
static async removeFromFavorites(seriesId: string): Promise<void> {
|
||||
try {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
await DebugService.measureMongoOperation("removeFromFavorites", async () => {
|
||||
@@ -92,7 +92,7 @@ export class FavoriteService {
|
||||
* Récupère tous les IDs des séries favorites
|
||||
*/
|
||||
static async getAllFavoriteIds(): Promise<string[]> {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
return DebugService.measureMongoOperation("getAllFavoriteIds", async () => {
|
||||
@@ -102,7 +102,7 @@ export class FavoriteService {
|
||||
}
|
||||
|
||||
static async addFavorite(seriesId: string) {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
return DebugService.measureMongoOperation("addFavorite", async () => {
|
||||
@@ -116,7 +116,7 @@ export class FavoriteService {
|
||||
}
|
||||
|
||||
static async removeFavorite(seriesId: string): Promise<boolean> {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
return DebugService.measureMongoOperation("removeFavorite", async () => {
|
||||
|
||||
@@ -2,13 +2,13 @@ import { PreferencesModel } from "@/lib/models/preferences.model";
|
||||
import { AuthServerService } from "./auth-server.service";
|
||||
import { ERROR_CODES } from "../../constants/errorCodes";
|
||||
import { AppError } from "../../utils/errors";
|
||||
import type { UserPreferences} from "@/types/preferences";
|
||||
import type { UserPreferences } from "@/types/preferences";
|
||||
import { defaultPreferences } from "@/types/preferences";
|
||||
import type { User } from "@/types/komga";
|
||||
|
||||
export class PreferencesService {
|
||||
static getCurrentUser(): User {
|
||||
const user = AuthServerService.getCurrentUser();
|
||||
static async getCurrentUser(): Promise<User> {
|
||||
const user = await AuthServerService.getCurrentUser();
|
||||
if (!user) {
|
||||
throw new AppError(ERROR_CODES.AUTH.UNAUTHENTICATED);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ export class PreferencesService {
|
||||
|
||||
static async getPreferences(): Promise<UserPreferences> {
|
||||
try {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
const preferences = await PreferencesModel.findOne({ userId: user.id });
|
||||
if (!preferences) {
|
||||
return defaultPreferences;
|
||||
@@ -36,7 +36,7 @@ export class PreferencesService {
|
||||
|
||||
static async updatePreferences(preferences: Partial<UserPreferences>): Promise<UserPreferences> {
|
||||
try {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
const updatedPreferences = await PreferencesModel.findOneAndUpdate(
|
||||
{ userId: user.id },
|
||||
{ $set: preferences },
|
||||
|
||||
Reference in New Issue
Block a user