1- import { createFileRoute } from '@tanstack/react-router'
1+ import { createFileRoute , useNavigate } from '@tanstack/react-router'
22import { useAuth } from '@workos-inc/authkit-react'
33import { useEffect , useState } from 'react'
44
@@ -9,6 +9,7 @@ export const Route = createFileRoute('/auth/callback')({
99function AuthCallback ( ) {
1010 const { user, isLoading } = useAuth ( )
1111 const [ error , setError ] = useState < string | null > ( null )
12+ const navigate = useNavigate ( )
1213
1314 useEffect ( ( ) => {
1415 // Check for error in URL
@@ -21,9 +22,13 @@ function AuthCallback() {
2122 return
2223 }
2324
24- // If we have a user, redirect to dashboard
25+ // If we have a user, redirect to dashboard using client-side navigation
26+ // This preserves the session state without a full page reload
2527 if ( ! isLoading && user ) {
26- window . location . href = '/dashboard'
28+ // Small delay to ensure session is fully saved
29+ setTimeout ( ( ) => {
30+ navigate ( { to : '/dashboard' } )
31+ } , 100 )
2732 return
2833 }
2934
@@ -32,11 +37,11 @@ function AuthCallback() {
3237 const code = params . get ( 'code' )
3338 if ( ! code ) {
3439 setTimeout ( ( ) => {
35- window . location . href = '/'
40+ navigate ( { to : '/' } )
3641 } , 2000 )
3742 }
3843 }
39- } , [ user , isLoading ] )
44+ } , [ user , isLoading , navigate ] )
4045
4146 if ( error ) {
4247 return (
0 commit comments