1- import { useClerk , useSession } from '@clerk/shared/react' ;
1+ import { useClerk , useSession , useUser } from '@clerk/shared/react' ;
2+ import type { ActiveSessionResource } from '@clerk/types' ;
23import type { PointerEventHandler } from 'react' ;
34import React , { useEffect , useRef } from 'react' ;
45
56import { getFullName , getIdentifier } from '../../../utils/user' ;
6- import { withCoreUserGuard } from '../../contexts' ;
7+ import { useSignOutContext , withCoreUserGuard } from '../../contexts' ;
78import type { LocalizationKey } from '../../customizables' ;
89import {
910 Col ,
@@ -17,6 +18,7 @@ import {
1718 useLocalizations ,
1819} from '../../customizables' ;
1920import { Portal } from '../../elements/Portal' ;
21+ import { useMultipleSessions } from '../../hooks/useMultipleSessions' ;
2022import { Eye } from '../../icons' ;
2123import type { PropsOfComponent } from '../../styledSystem' ;
2224import { InternalThemeProvider , mqu } from '../../styledSystem' ;
@@ -59,7 +61,17 @@ type FabContentProps = { title: LocalizationKey; signOutText: LocalizationKey };
5961
6062const FabContent = ( { title, signOutText } : FabContentProps ) => {
6163 const { session } = useSession ( ) ;
64+ const { user } = useUser ( ) ;
6265 const { signOut } = useClerk ( ) ;
66+ const { otherSessions } = useMultipleSessions ( { user } ) ;
67+ const { navigateAfterSignOut, navigateAfterMultiSessionSingleSignOutUrl } = useSignOutContext ( ) ;
68+
69+ const handleSignOutSessionClicked = ( session : ActiveSessionResource ) => ( ) => {
70+ if ( otherSessions . length === 0 ) {
71+ return signOut ( navigateAfterSignOut ) ;
72+ }
73+ return signOut ( navigateAfterMultiSessionSingleSignOutUrl , { sessionId : session . id } ) ;
74+ } ;
6375
6476 return (
6577 < Col
@@ -88,10 +100,10 @@ const FabContent = ({ title, signOutText }: FabContentProps) => {
88100 } ,
89101 } ) }
90102 localizationKey = { signOutText }
91- onClick = { async ( ) => {
103+ onClick = {
92104 // clerk-js has been loaded at this point so we can safely access session
93- await signOut ( { sessionId : session ! . id } ) ;
94- } }
105+ handleSignOutSessionClicked ( session ! )
106+ }
95107 />
96108 </ Col >
97109 ) ;
0 commit comments