2026-02-18 00:50:38 +05:30
|
|
|
'use client';
|
|
|
|
|
|
2026-03-08 01:55:46 +05:30
|
|
|
import { useEffect, useRef } from 'react';
|
2026-02-18 00:50:38 +05:30
|
|
|
import { signOut } from 'next-auth/react';
|
|
|
|
|
|
2026-03-08 12:06:07 +05:30
|
|
|
function clearAuthCookies() {
|
|
|
|
|
// Clear next-auth v5 (Auth.js) and v4 session cookies directly
|
|
|
|
|
const cookieNames = [
|
|
|
|
|
'authjs.session-token',
|
|
|
|
|
'__Secure-authjs.session-token',
|
|
|
|
|
'authjs.callback-url',
|
|
|
|
|
'authjs.csrf-token',
|
|
|
|
|
'next-auth.session-token',
|
|
|
|
|
'__Secure-next-auth.session-token',
|
|
|
|
|
'next-auth.callback-url',
|
|
|
|
|
'next-auth.csrf-token',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
cookieNames.forEach((name) => {
|
|
|
|
|
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
|
|
|
|
|
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=${window.location.hostname}`;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-18 00:50:38 +05:30
|
|
|
export default function LogoutPage() {
|
2026-03-08 01:55:46 +05:30
|
|
|
const hasStarted = useRef(false);
|
|
|
|
|
|
2026-02-18 00:50:38 +05:30
|
|
|
useEffect(() => {
|
2026-03-08 01:55:46 +05:30
|
|
|
if (hasStarted.current) return;
|
|
|
|
|
hasStarted.current = true;
|
|
|
|
|
|
2026-03-08 12:06:07 +05:30
|
|
|
// Ensure logout flag is set (prevents TokenSync and PresenceProvider from restoring tokens)
|
|
|
|
|
localStorage.setItem('isLoggingOut', 'true');
|
|
|
|
|
|
2026-02-18 00:50:38 +05:30
|
|
|
// Clear localStorage tokens
|
|
|
|
|
localStorage.removeItem('accessToken');
|
|
|
|
|
localStorage.removeItem('refreshToken');
|
|
|
|
|
localStorage.removeItem('user');
|
|
|
|
|
|
2026-03-08 12:06:07 +05:30
|
|
|
// Clear auth cookies directly as a robust backup
|
|
|
|
|
clearAuthCookies();
|
|
|
|
|
|
|
|
|
|
const redirectToLogin = () => {
|
|
|
|
|
clearAuthCookies();
|
|
|
|
|
// Clear the logout flag right before redirecting
|
|
|
|
|
localStorage.removeItem('isLoggingOut');
|
|
|
|
|
window.location.href = '/login';
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-08 01:55:46 +05:30
|
|
|
// Sign out via NextAuth (clears session cookie), then manually redirect
|
|
|
|
|
signOut({ redirect: false })
|
2026-03-08 12:06:07 +05:30
|
|
|
.then(redirectToLogin)
|
|
|
|
|
.catch(redirectToLogin);
|
2026-03-08 01:55:46 +05:30
|
|
|
|
|
|
|
|
// Safety fallback - if signOut hangs, redirect after 3 seconds
|
2026-03-08 12:06:07 +05:30
|
|
|
setTimeout(redirectToLogin, 3000);
|
2026-02-18 00:50:38 +05:30
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="min-h-screen flex items-center justify-center bg-white">
|
|
|
|
|
<div className="text-center">
|
|
|
|
|
<div className="w-12 h-12 border-4 border-[#e58625] border-t-transparent rounded-full animate-spin mx-auto mb-6" />
|
|
|
|
|
<h1 className="font-fractul font-bold text-[24px] text-[#00293D] mb-2">
|
|
|
|
|
Signing Out
|
|
|
|
|
</h1>
|
|
|
|
|
<p className="font-serif text-[14px] text-[#00293D]/60">
|
|
|
|
|
Please wait while we securely log you out...
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|