@@ -1412,7 +1412,7 @@ export class Clerk implements ClerkInterface {
14121412 return ;
14131413 }
14141414
1415- if ( newSession ?. status !== 'pending' ) {
1415+ if ( newSession ?. status !== 'pending' && this . session ?. id !== newSession ?. id ) {
14161416 this . #setTransitiveState( ) ;
14171417 }
14181418
@@ -2351,7 +2351,9 @@ export class Clerk implements ClerkInterface {
23512351 }
23522352
23532353 updateClient = ( newClient : ClientResource ) : void => {
2354- if ( ! this . client ) {
2354+ const isFirstClientSet = ! this . client ;
2355+
2356+ if ( isFirstClientSet ) {
23552357 // This is the first time client is being
23562358 // set, so we also need to set session
23572359 const session = this . #options. selectInitialSession
@@ -2381,6 +2383,11 @@ export class Clerk implements ClerkInterface {
23812383
23822384 // A client response contains its associated sessions, along with a fresh token, so we dispatch a token update event.
23832385 eventBus . emit ( events . TokenUpdate , { token : this . session ?. lastActiveToken } ) ;
2386+ } else if ( ! isFirstClientSet && newClient . sessions ?. length > 0 ) {
2387+ const session = this . #options. selectInitialSession
2388+ ? this . #options. selectInitialSession ( newClient )
2389+ : this . #defaultSession( newClient ) ;
2390+ this . #setAccessors( session ) ;
23842391 }
23852392
23862393 this . #emit( ) ;
@@ -2591,6 +2598,12 @@ export class Clerk implements ClerkInterface {
25912598 } ) ;
25922599
25932600 const initClient = async ( ) => {
2601+ const jwtInCookie = this . #authService?. getSessionCookie ( ) ;
2602+ if ( jwtInCookie ) {
2603+ const preliminaryClient = createClientFromJwt ( jwtInCookie ) ;
2604+ this . updateClient ( preliminaryClient ) ;
2605+ }
2606+
25942607 return Client . getOrCreateInstance ( )
25952608 . fetch ( )
25962609 . then ( res => this . updateClient ( res ) )
0 commit comments