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 () => {
|
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);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user