From ff5562a573cea1c0650f1cf6054700c7a88fab11 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Sun, 8 Mar 2026 12:11:52 +0530 Subject: [PATCH] style: Enhance ChatHeader responsiveness by adding name truncation and conditional visibility for details. --- src/app/logout/page.tsx | 45 +++++++---------------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/src/app/logout/page.tsx b/src/app/logout/page.tsx index 942efa6..9714831 100644 --- a/src/app/logout/page.tsx +++ b/src/app/logout/page.tsx @@ -3,25 +3,6 @@ import { useEffect, useRef } from 'react'; import { signOut } from 'next-auth/react'; -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}`; - }); -} - export default function LogoutPage() { const hasStarted = useRef(false); @@ -29,31 +10,19 @@ export default function LogoutPage() { if (hasStarted.current) return; hasStarted.current = true; - // Ensure logout flag is set (prevents TokenSync and PresenceProvider from restoring tokens) + // Set logout flag to prevent TokenSync/PresenceProvider from restoring tokens localStorage.setItem('isLoggingOut', 'true'); - // Clear localStorage tokens + // Clear all localStorage auth data localStorage.removeItem('accessToken'); localStorage.removeItem('refreshToken'); localStorage.removeItem('user'); - // 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'; - }; - - // Sign out via NextAuth (clears session cookie), then manually redirect - signOut({ redirect: false }) - .then(redirectToLogin) - .catch(redirectToLogin); - - // Safety fallback - if signOut hangs, redirect after 3 seconds - setTimeout(redirectToLogin, 3000); + // Use signOut with callbackUrl - this ensures the server clears the + // session cookie BEFORE the redirect happens (server-side 302). + // Do NOT use redirect:false + manual redirect, as that causes a race + // condition where navigation happens before the cookie is cleared. + signOut({ callbackUrl: '/login' }); }, []); return (