@@ -38,6 +38,7 @@ import type { TurnstileAction } from "@stackframe/stack-shared/dist/utils/turnst
3838import { isRelative } from "@stackframe/stack-shared/dist/utils/urls" ;
3939import { generateUuid } from "@stackframe/stack-shared/dist/utils/uuids" ;
4040import * as tanstackStartServerContext from "@stackframe/tanstack-start/tanstack-start-server-context" ; // THIS_LINE_PLATFORM tanstack-start
41+ import * as TanStackRouter from "@tanstack/react-router" ; // THIS_LINE_PLATFORM tanstack-start
4142import * as cookie from "cookie" ;
4243import * as NextNavigationUnscrambled from "next/navigation" ; // import the entire module to get around some static compiler warnings emitted by Next.js in some cases | THIS_LINE_PLATFORM next
4344import React , { useCallback , useMemo } from "react" ; // THIS_LINE_PLATFORM react-like
@@ -568,6 +569,7 @@ export class _StackClientAppImplIncomplete<HasTokenStore extends boolean, Projec
568569 this . _tokenStoreInit = resolvedOptions . tokenStore ;
569570 this . _redirectMethod = resolvedOptions . redirectMethod || ( isBrowserLike ( ) ? "window" : "none" ) ;
570571 this . _redirectMethod = resolvedOptions . redirectMethod || "nextjs" ; // THIS_LINE_PLATFORM next
572+ this . _redirectMethod = resolvedOptions . redirectMethod || "tanstack-start" ; // THIS_LINE_PLATFORM tanstack-start
571573 this . _urlOptions = resolvedOptions . urls ?? { } ;
572574 this . _oauthScopesOnSignIn = resolvedOptions . oauthScopesOnSignIn ?? { } ;
573575 this . _prefetchCrossDomainHandoffParamsIfNeeded ( ) ;
@@ -2463,6 +2465,10 @@ export class _StackClientAppImplIncomplete<HasTokenStore extends boolean, Projec
24632465 } else if ( isReactServer && this . _redirectMethod === "nextjs" ) {
24642466 NextNavigation . redirect ( options . url . toString ( ) , options . replace ? NextNavigation . RedirectType . replace : NextNavigation . RedirectType . push ) ;
24652467 // END_PLATFORM
2468+ // IF_PLATFORM tanstack-start
2469+ } else if ( this . _redirectMethod === "tanstack-start" && ! isBrowserLike ( ) ) {
2470+ throw TanStackRouter . redirect ( { href : options . url . toString ( ) , replace : options . replace } ) ;
2471+ // END_PLATFORM
24662472 } else if ( typeof this . _redirectMethod === "object" && this . _redirectMethod . navigate ) {
24672473 this . _redirectMethod . navigate ( options . url . toString ( ) ) ;
24682474 } else {
@@ -2487,6 +2493,10 @@ export class _StackClientAppImplIncomplete<HasTokenStore extends boolean, Projec
24872493 const router = NextNavigation . useRouter ( ) ;
24882494 return ( to : string ) => router . push ( to ) ;
24892495 // END_PLATFORM
2496+ // IF_PLATFORM tanstack-start
2497+ } else if ( this . _redirectMethod === "tanstack-start" ) {
2498+ return ( to : string ) => window . location . assign ( to ) ;
2499+ // END_PLATFORM
24902500 } else {
24912501 return ( to : string ) => { } ;
24922502 }
@@ -2532,6 +2542,20 @@ export class _StackClientAppImplIncomplete<HasTokenStore extends boolean, Projec
25322542 await this . _redirectIfTrusted ( plan . url , options ) ;
25332543 }
25342544
2545+ protected _redirectToHandlerDuringRender ( handlerName : keyof HandlerUrls , options ?: RedirectToOptions ) : boolean {
2546+ // IF_PLATFORM tanstack-start
2547+ if ( this . _redirectMethod === "tanstack-start" && ! isBrowserLike ( ) ) {
2548+ const rawUrls = getUrls ( this . _urlOptions , { projectId : this . projectId } ) ;
2549+ const rawHandlerUrl = rawUrls [ handlerName ] ;
2550+ if ( ! rawHandlerUrl ) {
2551+ throw new Error ( `No URL for handler name ${ handlerName } ` ) ;
2552+ }
2553+ throw TanStackRouter . redirect ( { href : rawHandlerUrl , replace : options ?. replace } ) ;
2554+ }
2555+ // END_PLATFORM
2556+ return false ;
2557+ }
2558+
25352559 async redirectToSignIn ( options ?: RedirectToOptions ) { return await this . _redirectToHandler ( "signIn" , options ) ; }
25362560 async redirectToSignUp ( options ?: RedirectToOptions ) { return await this . _redirectToHandler ( "signUp" , options ) ; }
25372561 async redirectToSignOut ( options ?: RedirectToOptions ) { return await this . _redirectToHandler ( "signOut" , options ) ; }
@@ -2685,9 +2709,13 @@ export class _StackClientAppImplIncomplete<HasTokenStore extends boolean, Projec
26852709 switch ( options ?. or ) {
26862710 case 'redirect' : {
26872711 if ( ! crud ?. is_anonymous && crud ?. is_restricted ) {
2688- runAsynchronously ( this . redirectToOnboarding ( { replace : true } ) ) ;
2712+ if ( ! this . _redirectToHandlerDuringRender ( "onboarding" , { replace : true } ) ) {
2713+ runAsynchronously ( this . redirectToOnboarding ( { replace : true } ) ) ;
2714+ }
26892715 } else {
2690- runAsynchronously ( this . redirectToSignIn ( { replace : true } ) ) ;
2716+ if ( ! this . _redirectToHandlerDuringRender ( "signIn" , { replace : true } ) ) {
2717+ runAsynchronously ( this . redirectToSignIn ( { replace : true } ) ) ;
2718+ }
26912719 }
26922720 suspend ( ) ;
26932721 throw new StackAssertionError ( "suspend should never return" ) ;
0 commit comments