From 78b8d18c4ea5bde14c9e7716a1afa7a198336515 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Fri, 27 Jan 2023 15:41:49 +0100 Subject: [PATCH] fix(backend): do not throw when email exists on registration --- backend/src/middleware/login/loginMiddleware.js | 11 +++++++---- .../schema/resolvers/helpers/existingEmailAddress.js | 10 +++++----- backend/src/schema/resolvers/registration.js | 7 ++++++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/backend/src/middleware/login/loginMiddleware.js b/backend/src/middleware/login/loginMiddleware.js index 3cd2158c2..cd8ab64ee 100644 --- a/backend/src/middleware/login/loginMiddleware.js +++ b/backend/src/middleware/login/loginMiddleware.js @@ -10,10 +10,13 @@ const sendSignupMail = async (resolve, root, args, context, resolveInfo) => { const { inviteCode } = args const response = await resolve(root, args, context, resolveInfo) const { email, nonce } = response - if (inviteCode) { - await sendMail(signupTemplate({ email, variables: { nonce, inviteCode } })) - } else { - await sendMail(signupTemplate({ email, variables: { nonce } })) + if (nonce) { + // emails that already exist do not have a nonce + if (inviteCode) { + await sendMail(signupTemplate({ email, variables: { nonce, inviteCode } })) + } else { + await sendMail(signupTemplate({ email, variables: { nonce } })) + } } delete response.nonce return response diff --git a/backend/src/schema/resolvers/helpers/existingEmailAddress.js b/backend/src/schema/resolvers/helpers/existingEmailAddress.js index 717d0d904..288a14a6d 100644 --- a/backend/src/schema/resolvers/helpers/existingEmailAddress.js +++ b/backend/src/schema/resolvers/helpers/existingEmailAddress.js @@ -1,5 +1,3 @@ -import { UserInputError } from 'apollo-server' - export default async function alreadyExistingMail({ args, context }) { const session = context.driver.session() try { @@ -20,9 +18,11 @@ export default async function alreadyExistingMail({ args, context }) { }) }) const [emailBelongsToUser] = await existingEmailAddressTxPromise - const { alreadyExistingEmail, user } = emailBelongsToUser || {} - if (user) throw new UserInputError('A user account with this email already exists.') - return alreadyExistingEmail + /* + const { alreadyExistingEmail, user } = + if (user) throw new UserInputError('A user account with this email already exists.') + */ + return emailBelongsToUser || {} } finally { session.close() } diff --git a/backend/src/schema/resolvers/registration.js b/backend/src/schema/resolvers/registration.js index 52c92b033..c988acfb2 100644 --- a/backend/src/schema/resolvers/registration.js +++ b/backend/src/schema/resolvers/registration.js @@ -13,7 +13,12 @@ export default { args.nonce = generateNonce() args.email = normalizeEmail(args.email) let emailAddress = await existingEmailAddress({ args, context }) - if (emailAddress) return emailAddress + /* + if (emailAddress.user) { + // what to do? + } + */ + if (emailAddress.alreadyExistingEmail) return emailAddress.alreadyExistingEmail try { emailAddress = await neode.create('EmailAddress', args) return emailAddress.toJson()