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 @@ -68,6 +68,7 @@ } from '../types/user-types.js'; import { authoritativeKeyserverID } from '../utils/authoritative-keyserver.js'; import { getConfig } from '../utils/config.js'; +import { getMessageForException } from '../utils/errors.js'; import { useSelector } from '../utils/redux-utils.js'; import { usingCommServicesAccessToken } from '../utils/services-utils.js'; import sleep from '../utils/sleep.js'; @@ -620,6 +621,7 @@ const client = React.useContext(IdentityClientContext); const identityClient = client?.identityClient; const preRequestUserState = useSelector(state => state.currentUserInfo); + const callClaimUsername = useClaimUsername(); return React.useCallback( (username, password) => { @@ -627,17 +629,38 @@ throw new Error('Identity service client is not initialized'); } return (async () => { - const result = await identityClient.logInPasswordUser( - username, - password, - ); + let result; + try { + result = await identityClient.logInPasswordUser(username, password); + } catch (e) { + const registerReservedPasswordUser = + identityClient.registerReservedPasswordUser; + if ( + registerReservedPasswordUser && + getMessageForException(e) === + 'need keyserver message to claim username' + ) { + const { message, signature } = await callClaimUsername({ + username, + password, + }); + result = await registerReservedPasswordUser( + username, + password, + message, + signature, + ); + } else { + throw e; + } + } return { ...result, preRequestUserState, }; })(); }, - [identityClient, preRequestUserState], + [identityClient, preRequestUserState, callClaimUsername], ); } function useIdentityWalletLogIn(): (