diff --git a/src/components/layout/Sidebar.tsx b/src/components/layout/Sidebar.tsx index 971300f..8ba0b20 100644 --- a/src/components/layout/Sidebar.tsx +++ b/src/components/layout/Sidebar.tsx @@ -15,9 +15,22 @@ export function Sidebar({ isOpen }: SidebarProps) { const router = useRouter(); const [libraries, setLibraries] = useState([]); const [isLoading, setIsLoading] = useState(true); + const [isAuthenticated, setIsAuthenticated] = useState(false); useEffect(() => { + // Vérifier si l'utilisateur est authentifié + const checkAuth = () => { + const isAuth = authService.isAuthenticated(); + setIsAuthenticated(isAuth); + return isAuth; + }; + const fetchLibraries = async () => { + if (!checkAuth()) { + setIsLoading(false); + return; + } + try { const response = await fetch("/api/komga/libraries"); if (!response.ok) { @@ -33,10 +46,12 @@ export function Sidebar({ isOpen }: SidebarProps) { }; fetchLibraries(); - }, []); + }, [pathname]); // Recharger quand le pathname change pour gérer la déconnexion const handleLogout = () => { authService.logout(); + setIsAuthenticated(false); + setLibraries([]); router.push("/login"); }; @@ -78,58 +93,63 @@ export function Sidebar({ isOpen }: SidebarProps) { -
-
-

Bibliothèques

- {isLoading ? ( -
Chargement...
- ) : libraries.length === 0 ? ( -
Aucune bibliothèque
- ) : ( - libraries.map((library) => ( + {isAuthenticated && ( + <> +
+
+

Bibliothèques

+ {isLoading ? ( +
Chargement...
+ ) : libraries.length === 0 ? ( +
Aucune bibliothèque
+ ) : ( + libraries.map((library) => ( + + + {library.name} + + )) + )} +
+
+ +
+
+

Configuration

- - {library.name} + + Préférences - )) - )} -
-
- -
-
-

Configuration

- - - Préférences - -
-
+
+
+ + )} - {/* Bouton de déconnexion */} -
- -
+ {isAuthenticated && ( +
+ +
+ )} ); }