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 @@ -438,7 +438,9 @@ // used to reset state (eg. Redux, SQLite) to a logged-out state. The state // reset only occurs when a success action is dispatched, so we always dispatch // a success. -function useDeleteDiscardedIdentityAccount(): () => Promise { +function useDeleteDiscardedIdentityAccount(): ( + password: ?string, +) => Promise { const client = React.useContext(IdentityClientContext); const identityClient = client?.identityClient; @@ -447,35 +449,44 @@ state => state.commServicesAccessToken, ); - return React.useCallback(async () => { - invariant( - usingCommServicesAccessToken, - 'deleteDiscardedIdentityAccount can only be called when ' + - 'usingCommServicesAccessToken', - ); - if (!identityClient) { - throw new Error('Identity service client is not initialized'); - } - if (!identityClient.deleteWalletUser) { - throw new Error('Delete wallet user method unimplemented'); - } - try { - await Promise.race([ - identityClient.deleteWalletUser(), - (async () => { - await sleep(500); - throw new Error('identity delete_wallet_user took more than 500ms'); - })(), - ]); - } catch {} - return { - currentUserInfo: null, - preRequestUserState: { - ...preRequestUserState, - commServicesAccessToken, - }, - }; - }, [commServicesAccessToken, identityClient, preRequestUserState]); + return React.useCallback( + async password => { + invariant( + usingCommServicesAccessToken, + 'deleteDiscardedIdentityAccount can only be called when ' + + 'usingCommServicesAccessToken', + ); + if (!identityClient) { + throw new Error('Identity service client is not initialized'); + } + if ( + !identityClient.deleteWalletUser || + !identityClient.deletePasswordUser + ) { + throw new Error('Delete user method unimplemented'); + } + const deleteUserPromise = password + ? identityClient.deletePasswordUser(password) + : identityClient.deleteWalletUser(); + try { + await Promise.race([ + deleteUserPromise, + (async () => { + await sleep(500); + throw new Error('identity delete user call took more than 500ms'); + })(), + ]); + } catch {} + return { + currentUserInfo: null, + preRequestUserState: { + ...preRequestUserState, + commServicesAccessToken, + }, + }; + }, + [commServicesAccessToken, identityClient, preRequestUserState], + ); } const legacyKeyserverRegisterActionTypes = Object.freeze({ diff --git a/native/account/registration/registration-server-call.js b/native/account/registration/registration-server-call.js --- a/native/account/registration/registration-server-call.js +++ b/native/account/registration/registration-server-call.js @@ -465,7 +465,9 @@ ); const discardIdentityAccountPromise = (async () => { try { - const deletionResult = await deleteDiscardedIdentityAccount(); + const deletionResult = await deleteDiscardedIdentityAccount( + credentialsToSave?.password, + ); if (messageForException === 'client_version_unsupported') { Alert.alert( appOutOfDateAlertDetails.title,