@@ -37,7 +37,6 @@ import type {
3737 OrganizationProfileProps ,
3838 OrganizationResource ,
3939 OrganizationSwitcherProps ,
40- RedirectOptions ,
4140 Resources ,
4241 SDKMetadata ,
4342 SetActiveParams ,
@@ -59,7 +58,6 @@ import type {
5958
6059import type { MountComponentRenderer } from '../ui/Components' ;
6160import {
62- appendAsQueryParams ,
6361 buildURL ,
6462 completeSignUpFlow ,
6563 createAllowedRedirectOrigins ,
@@ -77,17 +75,16 @@ import {
7775 isRedirectForFAPIInitiatedFlow ,
7876 noOrganizationExists ,
7977 noUserExists ,
80- pickRedirectionProp ,
8178 removeClerkQueryParam ,
8279 requiresUserInput ,
8380 sessionExistsAndSingleSessionModeEnabled ,
8481 stripOrigin ,
85- stripSameOrigin ,
86- toURL ,
8782 windowNavigate ,
8883} from '../utils' ;
84+ import { assertNoLegacyProp } from '../utils/assertNoLegacyProp' ;
8985import { getClientUatCookie } from '../utils/cookies/clientUat' ;
9086import { memoizeListenerCallback } from '../utils/memoizeStateListenerCallback' ;
87+ import { RedirectUrls } from '../utils/redirectUrls' ;
9188import { CLERK_SATELLITE_URL , CLERK_SYNCED , ERROR_CODES } from './constants' ;
9289import type { DevBrowser } from './devBrowser' ;
9390import { createDevBrowser } from './devBrowser' ;
@@ -133,9 +130,11 @@ const defaultOptions: ClerkOptions = {
133130 isSatellite : false ,
134131 signInUrl : undefined ,
135132 signUpUrl : undefined ,
136- afterSignInUrl : undefined ,
137- afterSignUpUrl : undefined ,
138133 afterSignOutUrl : undefined ,
134+ signInFallbackRedirectUrl : undefined ,
135+ signUpFallbackRedirectUrl : undefined ,
136+ signInForceRedirectUrl : undefined ,
137+ signUpForceRedirectUrl : undefined ,
139138} ;
140139
141140export class Clerk implements ClerkInterface {
@@ -276,6 +275,8 @@ export class Clerk implements ClerkInterface {
276275 ...options ,
277276 } ;
278277
278+ assertNoLegacyProp ( this . #options) ;
279+
279280 if ( this . #options. sdkMetadata ) {
280281 Clerk . sdkMetadata = this . #options. sdkMetadata ;
281282 }
@@ -827,11 +828,17 @@ export class Clerk implements ClerkInterface {
827828 }
828829
829830 public buildSignInUrl ( options ?: SignInRedirectOptions ) : string {
830- return this . #buildUrl( 'signInUrl' , options ) ;
831+ return this . #buildUrl( 'signInUrl' , {
832+ ...options ?. initialValues ,
833+ redirect_url : options ?. redirectUrl || window . location . href ,
834+ } ) ;
831835 }
832836
833837 public buildSignUpUrl ( options ?: SignUpRedirectOptions ) : string {
834- return this . #buildUrl( 'signUpUrl' , options ) ;
838+ return this . #buildUrl( 'signUpUrl' , {
839+ ...options ?. initialValues ,
840+ redirect_url : options ?. redirectUrl || window . location . href ,
841+ } ) ;
835842 }
836843
837844 public buildUserProfileUrl ( ) : string {
@@ -849,19 +856,11 @@ export class Clerk implements ClerkInterface {
849856 }
850857
851858 public buildAfterSignInUrl ( ) : string {
852- if ( ! this . #options. afterSignInUrl ) {
853- return '/' ;
854- }
855-
856- return this . buildUrlWithAuth ( this . #options. afterSignInUrl ) ;
859+ return this . buildUrlWithAuth ( new RedirectUrls ( this . #options) . getAfterSignInUrl ( ) ) ;
857860 }
858861
859862 public buildAfterSignUpUrl ( ) : string {
860- if ( ! this . #options. afterSignUpUrl ) {
861- return '/' ;
862- }
863-
864- return this . buildUrlWithAuth ( this . #options. afterSignUpUrl ) ;
863+ return this . buildUrlWithAuth ( new RedirectUrls ( this . #options) . getAfterSignUpUrl ( ) ) ;
865864 }
866865
867866 public buildAfterSignOutUrl ( ) : string {
@@ -1062,9 +1061,9 @@ export class Clerk implements ClerkInterface {
10621061 buildURL ( { base : displayConfig . signInUrl , hashPath : '/reset-password' } , { stringify : true } ) ,
10631062 ) ;
10641063
1065- const navigateAfterSignIn = makeNavigate ( params . afterSignInUrl || params . redirectUrl || '/' ) ;
1066-
1067- const navigateAfterSignUp = makeNavigate ( params . afterSignUpUrl || params . redirectUrl || '/' ) ;
1064+ const redirectUrls = new RedirectUrls ( this . #options , params ) ;
1065+ const navigateAfterSignIn = makeNavigate ( redirectUrls . getAfterSignInUrl ( ) ) ;
1066+ const navigateAfterSignUp = makeNavigate ( redirectUrls . getAfterSignUpUrl ( ) ) ;
10681067
10691068 const navigateToContinueSignUp = makeNavigate (
10701069 params . continueSignUpUrl ||
@@ -1090,7 +1089,6 @@ export class Clerk implements ClerkInterface {
10901089
10911090 const userExistsButNeedsToSignIn =
10921091 su . externalAccountStatus === 'transferable' && su . externalAccountErrorCode === 'external_account_exists' ;
1093-
10941092 if ( userExistsButNeedsToSignIn ) {
10951093 const res = await signIn . create ( { transfer : true } ) ;
10961094 switch ( res . status ) {
@@ -1644,31 +1642,13 @@ export class Clerk implements ClerkInterface {
16441642 } ) ;
16451643 } ;
16461644
1647- #buildUrl = ( key : 'signInUrl' | 'signUpUrl' , options ?: SignInRedirectOptions | SignUpRedirectOptions ) : string => {
1648- if ( ! this . loaded || ! this . #environment || ! this . #environment. displayConfig ) {
1645+ #buildUrl = ( key : 'signInUrl' | 'signUpUrl' , params ?: Record < string , string > ) : string => {
1646+ if ( ! key || ! this . loaded || ! this . #environment || ! this . #environment. displayConfig ) {
16491647 return '' ;
16501648 }
1651-
1652- const signInOrUpUrl = pickRedirectionProp (
1653- key ,
1654- { options : this . #options, displayConfig : this . #environment. displayConfig } ,
1655- false ,
1656- ) ;
1657-
1658- const urls : RedirectOptions = {
1659- afterSignInUrl : pickRedirectionProp ( 'afterSignInUrl' , { ctx : options , options : this . #options } , false ) ,
1660- afterSignUpUrl : pickRedirectionProp ( 'afterSignUpUrl' , { ctx : options , options : this . #options } , false ) ,
1661- redirectUrl : options ?. redirectUrl || window . location . href ,
1662- } ;
1663-
1664- ( Object . keys ( urls ) as Array < keyof typeof urls > ) . forEach ( function ( key ) {
1665- const url = urls [ key ] ;
1666- if ( url ) {
1667- urls [ key ] = stripSameOrigin ( toURL ( url ) , toURL ( signInOrUpUrl ) ) ;
1668- }
1669- } ) ;
1670-
1671- return this . buildUrlWithAuth ( appendAsQueryParams ( signInOrUpUrl , { ...urls , ...options ?. initialValues } ) ) ;
1649+ const signInOrUpUrl = this . #options[ key ] || this . #environment. displayConfig [ key ] ;
1650+ const redirectUrls = new RedirectUrls ( this . #options, params ) ;
1651+ return this . buildUrlWithAuth ( redirectUrls . appendPreservedPropsToUrl ( signInOrUpUrl , params ) ) ;
16721652 } ;
16731653
16741654 assertComponentsReady ( controls : unknown ) : asserts controls is ReturnType < MountComponentRenderer > {
0 commit comments