File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import { useSession } from "@/hooks/use-session"
2020import { cn } from "@/lib/utils"
2121import { toast } from "@/lib/toast"
2222import { truncator } from "@/lib/truncate"
23+ import { setPendingRedirect } from "@/lib/auth"
2324import { getRecentAccounts } from "@/lib/accounts"
2425
2526import * as Auth from "@/components/auth"
@@ -591,11 +592,13 @@ function SsoStep({
591592 onCancel : ( ) => void
592593} ) {
593594 const [ loading , setLoading ] = useState ( false )
595+ const { redirect } = useSearch ( { from : "/$accountId/auth/login" } )
594596
595597 function onContinue ( ) {
596598 if ( ! redirectUrl ) return
597599
598600 setLoading ( true )
601+ if ( redirect ) setPendingRedirect ( redirect )
599602 window . location . href = redirectUrl
600603 }
601604
Original file line number Diff line number Diff line change @@ -19,12 +19,27 @@ interface ResetToken {
1919 token : string
2020}
2121
22+ const REDIRECT_STORAGE_KEY = "keygen.auth.redirect"
23+
2224export function parseRedirect ( value : unknown ) : string | undefined {
2325 return typeof value === "string" && / ^ \/ g o t o (?: [ / ? # ] | $ ) / . test ( value )
2426 ? value
2527 : undefined
2628}
2729
30+ export function setPendingRedirect ( value : string ) : void {
31+ window . sessionStorage . setItem ( REDIRECT_STORAGE_KEY , value )
32+ }
33+
34+ export function takePendingRedirect ( ) : string | undefined {
35+ const value = parseRedirect (
36+ window . sessionStorage . getItem ( REDIRECT_STORAGE_KEY ) ,
37+ )
38+ window . sessionStorage . removeItem ( REDIRECT_STORAGE_KEY )
39+
40+ return value
41+ }
42+
2843// parse a reset token from the URL query string
2944export function parseResetToken (
3045 value : string | undefined | null ,
Original file line number Diff line number Diff line change 11import { createFileRoute , redirect } from "@tanstack/react-router"
22
33import { restoreSession } from "@/keygen/session"
4+ import { takePendingRedirect } from "@/lib/auth"
45
56export const Route = createFileRoute ( "/$accountId/" ) ( {
67 loader : async ( { params } ) => {
7- // SSO returns the browser to the slug-addressed account root. Resolve the
8+ // SSO returns the browser to the slug-addressed account root; resolve the
89 // session so we can land on the account's stable id rather than the slug.
910 const { accountId } = await restoreSession ( )
1011
11- return redirect ( {
12+ const pendingRedirect = takePendingRedirect ( )
13+ if ( pendingRedirect ) {
14+ redirect ( { href : pendingRedirect , replace : true , throw : true } )
15+ return
16+ }
17+
18+ redirect ( {
1219 to : "/$accountId/app" ,
1320 params : { accountId : accountId ?? params . accountId } ,
1421 replace : true ,
22+ throw : true ,
1523 } )
1624 } ,
1725 component : ( ) => null ,
You can’t perform that action at this time.
0 commit comments