feat(auth): improve logout process to redirect to Keycloak before clearing user state
All checks were successful
Build & Push Docker Image / build (push) Successful in 6m24s

This commit is contained in:
2026-03-10 22:41:27 +01:00
parent 14ed0c3689
commit 03e484b8c6

View File

@@ -41,18 +41,20 @@ export function AuthProvider({ children }) {
}, []); }, []);
const logout = useCallback(async () => { const logout = useCallback(async () => {
let keycloakLogoutUrl = null;
try { try {
const res = await api.post('/auth/logout'); const res = await api.post('/auth/logout');
localStorage.removeItem('token'); keycloakLogoutUrl = res.data?.keycloakLogoutUrl || null;
setUser(null);
if (res.data?.keycloakLogoutUrl) {
window.location.href = res.data.keycloakLogoutUrl;
return;
}
} catch { } catch {
// ignore — token is removed locally regardless // ignore — token is removed locally regardless
} }
localStorage.removeItem('token'); localStorage.removeItem('token');
if (keycloakLogoutUrl) {
// Redirect to Keycloak BEFORE clearing React state to avoid
// flash-rendering the login page while the redirect is pending.
window.location.href = keycloakLogoutUrl;
return;
}
setUser(null); setUser(null);
}, []); }, []);