feat: Introduce a dedicated logout page for consistent token and session invalidation across the application.

This commit is contained in:
pradeepkumar
2026-02-18 00:50:38 +05:30
parent cb76eb6488
commit 3d2171e0bb
3 changed files with 34 additions and 3 deletions

30
src/app/logout/page.tsx Normal file
View File

@@ -0,0 +1,30 @@
'use client';
import { useEffect } from 'react';
import { signOut } from 'next-auth/react';
export default function LogoutPage() {
useEffect(() => {
// Clear localStorage tokens
localStorage.removeItem('accessToken');
localStorage.removeItem('refreshToken');
localStorage.removeItem('user');
// Sign out via NextAuth (clears session cookie) and redirect to login
signOut({ callbackUrl: '/login', redirect: true });
}, []);
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>
);
}

View File

@@ -5,7 +5,7 @@ import { NextResponse } from "next/server";
const authRoutes = ["/login", "/signup", "/forgot-password", "/reset-password", "/verify-email"];
// Public routes - accessible to everyone (logged in or not)
const publicRoutes = ["/", "/contact", "/about", "/faq", "/user/dashboard", "/user/profiles", "/user/profile"];
const publicRoutes = ["/", "/contact", "/about", "/faq", "/logout", "/user/dashboard", "/user/profiles", "/user/profile"];
export default auth((req) => {
const { nextUrl } = req;

View File

@@ -28,7 +28,7 @@ let failedQueue: Array<{
config: InternalAxiosRequestConfig;
}> = [];
// Force logout: clear all tokens and redirect to login
// Force logout: clear all tokens and redirect to logout page
const forceLogout = () => {
if (isLoggingOut) return; // Prevent multiple redirects
isLoggingOut = true;
@@ -36,7 +36,8 @@ const forceLogout = () => {
localStorage.removeItem('accessToken');
localStorage.removeItem('refreshToken');
localStorage.removeItem('user');
window.location.href = '/api/auth/signout?callbackUrl=/login';
// Redirect to /logout page which properly clears NextAuth session
window.location.href = '/logout';
}
};