bugfix: logout behaviour fixed.

This commit is contained in:
2026-04-29 15:55:58 +03:30
parent 063a5faa56
commit 207e7fed75
2 changed files with 53 additions and 5 deletions

View File

@@ -181,11 +181,22 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
}, [router]);
const logout = useCallback(async () => {
localStorage.clear();
setUser(null);
setOrganizations([]);
setCurrentOrganization(null);
router.push('/');
try {
// Important: clear auth cookies/session on the server first,
// otherwise middleware may still treat the user as authenticated.
await authApi.logout();
} catch (err) {
console.error('Logout API failed:', err);
} finally {
localStorage.clear();
setUser(null);
setOrganizations([]);
setCurrentOrganization(null);
setError(null);
setIsAuthReady(true);
router.replace('/');
router.refresh();
}
}, [router]);
const selectOrganization = useCallback(async (orgId: string) => {