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 @@ -22,30 +22,54 @@ account.mark_keys_as_published(); } +async function getUserCredentials(): Promise { + const userInfo = await getCommConfig({ + 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 { + 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 { +async function registerOrLogIn( + userInfo: UserCredentials, +): Promise { const rustAPIPromise = getRustAPI(); - const userInfo = await getCommConfig({ - folder: 'secrets', - name: 'user_credentials', - }); - - if (!userInfo) { - throw new ServerError('missing_user_credentials'); - } - const { identityKeys: notificationsIdentityKeys, prekey: notificationsPrekey,