feat: Centralize authentication redirects to middleware, remove client-side redirect logic, and refine logout process.

This commit is contained in:
pradeepkumar
2026-03-10 09:28:19 +05:30
parent 69eff70fbb
commit c7f1b89203
9 changed files with 77 additions and 70 deletions

View File

@@ -9,10 +9,11 @@ function TokenSync() {
const hasInitialized = useRef(false);
useEffect(() => {
// Never restore tokens if a logout is in progress
// Never restore tokens if a logout is in progress or we're on the logout page
const loggingOut = localStorage.getItem("isLoggingOut") === "true";
const onLogoutPage = window.location.pathname === "/logout";
if (status === "authenticated" && session?.user && !loggingOut) {
if (status === "authenticated" && session?.user && !loggingOut && !onLogoutPage) {
const user = session.user as { accessToken?: string; refreshToken?: string };
// Only sync tokens from NextAuth to localStorage if: