Page MenuHomePhabricator

D6060.diff
No OneTemporary

D6060.diff

diff --git a/keyserver/src/fetchers/user-fetchers.js b/keyserver/src/fetchers/user-fetchers.js
--- a/keyserver/src/fetchers/user-fetchers.js
+++ b/keyserver/src/fetchers/user-fetchers.js
@@ -290,6 +290,18 @@
return result[0].user;
}
+async function fetchUserIDForEthereumAddress(
+ address: string,
+): Promise<?string> {
+ const query = SQL`
+ SELECT id
+ FROM users
+ WHERE LCASE(ethereum_address) = LCASE(${address})
+ `;
+ const [result] = await dbQuery(query);
+ return result.length === 0 ? null : result[0].id;
+}
+
export {
fetchUserInfos,
fetchLoggedInUserInfo,
@@ -300,4 +312,5 @@
fetchUsername,
fetchKnownUserInfos,
fetchKeyserverAdminID,
+ fetchUserIDForEthereumAddress,
};
diff --git a/keyserver/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js
--- a/keyserver/src/responders/user-responders.js
+++ b/keyserver/src/responders/user-responders.js
@@ -55,6 +55,7 @@
import {
fetchKnownUserInfos,
fetchLoggedInUserInfo,
+ fetchUserIDForEthereumAddress,
} from '../fetchers/user-fetchers';
import {
createNewAnonymousCookie,
@@ -195,7 +196,7 @@
input: any,
userID: string,
calendarQuery: ?CalendarQuery,
-) {
+): Promise<LogInResponse> {
const request: LogInRequest = input;
const newServerTime = Date.now();
const deviceToken = request.deviceTokenUpdateRequest
@@ -316,7 +317,10 @@
watchedIDs: t.list(t.String),
});
-async function siweAuthResponder(viewer: Viewer, input: any): Promise<boolean> {
+async function siweAuthResponder(
+ viewer: Viewer,
+ input: any,
+): Promise<LogInResponse> {
await validateInput(viewer, siweAuthRequestInputValidator, input);
const request: SIWEAuthRequest = input;
const { message, signature } = request;
@@ -355,7 +359,13 @@
}
}
- return false;
+ // 4. Complete login with call to `successfulLogInQueries(...)`
+ // if `address` corresponds to an existing user.
+ const userID = await fetchUserIDForEthereumAddress(siweMessage.address);
+ if (!userID) {
+ throw new ServerError('placeholder_error');
+ }
+ return await processSuccessfulLogin(viewer, input, userID);
}
const updatePasswordRequestInputValidator = tShape({
diff --git a/lib/actions/siwe-actions.js b/lib/actions/siwe-actions.js
--- a/lib/actions/siwe-actions.js
+++ b/lib/actions/siwe-actions.js
@@ -1,6 +1,7 @@
// @flow
import threadWatcher from '../shared/thread-watcher.js';
+import type { LogInResponse } from '../types/account-types.js';
import type { SIWEAuthServerCall } from '../types/siwe-types.js';
import type { CallServerEndpoint } from '../utils/call-server-endpoint';
import { getConfig } from '../utils/config.js';
@@ -27,7 +28,7 @@
callServerEndpoint: CallServerEndpoint,
): ((
siweAuthPayload: SIWEAuthServerCall,
-) => Promise<boolean>) => async siweAuthPayload => {
+) => Promise<LogInResponse>) => async siweAuthPayload => {
const watchedIDs = threadWatcher.getWatchedIDs();
const response = await callServerEndpoint(
'siwe_auth',
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
@@ -7,6 +7,7 @@
LogInResult,
RegisterResult,
DefaultNotificationPayload,
+ LogInResponse,
} from './account-types';
import type {
ActivityUpdateSuccessPayload,
@@ -901,7 +902,7 @@
}
| {
+type: 'SIWE_AUTH_SUCCESS',
- +payload?: boolean,
+ +payload: LogInResponse,
+loadingInfo: LoadingInfo,
}
| {

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 26, 6:35 PM (5 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2707978
Default Alt Text
D6060.diff (3 KB)

Event Timeline