more auth ree
This commit is contained in:
@@ -4,7 +4,6 @@ import {
|
||||
Outlet,
|
||||
Scripts,
|
||||
createRootRouteWithContext,
|
||||
redirect,
|
||||
} from "@tanstack/react-router";
|
||||
import * as React from "react";
|
||||
import { DefaultCatchBoundary } from "@/components/DefaultCatchBoundary";
|
||||
@@ -133,15 +132,6 @@ export const Route = createRootRouteWithContext<{
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (error instanceof Response && error.status === 440) {
|
||||
console.log('__root beforeLoad: Session needs refresh, redirecting');
|
||||
const from = encodeURIComponent(location.pathname + location.search);
|
||||
throw redirect({
|
||||
to: "/refresh-session",
|
||||
search: { redirect: from }
|
||||
});
|
||||
}
|
||||
|
||||
console.error('__root beforeLoad error:', error);
|
||||
return {};
|
||||
}
|
||||
@@ -152,6 +142,32 @@ export const Route = createRootRouteWithContext<{
|
||||
function RootComponent() {
|
||||
React.useEffect(() => {
|
||||
ensureSuperTokensFrontend();
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
const cookies = document.cookie.split(';');
|
||||
const accessTokenCookies = cookies.filter(c => c.trim().startsWith('sAccessToken='));
|
||||
|
||||
if (accessTokenCookies.length > 1) {
|
||||
console.warn(`[Root] Found ${accessTokenCookies.length} duplicate sAccessToken cookies - clearing all 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}`;
|
||||
}
|
||||
});
|
||||
|
||||
console.log('[Root] Cleared duplicate cookies - page will reload to establish fresh session');
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user