diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -412,6 +412,7 @@ } | { +type: 'IDENTITY_REGISTER_FAILED', + +error: true, +payload: Error, +loadingInfo: LoadingInfo, } diff --git a/web/account/traditional-login-form.react.js b/web/account/traditional-login-form.react.js --- a/web/account/traditional-login-form.react.js +++ b/web/account/traditional-login-form.react.js @@ -3,7 +3,12 @@ import invariant from 'invariant'; import * as React from 'react'; -import { useLogIn, logInActionTypes } from 'lib/actions/user-actions.js'; +import { + useLogIn, + logInActionTypes, + useIdentityPasswordLogIn, + identityLogInActionTypes, +} from 'lib/actions/user-actions.js'; import { useModalContext } from 'lib/components/modal-provider.react.js'; import { logInExtraInfoSelector } from 'lib/selectors/account-selectors.js'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; @@ -17,6 +22,7 @@ } from 'lib/types/account-types.js'; import { logInActionSources } from 'lib/types/account-types.js'; import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; +import { usingCommServicesAccessToken } from 'lib/utils/services-utils.js'; import { useGetSignedIdentityKeysBlob } from './account-hooks.js'; import HeaderSeparator from './header-separator.react.js'; @@ -32,6 +38,8 @@ const inputDisabled = useSelector(loadingStatusSelector) === 'loading'; const loginExtraInfo = useSelector(logInExtraInfoSelector); const callLegacyLogIn = useLogIn(); + const callIdentityPasswordLogIn = useIdentityPasswordLogIn(); + const dispatchActionPromise = useDispatchActionPromise(); const modalContext = useModalContext(); @@ -105,6 +113,24 @@ ], ); + const identityPasswordLogInAction = React.useCallback(async () => { + try { + const result = await callIdentityPasswordLogIn(username, password); + modalContext.popModal(); + return result; + } catch (e) { + setUsername(''); + setPassword(''); + if (e.message === 'user not found') { + setErrorMessage('incorrect username or password'); + } else { + setErrorMessage('unknown error'); + } + usernameInputRef.current?.focus(); + throw e; + } + }, [callIdentityPasswordLogIn, modalContext, password, username]); + const onSubmit = React.useCallback( (event: SyntheticEvent) => { event.preventDefault(); @@ -124,15 +150,25 @@ usernameInputRef.current?.focus(); return; } - void dispatchActionPromise( - logInActionTypes, - legacyLogInAction(loginExtraInfo), - undefined, - ({ calendarQuery: loginExtraInfo.calendarQuery }: LogInStartingPayload), - ); + if (usingCommServicesAccessToken) { + void dispatchActionPromise( + identityLogInActionTypes, + identityPasswordLogInAction(), + ); + } else { + void dispatchActionPromise( + logInActionTypes, + legacyLogInAction(loginExtraInfo), + undefined, + ({ + calendarQuery: loginExtraInfo.calendarQuery, + }: LogInStartingPayload), + ); + } }, [ dispatchActionPromise, + identityPasswordLogInAction, legacyLogInAction, loginExtraInfo, username, diff --git a/web/grpc/identity-service-client-wrapper.js b/web/grpc/identity-service-client-wrapper.js --- a/web/grpc/identity-service-client-wrapper.js +++ b/web/grpc/identity-service-client-wrapper.js @@ -288,11 +288,7 @@ await client.logInPasswordUserStart(loginStartRequest); } catch (e) { console.log('Error calling logInPasswordUserStart:', e); - throw new Error( - `logInPasswordUserStart RPC failed: ${ - getMessageForException(e) ?? 'unknown' - }`, - ); + throw new Error(getMessageForException(e) ?? 'unknown'); } const finishRequestBytes = opaqueLogin.finish( loginStartResponse.getOpaqueLoginResponse_asU8(), @@ -308,11 +304,7 @@ await client.logInPasswordUserFinish(loginFinishRequest); } catch (e) { console.log('Error calling logInPasswordUserFinish:', e); - throw new Error( - `logInPasswordUserFinish RPC failed: ${ - getMessageForException(e) ?? 'unknown' - }`, - ); + throw new Error(getMessageForException(e) ?? 'unknown'); } const userID = loginFinishResponse.getUserId();