This commit is contained in:
yohlo
2026-02-14 15:46:31 -06:00
parent 6e9e014fcc
commit 7f60b4d200

View File

@@ -103,23 +103,35 @@ export const Route = createRootRouteWithContext<{
component: RootComponent,
notFoundComponent: () => <Navigate to="/" />,
beforeLoad: async ({ context, location }) => {
// Skip auth check for refresh-session route to avoid infinite loops
if (location.pathname === '/refresh-session') {
return {};
}
if (location.pathname === '/login' || location.pathname === '/logout') {
const publicRoutes = ['/login', '/logout', '/refresh-session'];
if (publicRoutes.some(route => location.pathname.startsWith(route))) {
return {};
}
try {
// https://github.com/TanStack/router/discussions/3531
const auth = await ensureServerQueryData(
context.queryClient,
playerQueries.auth()
);
return { auth };
} catch (error) {
} catch (error: any) {
if (typeof window !== 'undefined') {
const { doesSessionExist, attemptRefreshingSession } = await import('supertokens-web-js/recipe/session');
const sessionExists = await doesSessionExist();
if (sessionExists) {
try {
await attemptRefreshingSession();
const auth = await ensureServerQueryData(
context.queryClient,
playerQueries.auth()
);
return { auth };
} catch {
return {};
}
}
}
return {};
}
},