Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3492042
D11267.id38027.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D11267.id38027.diff
View Options
diff --git a/keyserver/src/user/login.js b/keyserver/src/user/login.js
--- a/keyserver/src/user/login.js
+++ b/keyserver/src/user/login.js
@@ -7,6 +7,7 @@
import { ServerError } from 'lib/utils/errors.js';
import { retrieveAccountKeysSet } from 'lib/utils/olm-utils.js';
+import type { UserCredentials } from './checks.js';
import {
saveIdentityInfo,
fetchIdentityInfo,
@@ -15,38 +16,60 @@
import { getMessageForException } from '../responders/utils.js';
import { fetchCallUpdateOlmAccount } from '../updaters/olm-account-updater.js';
-type UserCredentials = { +username: string, +password: string };
-
// After register or login is successful
function markKeysAsPublished(account: OlmAccount) {
account.mark_prekey_as_published();
account.mark_keys_as_published();
}
+async function getUserCredentials(): Promise<UserCredentials> {
+ const userInfo = await getCommConfig<UserCredentials>({
+ folder: 'secrets',
+ name: 'user_credentials',
+ });
+
+ if (!userInfo) {
+ throw new ServerError('missing_user_credentials');
+ }
+
+ if (
+ userInfo.usingIdentityCredentials === undefined &&
+ process.env.NODE_ENV === 'development'
+ ) {
+ console.warn(
+ 'Keyserver is not set up to use identity credentials' +
+ '\nUsing identity credentials is optional for now' +
+ '\nYou can restart nix to set up a new keyserver ' +
+ 'with identity credentials' +
+ '\nFor keyservers running in Docker, refer to ' +
+ 'https://www.notion.so/commapp/Running-two-keyservers-4295f98e7b0547d4ba027ba52c2d2e80?pvs=4#1f4178200d2b442bb7fa05dca447f406',
+ );
+ }
+
+ return userInfo;
+}
+
async function verifyUserLoggedIn(): Promise<IdentityInfo> {
+ const userInfoPromise = getUserCredentials();
+
const result = await fetchIdentityInfo();
if (result) {
return result;
}
- const identityInfo = await registerOrLogIn();
+ const userInfo = await userInfoPromise;
+
+ const identityInfo = await registerOrLogIn(userInfo);
await saveIdentityInfo(identityInfo);
return identityInfo;
}
-async function registerOrLogIn(): Promise<IdentityInfo> {
+async function registerOrLogIn(
+ userInfo: UserCredentials,
+): Promise<IdentityInfo> {
const rustAPIPromise = getRustAPI();
- const userInfo = await getCommConfig<UserCredentials>({
- folder: 'secrets',
- name: 'user_credentials',
- });
-
- if (!userInfo) {
- throw new ServerError('missing_user_credentials');
- }
-
const {
identityKeys: notificationsIdentityKeys,
prekey: notificationsPrekey,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 9:53 PM (20 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2678961
Default Alt Text
D11267.id38027.diff (2 KB)
Attached To
Mode
D11267: [keyserver] Print warnings if usingIdentityCredentials not set
Attached
Detach File
Event Timeline
Log In to Comment