@@ -37,7 +37,6 @@ import type {
37
37
OrganizationProfileProps ,
38
38
OrganizationResource ,
39
39
OrganizationSwitcherProps ,
40
- RedirectOptions ,
41
40
Resources ,
42
41
SDKMetadata ,
43
42
SetActiveParams ,
@@ -59,7 +58,6 @@ import type {
59
58
60
59
import type { MountComponentRenderer } from '../ui/Components' ;
61
60
import {
62
- appendAsQueryParams ,
63
61
buildURL ,
64
62
completeSignUpFlow ,
65
63
createAllowedRedirectOrigins ,
@@ -77,17 +75,16 @@ import {
77
75
isRedirectForFAPIInitiatedFlow ,
78
76
noOrganizationExists ,
79
77
noUserExists ,
80
- pickRedirectionProp ,
81
78
removeClerkQueryParam ,
82
79
requiresUserInput ,
83
80
sessionExistsAndSingleSessionModeEnabled ,
84
81
stripOrigin ,
85
- stripSameOrigin ,
86
- toURL ,
87
82
windowNavigate ,
88
83
} from '../utils' ;
84
+ import { assertNoLegacyProp } from '../utils/assertNoLegacyProp' ;
89
85
import { getClientUatCookie } from '../utils/cookies/clientUat' ;
90
86
import { memoizeListenerCallback } from '../utils/memoizeStateListenerCallback' ;
87
+ import { RedirectUrls } from '../utils/redirectUrls' ;
91
88
import { CLERK_SATELLITE_URL , CLERK_SYNCED , ERROR_CODES } from './constants' ;
92
89
import type { DevBrowser } from './devBrowser' ;
93
90
import { createDevBrowser } from './devBrowser' ;
@@ -133,9 +130,11 @@ const defaultOptions: ClerkOptions = {
133
130
isSatellite : false ,
134
131
signInUrl : undefined ,
135
132
signUpUrl : undefined ,
136
- afterSignInUrl : undefined ,
137
- afterSignUpUrl : undefined ,
138
133
afterSignOutUrl : undefined ,
134
+ signInFallbackRedirectUrl : undefined ,
135
+ signUpFallbackRedirectUrl : undefined ,
136
+ signInForceRedirectUrl : undefined ,
137
+ signUpForceRedirectUrl : undefined ,
139
138
} ;
140
139
141
140
export class Clerk implements ClerkInterface {
@@ -276,6 +275,8 @@ export class Clerk implements ClerkInterface {
276
275
...options ,
277
276
} ;
278
277
278
+ assertNoLegacyProp ( this . #options) ;
279
+
279
280
if ( this . #options. sdkMetadata ) {
280
281
Clerk . sdkMetadata = this . #options. sdkMetadata ;
281
282
}
@@ -827,11 +828,17 @@ export class Clerk implements ClerkInterface {
827
828
}
828
829
829
830
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
+ } ) ;
831
835
}
832
836
833
837
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
+ } ) ;
835
842
}
836
843
837
844
public buildUserProfileUrl ( ) : string {
@@ -849,19 +856,11 @@ export class Clerk implements ClerkInterface {
849
856
}
850
857
851
858
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 ( ) ) ;
857
860
}
858
861
859
862
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 ( ) ) ;
865
864
}
866
865
867
866
public buildAfterSignOutUrl ( ) : string {
@@ -1062,9 +1061,9 @@ export class Clerk implements ClerkInterface {
1062
1061
buildURL ( { base : displayConfig . signInUrl , hashPath : '/reset-password' } , { stringify : true } ) ,
1063
1062
) ;
1064
1063
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 ( ) ) ;
1068
1067
1069
1068
const navigateToContinueSignUp = makeNavigate (
1070
1069
params . continueSignUpUrl ||
@@ -1090,7 +1089,6 @@ export class Clerk implements ClerkInterface {
1090
1089
1091
1090
const userExistsButNeedsToSignIn =
1092
1091
su . externalAccountStatus === 'transferable' && su . externalAccountErrorCode === 'external_account_exists' ;
1093
-
1094
1092
if ( userExistsButNeedsToSignIn ) {
1095
1093
const res = await signIn . create ( { transfer : true } ) ;
1096
1094
switch ( res . status ) {
@@ -1644,31 +1642,13 @@ export class Clerk implements ClerkInterface {
1644
1642
} ) ;
1645
1643
} ;
1646
1644
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 ) {
1649
1647
return '' ;
1650
1648
}
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 ) ) ;
1672
1652
} ;
1673
1653
1674
1654
assertComponentsReady ( controls : unknown ) : asserts controls is ReturnType < MountComponentRenderer > {
0 commit comments