diff --git a/src/components/debug/DebugWrapper.tsx b/src/components/debug/DebugWrapper.tsx
new file mode 100644
index 0000000..0aa0fe9
--- /dev/null
+++ b/src/components/debug/DebugWrapper.tsx
@@ -0,0 +1,14 @@
+"use client";
+
+import { usePreferences } from "@/contexts/PreferencesContext";
+import { DebugInfo } from "./DebugInfo";
+
+export function DebugWrapper() {
+ const { preferences } = usePreferences();
+
+ if (!preferences.debug) {
+ return null;
+ }
+
+ return ;
+}
diff --git a/src/lib/services/config-db.service.ts b/src/lib/services/config-db.service.ts
index cb66977..d9abfe7 100644
--- a/src/lib/services/config-db.service.ts
+++ b/src/lib/services/config-db.service.ts
@@ -1,7 +1,7 @@
-import { cookies } from "next/headers";
import connectDB from "@/lib/mongodb";
import { KomgaConfig } from "@/lib/models/config.model";
import { TTLConfig } from "@/lib/models/ttl-config.model";
+import { AuthServerService } from "./auth-server.service";
interface User {
id: string;
@@ -24,23 +24,16 @@ interface TTLConfigData {
}
export class ConfigDBService {
- private static async getCurrentUser(): Promise {
- const userCookie = cookies().get("stripUser");
-
- if (!userCookie) {
- throw new Error("Utilisateur non authentifié");
- }
-
- try {
- return JSON.parse(atob(userCookie.value));
- } catch (error) {
- console.error("Erreur lors de la récupération de l'utilisateur depuis le cookie:", error);
+ private static getCurrentUser(): User {
+ const user = AuthServerService.getCurrentUser();
+ if (!user) {
throw new Error("Utilisateur non authentifié");
}
+ return user;
}
static async saveConfig(data: KomgaConfigData) {
- const user = await this.getCurrentUser();
+ const user = this.getCurrentUser();
await connectDB();
const config = await KomgaConfig.findOneAndUpdate(
@@ -58,7 +51,7 @@ export class ConfigDBService {
}
static async getConfig() {
- const user = await this.getCurrentUser();
+ const user = this.getCurrentUser();
await connectDB();
const config = await KomgaConfig.findOne({ userId: user.id });
@@ -71,7 +64,7 @@ export class ConfigDBService {
}
static async saveTTLConfig(data: TTLConfigData) {
- const user = await this.getCurrentUser();
+ const user = this.getCurrentUser();
await connectDB();
const config = await TTLConfig.findOneAndUpdate(
@@ -87,7 +80,7 @@ export class ConfigDBService {
}
static async getTTLConfig() {
- const user = await this.getCurrentUser();
+ const user = this.getCurrentUser();
await connectDB();
const config = await TTLConfig.findOne({ userId: user.id });
diff --git a/src/lib/services/favorite.service.ts b/src/lib/services/favorite.service.ts
index ae18c64..d45cde5 100644
--- a/src/lib/services/favorite.service.ts
+++ b/src/lib/services/favorite.service.ts
@@ -1,6 +1,6 @@
-import { cookies } from "next/headers";
import connectDB from "@/lib/mongodb";
import { FavoriteModel } from "@/lib/models/favorite.model";
+import { AuthServerService } from "./auth-server.service";
interface User {
id: string;
@@ -17,19 +17,12 @@ export class FavoriteService {
}
}
- private static async getCurrentUser(): Promise {
- const userCookie = cookies().get("stripUser");
-
- if (!userCookie) {
- throw new Error("Utilisateur non authentifié");
- }
-
- try {
- return JSON.parse(atob(userCookie.value));
- } catch (error) {
- console.error("Erreur lors de la récupération de l'utilisateur depuis le cookie:", error);
+ private static getCurrentUser(): User {
+ const user = AuthServerService.getCurrentUser();
+ if (!user) {
throw new Error("Utilisateur non authentifié");
}
+ return user;
}
/**
@@ -37,7 +30,7 @@ export class FavoriteService {
*/
static async isFavorite(seriesId: string): Promise {
try {
- const user = await this.getCurrentUser();
+ const user = this.getCurrentUser();
await connectDB();
const favorite = await FavoriteModel.findOne({
@@ -57,7 +50,7 @@ export class FavoriteService {
*/
static async addToFavorites(seriesId: string): Promise {
try {
- const user = await this.getCurrentUser();
+ const user = this.getCurrentUser();
await connectDB();
await FavoriteModel.findOneAndUpdate(
@@ -78,7 +71,7 @@ export class FavoriteService {
*/
static async removeFromFavorites(seriesId: string): Promise {
try {
- const user = await this.getCurrentUser();
+ const user = this.getCurrentUser();
await connectDB();
await FavoriteModel.findOneAndDelete({
@@ -98,7 +91,7 @@ export class FavoriteService {
*/
static async getAllFavoriteIds(): Promise {
try {
- const user = await this.getCurrentUser();
+ const user = this.getCurrentUser();
await connectDB();
const favorites = await FavoriteModel.find({ userId: user.id });
diff --git a/src/lib/services/preferences.service.ts b/src/lib/services/preferences.service.ts
index 6dc2c44..6658e48 100644
--- a/src/lib/services/preferences.service.ts
+++ b/src/lib/services/preferences.service.ts
@@ -1,5 +1,5 @@
-import { cookies } from "next/headers";
import { PreferencesModel } from "@/lib/models/preferences.model";
+import { AuthServerService } from "./auth-server.service";
interface User {
id: string;
@@ -21,24 +21,17 @@ const defaultPreferences: UserPreferences = {
};
export class PreferencesService {
- static async getCurrentUser(): Promise {
- const userCookie = cookies().get("stripUser");
-
- if (!userCookie) {
- throw new Error("Utilisateur non authentifié");
- }
-
- try {
- return JSON.parse(atob(userCookie.value));
- } catch (error) {
- console.error("Erreur lors de la récupération de l'utilisateur depuis le cookie:", error);
+ static getCurrentUser(): User {
+ const user = AuthServerService.getCurrentUser();
+ if (!user) {
throw new Error("Utilisateur non authentifié");
}
+ return user;
}
static async getPreferences(): Promise {
try {
- const user = await this.getCurrentUser();
+ const user = this.getCurrentUser();
const preferences = await PreferencesModel.findOne({ userId: user.id });
if (!preferences) {
return defaultPreferences;
@@ -55,7 +48,7 @@ export class PreferencesService {
static async updatePreferences(preferences: Partial): Promise {
try {
- const user = await this.getCurrentUser();
+ const user = this.getCurrentUser();
const updatedPreferences = await PreferencesModel.findOneAndUpdate(
{ userId: user.id },
{ $set: preferences },