fix: Prevent redundant logout redirects and synchronously clear authentication tokens on the logout page.
This commit is contained in:
@@ -8,13 +8,19 @@ import Image from 'next/image';
|
||||
export default function LogoutPage() {
|
||||
const hasStarted = useRef(false);
|
||||
|
||||
// Set logout flag synchronously on render to block API interceptor immediately
|
||||
if (typeof window !== 'undefined') {
|
||||
localStorage.setItem('isLoggingOut', 'true');
|
||||
localStorage.removeItem('accessToken');
|
||||
localStorage.removeItem('refreshToken');
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (hasStarted.current) return;
|
||||
hasStarted.current = true;
|
||||
|
||||
const performLogout = async () => {
|
||||
// Clear localStorage
|
||||
localStorage.setItem('isLoggingOut', 'true');
|
||||
localStorage.removeItem('accessToken');
|
||||
localStorage.removeItem('refreshToken');
|
||||
localStorage.removeItem('user');
|
||||
|
||||
@@ -37,8 +37,11 @@ export const resetLogoutState = () => {
|
||||
// Force logout: redirect to /logout page which handles everything
|
||||
const forceLogout = () => {
|
||||
if (isLoggingOut) return;
|
||||
isLoggingOut = true;
|
||||
if (typeof window !== 'undefined') {
|
||||
// Don't redirect to /logout if we're already on it or on /login
|
||||
const path = window.location.pathname;
|
||||
if (path === '/logout' || path === '/login') return;
|
||||
isLoggingOut = true;
|
||||
localStorage.setItem('isLoggingOut', 'true');
|
||||
window.location.href = '/logout';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user