@@ -4,15 +4,16 @@ import { retry } from '@clerk/shared/retry';
4
4
import type {
5
5
ActJWTClaim ,
6
6
CheckAuthorization ,
7
+ ClerkOptions ,
7
8
EmailCodeConfig ,
9
+ EnvironmentResource ,
8
10
GetToken ,
9
11
GetTokenOptions ,
10
12
PhoneCodeConfig ,
11
13
SessionJSON ,
12
14
SessionJSONSnapshot ,
13
15
SessionResource ,
14
16
SessionStatus ,
15
- SessionTask ,
16
17
SessionVerificationJSON ,
17
18
SessionVerificationResource ,
18
19
SessionVerifyAttemptFirstFactorParams ,
@@ -24,11 +25,13 @@ import type {
24
25
UserResource ,
25
26
} from '@clerk/types' ;
26
27
28
+ import { buildURL , inBrowser } from '../../utils' ;
27
29
import { unixEpochToDate } from '../../utils/date' ;
28
30
import { clerkInvalidStrategy } from '../errors' ;
29
31
import { eventBus , events } from '../events' ;
30
32
import { SessionTokenCache } from '../tokenCache' ;
31
33
import { BaseResource , PublicUserData , Token , User } from './internal' ;
34
+ import { SessionTask } from './SessionTask' ;
32
35
import { SessionVerification } from './SessionVerification' ;
33
36
34
37
export class Session extends BaseResource implements SessionResource {
@@ -226,7 +229,7 @@ export class Session extends BaseResource implements SessionResource {
226
229
this . createdAt = unixEpochToDate ( data . created_at ) ;
227
230
this . updatedAt = unixEpochToDate ( data . updated_at ) ;
228
231
this . user = new User ( data . user ) ;
229
- this . tasks = data . tasks ;
232
+ this . tasks = data . tasks ?. map ( task => new SessionTask ( task ) ) ?? [ ] ;
230
233
231
234
if ( data . public_user_data ) {
232
235
this . publicUserData = new PublicUserData ( data . public_user_data ) ;
@@ -303,4 +306,21 @@ export class Session extends BaseResource implements SessionResource {
303
306
return token . getRawString ( ) || null ;
304
307
} ) ;
305
308
}
309
+
310
+ public __internal_buildSessionTaskUrl ( options : ClerkOptions , environment ?: EnvironmentResource | null ) : string {
311
+ const [ currentTask ] = this . tasks ?? [ ] ;
312
+
313
+ if ( ! currentTask || ! environment || ! inBrowser ( ) ) {
314
+ return '' ;
315
+ }
316
+
317
+ const signInUrl = options [ 'signInUrl' ] || environment . displayConfig . signInUrl ;
318
+ const signUpUrl = options [ 'signUpUrl' ] || environment . displayConfig . signUpUrl ;
319
+ const isReferrerSignUpUrl = window . location . href . startsWith ( signUpUrl ) ;
320
+
321
+ return buildURL (
322
+ { base : isReferrerSignUpUrl ? signUpUrl : signInUrl , hashPath : currentTask . __internal_getNavigationPath ( ) } ,
323
+ { stringify : true } ,
324
+ ) ;
325
+ }
306
326
}
0 commit comments