@@ -927,6 +927,16 @@ export class Clerk implements ClerkInterface {
927
927
}
928
928
929
929
const hasSessionTaskToResolve = ! ! newSession ?. tasks ?. length ;
930
+ if ( hasSessionTaskToResolve && this . #options. standardBrowser ) {
931
+ const hasEventHandler = eventBus . has ( events . InternalComponentNavigate ) ;
932
+ if ( hasEventHandler ) {
933
+ await new Promise < void > ( resolveNavigation =>
934
+ eventBus . dispatch ( events . InternalComponentNavigate , resolveNavigation ) ,
935
+ ) ;
936
+ } else {
937
+ await this . navigate ( this . internal__buildSessionTaskUrl ( ) ) ;
938
+ }
939
+ }
930
940
931
941
//2. If there's a beforeEmit, typically we're navigating. Emit the session as
932
942
// undefined, then wait for beforeEmit to complete before emitting the new session.
@@ -940,15 +950,14 @@ export class Clerk implements ClerkInterface {
940
950
) ;
941
951
beforeUnloadTracker ?. startTracking ( ) ;
942
952
943
- // Do not unmount SignIn/SignUp for in-component navigation on new session tasks
944
- if ( ! hasSessionTaskToResolve ) {
945
- this . #setTransitiveState( ) ;
946
- }
953
+ this . #setTransitiveState( ) ;
947
954
948
955
await beforeEmit ( newSession ) ;
949
956
beforeUnloadTracker ?. stopTracking ( ) ;
950
957
}
951
958
959
+ // `hasSessionTaskToResolve` needs to be checked in order to override
960
+ // redirects to `afterSignInUrl/afterSignUpUrl` when there are pending tasks
952
961
if ( redirectUrl && ! beforeEmit && ! hasSessionTaskToResolve ) {
953
962
beforeUnloadTracker ?. startTracking ( ) ;
954
963
this . #setTransitiveState( ) ;
@@ -1148,21 +1157,22 @@ export class Clerk implements ClerkInterface {
1148
1157
return this . buildUrlWithAuth ( this . environment . displayConfig . organizationProfileUrl ) ;
1149
1158
}
1150
1159
1151
- public buildSessionTaskUrl ( ) : string {
1160
+ // pass this to the session object as internal
1161
+ public internal__buildSessionTaskUrl ( ) : string {
1152
1162
const [ currentTask ] = this . session ?. tasks ?? [ ] ;
1153
1163
1154
1164
if ( ! currentTask || ! this . environment || ! this . environment . displayConfig ) {
1155
1165
return '' ;
1156
1166
}
1157
1167
1158
- // TODO - Make it type safe and abstracted
1159
- const mapTaskRoutePathFromKey = {
1160
- orgs : '/add-organization' ,
1161
- } ;
1162
-
1163
1168
const signInUrl = this . #options[ 'signInUrl' ] || this . environment . displayConfig . signInUrl ;
1164
- // TODO - Make it path dynamic by current session task
1165
- return buildURL ( { base : `${ signInUrl } ` , hashPath : mapTaskRoutePathFromKey [ currentTask . key ] } , { stringify : true } ) ;
1169
+ const signUpUrl = this . #options[ 'signUpUrl' ] || this . environment . displayConfig . signUpUrl ;
1170
+ const isReferrerSignUpUrl = window . location . href . startsWith ( signUpUrl ) ;
1171
+
1172
+ return buildURL (
1173
+ { base : isReferrerSignUpUrl ? signUpUrl : signInUrl , hashPath : '/add-organization' } ,
1174
+ { stringify : true } ,
1175
+ ) ;
1166
1176
}
1167
1177
1168
1178
#redirectToSatellite = async ( ) : Promise < unknown > => {
0 commit comments