From 7f60b4d2005b7ca7634bb459c7586004da077d8a Mon Sep 17 00:00:00 2001 From: yohlo Date: Sat, 14 Feb 2026 15:46:31 -0600 Subject: [PATCH] idk --- src/app/routes/__root.tsx | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/app/routes/__root.tsx b/src/app/routes/__root.tsx index 64f63ff..c8d541a 100644 --- a/src/app/routes/__root.tsx +++ b/src/app/routes/__root.tsx @@ -103,23 +103,35 @@ export const Route = createRootRouteWithContext<{ component: RootComponent, notFoundComponent: () => , 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 {}; } },