From 3f5e5fdca6c6f748b8227c4a362687ccaa39bc29 Mon Sep 17 00:00:00 2001 From: davinci Date: Tue, 5 Mar 2024 13:54:27 +0100 Subject: [PATCH] fix: auth flow decision admin/url --- src/daemon/authorize.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/daemon/authorize.ts b/src/daemon/authorize.ts index cb9721b..7f500da 100644 --- a/src/daemon/authorize.ts +++ b/src/daemon/authorize.ts @@ -25,12 +25,25 @@ export async function requestAuthorization( if (baseUrl === undefined) { const config = await admin.config(); baseUrl = config.baseUrl; - console.log('baseUrl', baseUrl); + } + + let userRecord: any + + if(keyName) { + const [username, domain] = keyName.split("@"); + + if (!username || !domain) { + return + } + + userRecord = await prisma.user.findUnique({ + where: { username, domain } + }); } return new Promise((resolve, reject) => { - if (baseUrl) { - // If we have a URL, request authorization through web + if (baseUrl && (userRecord || method === "create_account")) { + // If we have a URL and user record, request authorization through web urlAuthFlow(baseUrl, admin, remotePubkey, requestId, request, resolve, reject); } else { adminAuthFlow(admin, keyName, remotePubkey, method, param, resolve, reject);