File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed
packages/clerk-js/src/core Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @clerk/clerk-js " : patch
3
+ ---
4
+
5
+ Set ` session ` and ` client_uat ` before invalidating cache during ` setActive() ` flow
Original file line number Diff line number Diff line change @@ -156,6 +156,7 @@ describe('Clerk singleton', () => {
156
156
user : { } ,
157
157
touch : jest . fn ( ) ,
158
158
getToken : jest . fn ( ) ,
159
+ lastActiveToken : { getRawString : ( ) => 'mocked-token' } ,
159
160
} ;
160
161
let evenBusSpy ;
161
162
@@ -243,6 +244,19 @@ describe('Clerk singleton', () => {
243
244
await sut . setActive ( { session : null } ) ;
244
245
} ) ;
245
246
247
+ it ( 'sets __session and __client_uat cookie before calling __unstable__onBeforeSetActive' , async ( ) => {
248
+ mockSession . touch . mockReturnValueOnce ( Promise . resolve ( ) ) ;
249
+ mockClientFetch . mockReturnValue ( Promise . resolve ( { activeSessions : [ mockSession ] } ) ) ;
250
+
251
+ ( window as any ) . __unstable__onBeforeSetActive = ( ) => {
252
+ expect ( evenBusSpy ) . toHaveBeenCalledWith ( 'token:update' , { token : mockSession . lastActiveToken } ) ;
253
+ } ;
254
+
255
+ const sut = new Clerk ( productionPublishableKey ) ;
256
+ await sut . load ( ) ;
257
+ await sut . setActive ( { session : mockSession as any as ActiveSessionResource } ) ;
258
+ } ) ;
259
+
246
260
it ( 'calls __unstable__onAfterSetActive after beforeEmit and session.touch' , async ( ) => {
247
261
const beforeEmitMock = jest . fn ( ) ;
248
262
mockSession . touch . mockReturnValueOnce ( Promise . resolve ( ) ) ;
Original file line number Diff line number Diff line change @@ -720,6 +720,10 @@ export class Clerk implements ClerkInterface {
720
720
eventBus . dispatch ( events . TokenUpdate , { token : null } ) ;
721
721
}
722
722
723
+ if ( session ?. lastActiveToken ) {
724
+ eventBus . dispatch ( events . TokenUpdate , { token : session . lastActiveToken } ) ;
725
+ }
726
+
723
727
await onBeforeSetActive ( ) ;
724
728
725
729
//1. setLastActiveSession to passed user session (add a param).
@@ -755,6 +759,7 @@ export class Clerk implements ClerkInterface {
755
759
}
756
760
757
761
this . #setAccessors( newSession ) ;
762
+
758
763
this . #emit( ) ;
759
764
await onAfterSetActive ( ) ;
760
765
this . #resetComponentsState( ) ;
You can’t perform that action at this time.
0 commit comments