From ced6d5e4bbc80a5b08f38db98727ec561bda5632 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Thu, 11 Nov 2021 12:31:45 +0100 Subject: [PATCH] Don't sign in user when trying to connect a social account that was already created --- website/common/locales/en/front.json | 1 + website/server/libs/auth/social.js | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/website/common/locales/en/front.json b/website/common/locales/en/front.json index 58c3e06b80..9b1fae34ef 100644 --- a/website/common/locales/en/front.json +++ b/website/common/locales/en/front.json @@ -133,6 +133,7 @@ "unsupportedNetwork": "This network is not currently supported.", "cantDetachSocial": "Account lacks another authentication method; can't detach this authentication method.", "onlySocialAttachLocal": "Local authentication can be added to only a social account.", + "socialAlreadyExists": "This social login is already linked to an existing Habitica account.", "invalidReqParams": "Invalid request parameters.", "memberIdRequired": "\"member\" must be a valid UUID.", "heroIdRequired": "\"heroId\" must be a valid UUID.", diff --git a/website/server/libs/auth/social.js b/website/server/libs/auth/social.js index 02e4d64faf..48f9731d11 100644 --- a/website/server/libs/auth/social.js +++ b/website/server/libs/auth/social.js @@ -1,6 +1,6 @@ import passport from 'passport'; import common from '../../../common'; -import { BadRequest } from '../errors'; +import { BadRequest, NotAuthorized } from '../errors'; import logger from '../logger'; import { generateUsername, @@ -47,6 +47,9 @@ export async function loginSocial (req, res) { // eslint-disable-line import/pre // User already signed up if (user) { + if (existingUser) { + throw new NotAuthorized(res.t('socialAlreadyExists')) + } return loginRes(user, req, res); }