diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js --- a/lib/actions/user-actions.js +++ b/lib/actions/user-actions.js @@ -358,13 +358,7 @@ ]); } -const secondaryDeviceLogOutOptions = Object.freeze({ - logOutType: 'secondary_device', -}); - -function useSecondaryDeviceLogOut(): () => Promise { - const logOut = useLogOut(secondaryDeviceLogOutOptions); - +function useSendLogoutMessageToPrimaryDevice(): () => Promise { const identityContext = React.useContext(IdentityClientContext); if (!identityContext) { throw new Error('Identity service client is not initialized'); @@ -398,10 +392,23 @@ [recipient], authMetadata, ); + }, [identityContext, broadcastEphemeralMessage]); +} + +const secondaryDeviceLogOutOptions = Object.freeze({ + logOutType: 'secondary_device', +}); + +function useSecondaryDeviceLogOut(): () => Promise { + const logOut = useLogOut(secondaryDeviceLogOutOptions); + const sendLogoutMessage = useSendLogoutMessageToPrimaryDevice(); + + return React.useCallback(async () => { + await sendLogoutMessage(); // log out of identity service, keyserver and visually return logOut(); - }, [identityContext, broadcastEphemeralMessage, logOut]); + }, [sendLogoutMessage, logOut]); } const claimUsernameActionTypes = Object.freeze({