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
All checks were successful
Build & Push Docker Image / build (push) Successful in 6m24s
This commit is contained in:
@@ -41,18 +41,20 @@ export function AuthProvider({ children }) {
|
||||
}, []);
|
||||
|
||||
const logout = useCallback(async () => {
|
||||
let keycloakLogoutUrl = null;
|
||||
try {
|
||||
const res = await api.post('/auth/logout');
|
||||
localStorage.removeItem('token');
|
||||
setUser(null);
|
||||
if (res.data?.keycloakLogoutUrl) {
|
||||
window.location.href = res.data.keycloakLogoutUrl;
|
||||
return;
|
||||
}
|
||||
keycloakLogoutUrl = res.data?.keycloakLogoutUrl || null;
|
||||
} catch {
|
||||
// ignore — token is removed locally regardless
|
||||
}
|
||||
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);
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user