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 @@ -133,7 +133,7 @@ }; type UseLogOutOptions = { - +logOutType?: 'legacy' | 'secondary_device', + +logOutType?: 'legacy' | 'primary_device' | 'secondary_device', }; function useLogOut( @@ -159,10 +159,21 @@ if (!identityClient) { throw new Error('Identity service client is not initialized'); } - const callIdentityClientLogOut = - logOutType === 'secondary_device' - ? identityClient.logOutSecondaryDevice - : identityClient.logOut; + let callIdentityClientLogOut; + if (logOutType === 'primary_device') { + if (!identityClient.logOutPrimaryDevice) { + throw new Error( + 'logOutPrimaryDevice not defined. ' + + 'Are you calling it on non-primary device?', + ); + } + callIdentityClientLogOut = identityClient.logOutPrimaryDevice; + } else { + callIdentityClientLogOut = + logOutType === 'secondary_device' + ? identityClient.logOutSecondaryDevice + : identityClient.logOut; + } try { await Promise.race([ callIdentityClientLogOut(), @@ -235,6 +246,15 @@ }, [commServicesAccessToken, identityClient, preRequestUserState]); } +const primaryDeviceLogOutOptions = Object.freeze({ + logOutType: 'primary_device', +}); + +function usePrimaryDeviceLogOut(): () => Promise { + const logOut = useLogOut(primaryDeviceLogOutOptions); + return logOut; +} + const secondaryDeviceLogOutOptions = Object.freeze({ logOutType: 'secondary_device', }); @@ -1301,6 +1321,7 @@ legacyLogInActionTypes, useLogOut, useIdentityLogOut, + usePrimaryDeviceLogOut, useSecondaryDeviceLogOut, logOutActionTypes, legacyKeyserverRegister,