diff --git a/src/app/routes/login.tsx b/src/app/routes/login.tsx index bca5592..0404651 100644 --- a/src/app/routes/login.tsx +++ b/src/app/routes/login.tsx @@ -2,6 +2,7 @@ import LoginLayout from "@/features/login/components/layout"; import LoginFlow from "@/features/login/components/login-flow"; import { redirect, createFileRoute } from "@tanstack/react-router"; import z from "zod"; +import { useEffect } from "react"; const loginSearchSchema = z.object({ stage: z.enum(["code", "name"]).optional(), @@ -9,6 +10,36 @@ const loginSearchSchema = z.object({ callback: z.string().optional(), }); +function LoginComponent() { + useEffect(() => { + if (typeof window !== 'undefined') { + const cookies = document.cookie.split(';'); + const accessTokenCookies = cookies.filter(c => c.trim().startsWith('sAccessToken=')); + + if (accessTokenCookies.length > 0) { + console.log('[Login] Clearing old SuperTokens cookies'); + + const cookieNames = ['sAccessToken', 'sRefreshToken', 'sIdRefreshToken', 'sFrontToken']; + const cookieDomain = (window as any).__COOKIE_DOMAIN__ || undefined; + + cookieNames.forEach(name => { + document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`; + + if (cookieDomain) { + document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=${cookieDomain}`; + } + }); + } + } + }, []); + + return ( + + + + ); +} + export const Route = createFileRoute("/login")({ validateSearch: loginSearchSchema, beforeLoad: async ({ context }) => { @@ -16,11 +47,5 @@ export const Route = createFileRoute("/login")({ throw redirect({ to: "/" }); } }, - component: () => { - return ( - - - - ); - }, + component: LoginComponent, });