@@ -369,8 +369,21 @@ export class Clerk implements ClerkInterface {
369369 const opts = callbackOrOptions && typeof callbackOrOptions === 'object' ? callbackOrOptions : options || { } ;
370370
371371 const redirectUrl = opts ?. redirectUrl || this . buildAfterSignOutUrl ( ) ;
372- const defaultCb = ( ) => this . navigate ( redirectUrl ) ;
373- const cb = typeof callbackOrOptions === 'function' ? callbackOrOptions : defaultCb ;
372+
373+ const handleSetActive = ( ) => {
374+ const signOutCallback = typeof callbackOrOptions === 'function' ? callbackOrOptions : undefined ;
375+ if ( signOutCallback ) {
376+ return this . setActive ( {
377+ session : null ,
378+ beforeEmit : ignoreEventValue ( signOutCallback ) ,
379+ } ) ;
380+ }
381+
382+ return this . setActive ( {
383+ session : null ,
384+ redirectUrl,
385+ } ) ;
386+ } ;
374387
375388 if ( ! opts . sessionId || this . client . activeSessions . length === 1 ) {
376389 if ( this . #options. experimental ?. persistClient ?? true ) {
@@ -379,22 +392,14 @@ export class Clerk implements ClerkInterface {
379392 await this . client . destroy ( ) ;
380393 }
381394
382- return this . setActive ( {
383- session : null ,
384- beforeEmit : ignoreEventValue ( cb ) ,
385- redirectUrl,
386- } ) ;
395+ return handleSetActive ( ) ;
387396 }
388397
389398 const session = this . client . activeSessions . find ( s => s . id === opts . sessionId ) ;
390399 const shouldSignOutCurrent = session ?. id && this . session ?. id === session . id ;
391400 await session ?. remove ( ) ;
392401 if ( shouldSignOutCurrent ) {
393- return this . setActive ( {
394- session : null ,
395- beforeEmit : ignoreEventValue ( cb ) ,
396- redirectUrl,
397- } ) ;
402+ return handleSetActive ( ) ;
398403 }
399404 } ;
400405
@@ -906,12 +911,15 @@ export class Clerk implements ClerkInterface {
906911 if ( beforeEmit ) {
907912 beforeUnloadTracker ?. startTracking ( ) ;
908913 this . #setTransitiveState( ) ;
909- deprecated ( 'beforeEmit' , 'Use the `redirectUrl` property instead.' ) ;
914+ deprecated (
915+ 'Clerk.setActive({beforeEmit})' ,
916+ 'Use the `redirectUrl` property instead. Example `Clerk.setActive({redirectUrl:"/"})`' ,
917+ ) ;
910918 await beforeEmit ( newSession ) ;
911919 beforeUnloadTracker ?. stopTracking ( ) ;
912920 }
913921
914- if ( redirectUrl ) {
922+ if ( redirectUrl && ! beforeEmit ) {
915923 beforeUnloadTracker ?. startTracking ( ) ;
916924 this . #setTransitiveState( ) ;
917925
0 commit comments