Page MenuHomePhabricator

D11020.id37291.diff
No OneTemporary

D11020.id37291.diff

diff --git a/web/account/siwe-login-form.react.js b/web/account/siwe-login-form.react.js
--- a/web/account/siwe-login-form.react.js
+++ b/web/account/siwe-login-form.react.js
@@ -16,6 +16,8 @@
import {
identityGenerateNonceActionTypes,
useIdentityGenerateNonce,
+ identityLogInActionTypes,
+ useIdentityWalletLogIn,
} from 'lib/actions/user-actions.js';
import ConnectedWalletInfo from 'lib/components/connected-wallet-info.react.js';
import SWMansionIcon from 'lib/components/SWMansionIcon.react.js';
@@ -28,7 +30,7 @@
} from 'lib/types/account-types.js';
import type { OLMIdentityKeys } from 'lib/types/crypto-types.js';
import { useLegacyAshoatKeyserverCall } from 'lib/utils/action-utils.js';
-import { ServerError } from 'lib/utils/errors.js';
+import { getMessageForException, ServerError } from 'lib/utils/errors.js';
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
import { useDispatch } from 'lib/utils/redux-utils.js';
import { usingCommServicesAccessToken } from 'lib/utils/services-utils.js';
@@ -78,6 +80,8 @@
const legacySiweAuthCall = useLegacyAshoatKeyserverCall(siweAuth);
const logInExtraInfo = useSelector(logInExtraInfoSelector);
+ const identityWalletLogIn = useIdentityWalletLogIn();
+
const [siweNonce, setSIWENonce] = React.useState<?string>(null);
const siweNonceShouldBeFetched =
@@ -159,6 +163,29 @@
[callLegacySIWEAuthEndpoint, dispatchActionPromise, logInExtraInfo],
);
+ const attemptIdentityWalletLogIn = React.useCallback(
+ (walletAddress: string, siweMessage: string, siweSignature: string) => {
+ return dispatchActionPromise(
+ identityLogInActionTypes,
+ (async () => {
+ try {
+ return await identityWalletLogIn(
+ walletAddress,
+ siweMessage,
+ siweSignature,
+ );
+ } catch (e) {
+ if (getMessageForException(e) === 'user not found') {
+ setError('account_does_not_exist');
+ }
+ throw e;
+ }
+ })(),
+ );
+ },
+ [dispatchActionPromise, identityWalletLogIn],
+ );
+
const dispatch = useDispatch();
const onSignInButtonClick = React.useCallback(async () => {
invariant(signer, 'signer must be present during SIWE attempt');
@@ -172,16 +199,21 @@
);
const message = createSIWEMessage(address, statement, siweNonce);
const signature = await signer.signMessage({ message });
- await attemptLegacySIWEAuth(message, signature);
- dispatch({
- type: setDataLoadedActionType,
- payload: {
- dataLoaded: true,
- },
- });
+ if (usingCommServicesAccessToken) {
+ await attemptIdentityWalletLogIn(address, message, signature);
+ } else {
+ await attemptLegacySIWEAuth(message, signature);
+ dispatch({
+ type: setDataLoadedActionType,
+ payload: {
+ dataLoaded: true,
+ },
+ });
+ }
}, [
address,
attemptLegacySIWEAuth,
+ attemptIdentityWalletLogIn,
primaryIdentityPublicKeys,
signer,
siweNonce,

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 29, 11:08 AM (8 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2731913
Default Alt Text
D11020.id37291.diff (3 KB)

Event Timeline