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 @@ -193,6 +193,8 @@ } })(); + const logoutSource = `base_logout_${JSON.stringify(options)}`; + const identityPromise = (async () => { if (skipIdentityLogOut || !commServicesAccessToken) { return; @@ -211,6 +213,7 @@ } callIdentityClientLogOut = async () => { await logOutPrimaryDevice( + logoutSource, ownedKeyserverDeviceID, preRequestAuthMetadata, ); @@ -221,7 +224,7 @@ } else { callIdentityClientLogOut = async () => { try { - await identityClient.logOut(preRequestAuthMetadata); + await identityClient.logOut(logoutSource, preRequestAuthMetadata); } catch (e) { const errorMessage = getMessageForException(e); if (errorMessage !== 'use_new_flow') { @@ -273,16 +276,17 @@ }; }, [ + options, callKeyserverLogOut, + preRequestUserState, commServicesAccessToken, + removeAllHolders, + skipIdentityLogOut, identityClient, logOutType, ownedKeyserverDeviceID, - preRequestUserState, - removeAllHolders, - skipIdentityLogOut, - sendLogoutMessage, handleUseNewFlowResponse, + sendLogoutMessage, ], ); } @@ -339,6 +343,8 @@ throw new Error('Identity service client is not initialized'); } + const description = `identity ${logOutType} log_out`; + let callIdentityClientLogOut; if (logOutType === 'primary_device') { if (!identityClient.logOutPrimaryDevice) { @@ -347,17 +353,21 @@ 'Are you calling it on non-primary device?', ); } - callIdentityClientLogOut = identityClient.logOutPrimaryDevice; + callIdentityClientLogOut = async () => { + await identityClient.logOutPrimaryDevice?.(description); + }; } else if (logOutType === 'secondary_device') { callIdentityClientLogOut = identityClient.logOutSecondaryDevice; } else { - callIdentityClientLogOut = identityClient.logOut; + callIdentityClientLogOut = async () => { + await identityClient.logOut(description); + }; } try { await promiseWithTimeout( callIdentityClientLogOut(), logoutTimeout, - `identity ${logOutType} log_out`, + description, ); } catch (e) { console.log(`Identity logout failed: ${getMessageForException(e) ?? ''}`); diff --git a/lib/types/identity-service-types.js b/lib/types/identity-service-types.js --- a/lib/types/identity-service-types.js +++ b/lib/types/identity-service-types.js @@ -127,10 +127,14 @@ // Only a primary device can initiate account deletion, and web cannot be a // primary device +deletePasswordUser?: (password: string) => Promise; - +logOut: (preRequestAuthMetadata?: AuthMetadata) => Promise; + +logOut: ( + source: string, + preRequestAuthMetadata?: AuthMetadata, + ) => Promise; // This log out type is specific to primary device, and web cannot be a // primary device +logOutPrimaryDevice?: ( + source: string, keyserverDeviceID: ?string, preRequestAuthMetadata?: AuthMetadata, ) => Promise; diff --git a/native/identity-service/identity-service-context-provider.react.js b/native/identity-service/identity-service-context-provider.react.js --- a/native/identity-service/identity-service-context-provider.react.js +++ b/native/identity-service/identity-service-context-provider.react.js @@ -152,7 +152,11 @@ 'deletePasswordUser', ); }, - logOut: async (preRequestAuthMetadata?: AuthMetadata) => { + logOut: async (source: string, preRequestAuthMetadata?: AuthMetadata) => { + const { showAlert, isStaffRelease } = getConfig(); + if (isStaffRelease) { + showAlert('logOut', source); + } let authMetadata = preRequestAuthMetadata; if (!authMetadata) { authMetadata = await getAuthMetadata(); @@ -167,9 +171,14 @@ ); }, logOutPrimaryDevice: async ( + source: string, keyserverDeviceID: ?string, preRequestAuthMetadata?: AuthMetadata, ) => { + const { showAlert, isStaffRelease } = getConfig(); + if (isStaffRelease) { + showAlert('logOutPrimaryDevice', source); + } let authMetadata = preRequestAuthMetadata; if (!authMetadata) { authMetadata = await getAuthMetadata();