regionals #5
@@ -103,23 +103,35 @@ export const Route = createRootRouteWithContext<{
|
|||||||
component: RootComponent,
|
component: RootComponent,
|
||||||
notFoundComponent: () => <Navigate to="/" />,
|
notFoundComponent: () => <Navigate to="/" />,
|
||||||
beforeLoad: async ({ context, location }) => {
|
beforeLoad: async ({ context, location }) => {
|
||||||
// Skip auth check for refresh-session route to avoid infinite loops
|
const publicRoutes = ['/login', '/logout', '/refresh-session'];
|
||||||
if (location.pathname === '/refresh-session') {
|
if (publicRoutes.some(route => location.pathname.startsWith(route))) {
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (location.pathname === '/login' || location.pathname === '/logout') {
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// https://github.com/TanStack/router/discussions/3531
|
|
||||||
const auth = await ensureServerQueryData(
|
const auth = await ensureServerQueryData(
|
||||||
context.queryClient,
|
context.queryClient,
|
||||||
playerQueries.auth()
|
playerQueries.auth()
|
||||||
);
|
);
|
||||||
return { 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 {};
|
return {};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user