From 7bd4263564eebaf22d71cbb8362628e02c6fa956 Mon Sep 17 00:00:00 2001 From: Jerry Yip Date: Thu, 19 Oct 2023 14:22:32 -0700 Subject: [PATCH] add logic for 1st time login with Microsoft (#349) create new account if first time logging in via Microsoft OAuth feature Co-authored-by: Joseph Richardson --- backend/graphql_api/graphql/resolvers/query.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/graphql_api/graphql/resolvers/query.js b/backend/graphql_api/graphql/resolvers/query.js index f2c268b0..481c7385 100644 --- a/backend/graphql_api/graphql/resolvers/query.js +++ b/backend/graphql_api/graphql/resolvers/query.js @@ -221,8 +221,13 @@ module.exports = (logger) => { try { user = await authentication.verifyMicrosoftToken(dbClient, context.token); if (!user.isRegistered) { - logger.error(`User not registered`); - throw new Error(`User not registered`); + // Create new user if first time signing in w/ Microsoft + user = await mutationResolver.createAccount( + dbClient, + { email_address: user.email_address }, + context + ); + return { token: user.token, email: user.email_address }; } token = authentication.createJWT({ rows: [user] }); } catch (e) {