fix: ne pas charger les bibliothèques dans la sidebar en mode déconnecté
This commit is contained in:
@@ -15,9 +15,22 @@ export function Sidebar({ isOpen }: SidebarProps) {
|
||||
const router = useRouter();
|
||||
const [libraries, setLibraries] = useState<KomgaLibrary[]>([]);
|
||||
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,6 +93,8 @@ export function Sidebar({ isOpen }: SidebarProps) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isAuthenticated && (
|
||||
<>
|
||||
<div className="px-3 py-2">
|
||||
<div className="space-y-1">
|
||||
<h2 className="mb-2 px-4 text-lg font-semibold tracking-tight">Bibliothèques</h2>
|
||||
@@ -118,9 +135,11 @@ export function Sidebar({ isOpen }: SidebarProps) {
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Bouton de déconnexion */}
|
||||
{isAuthenticated && (
|
||||
<div className="p-3 border-t border-border/40">
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
@@ -130,6 +149,7 @@ export function Sidebar({ isOpen }: SidebarProps) {
|
||||
Se déconnecter
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user