session fixes
This commit is contained in:
@@ -11,6 +11,7 @@ import { type QueryClient } from "@tanstack/react-query";
|
||||
import { ensureSuperTokensFrontend } from "@/lib/supertokens/client";
|
||||
import { AuthContextType } from "@/contexts/auth-context";
|
||||
import Providers from "@/features/core/components/providers";
|
||||
import { SessionMonitor } from "@/components/session-monitor";
|
||||
import { ColorSchemeScript, mantineHtmlProps } from "@mantine/core";
|
||||
import { HeaderConfig } from "@/features/core/types/header-config";
|
||||
import { playerQueries } from "@/features/players/queries";
|
||||
@@ -126,6 +127,7 @@ function RootComponent() {
|
||||
return (
|
||||
<RootDocument>
|
||||
<Providers>
|
||||
<SessionMonitor />
|
||||
<Outlet />
|
||||
</Providers>
|
||||
</RootDocument>
|
||||
|
||||
@@ -2,7 +2,8 @@ import { createFileRoute } from '@tanstack/react-router'
|
||||
import { useEffect, useRef } from 'react'
|
||||
import FullScreenLoader from '@/components/full-screen-loader'
|
||||
import { attemptRefreshingSession } from 'supertokens-web-js/recipe/session'
|
||||
import { resetRefreshFlag } from '@/lib/supertokens/client'
|
||||
import { resetRefreshFlag, getOrCreateRefreshPromise } from '@/lib/supertokens/client'
|
||||
import { logger } from '@/lib/supertokens'
|
||||
|
||||
export const Route = createFileRoute('/refresh-session')({
|
||||
component: RouteComponent,
|
||||
@@ -17,23 +18,31 @@ function RouteComponent() {
|
||||
|
||||
const handleRefresh = async () => {
|
||||
try {
|
||||
resetRefreshFlag();
|
||||
const refreshed = await attemptRefreshingSession()
|
||||
logger.info("Refresh session route: starting refresh");
|
||||
|
||||
const refreshed = await getOrCreateRefreshPromise(async () => {
|
||||
return await attemptRefreshingSession();
|
||||
});
|
||||
|
||||
if (refreshed) {
|
||||
const urlParams = new URLSearchParams(window.location.search)
|
||||
const redirect = urlParams.get('redirect')
|
||||
logger.info("Refresh session route: refresh successful");
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const redirect = urlParams.get('redirect');
|
||||
|
||||
if (redirect && !redirect.includes('_serverFn') && !redirect.includes('/api/')) {
|
||||
window.location.href = decodeURIComponent(redirect)
|
||||
logger.info("Refresh session route: redirecting to", redirect);
|
||||
window.location.href = decodeURIComponent(redirect);
|
||||
} else {
|
||||
logger.info("Refresh session route: redirecting to home");
|
||||
window.location.href = '/';
|
||||
}
|
||||
} else {
|
||||
window.location.href = '/login'
|
||||
logger.warn("Refresh session route: refresh failed, redirecting to login");
|
||||
window.location.href = '/login';
|
||||
}
|
||||
} catch (error) {
|
||||
window.location.href = '/login'
|
||||
logger.error("Refresh session route: error during refresh", error);
|
||||
window.location.href = '/login';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user