refresh progress

This commit is contained in:
2025-08-31 10:23:18 -05:00
parent b7d14be590
commit 07388e30da
7 changed files with 146 additions and 51 deletions

View File

@@ -0,0 +1,39 @@
import { createFileRoute } from '@tanstack/react-router'
import { useEffect } from 'react'
import FullScreenLoader from '@/components/full-screen-loader'
import { attemptRefreshingSession } from 'supertokens-web-js/recipe/session'
export const Route = createFileRoute('/refresh-session')({
component: RouteComponent,
})
// https://supertokens.com/docs/additional-verification/session-verification/ssr?uiType=custom
function RouteComponent() {
useEffect(() => {
const handleRefresh = async () => {
try {
const refreshed = await attemptRefreshingSession()
if (refreshed) {
const urlParams = new URLSearchParams(window.location.search)
const redirect = urlParams.get('redirect')
if (redirect) {
window.location.href = decodeURIComponent(redirect)
} else {
window.location.href = '/'
}
} else {
window.location.href = '/login'
}
} catch (error) {
window.location.href = '/login'
}
}
const timeout = setTimeout(handleRefresh, 100)
return () => clearTimeout(timeout)
}, [])
return <FullScreenLoader />
}