From 981d0095084b2326fa0d3a324ef2274b652e9e2b Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+Berry-13@users.noreply.github.com> Date: Thu, 13 Jul 2023 00:15:11 +0200 Subject: [PATCH] fix(discordStrategy): only authorize on first login (#626) * Add files via upload * Create linode-setup.md * Create cloudflare-setup.md * Update cloudflare-setup.md * Delete 4-linode.png * Delete 3-linode.png * Add files via upload * Add files via upload * Update cloudflare-setup.md * Update linode-setup.md * Rename cloudflare-setup.md to cloudflare.md * Rename linode-setup.md to linode.md * Update mkdocs.yml * Update cloudflare.md * Update linode.md * Update README.md * Update README.md * Update linode.md sentence in Italian * v1 The frontend has been completed, along with the .env variables. However, there is an issue of infinite loading thereafter. * Fix email and remove deprecated GitHub passport * Update user_auth_system.md add How to Set Up a Github Authentication * Update .env.example Improved the comment above the GitHub client ID and secret. * Update user_auth_system.md * Update package.json * Remove unnecessary passport GitHub package * fixed conflicts fixed conflicts between Berry-13:main and danny-avila:main in api/server/index.js 45:54 * Delete e -i HEAD~2 * (WIP) Discord Login * Fix duplicate githubLoginEnabled * .env.example restore * Update user_auth_system.md Discord Login * Fix and new Feature 1. Added Discord login to .env.example. 2. Created Google, Github, and Discord icons in client\src\components\svg. 3. Added the social login option in the .env file; it fixes the ---or---. Check Discord for more information. * fix Login.tsx and Registration.tsx * Update user_auth_system.md * Update .env.example * Added OpenID Icon * quick discord icon fix * discord strategy fix * remove comment * fix discord authorize every time --- api/strategies/discordStrategy.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/api/strategies/discordStrategy.js b/api/strategies/discordStrategy.js index 428279ebfb..040453d9cd 100644 --- a/api/strategies/discordStrategy.js +++ b/api/strategies/discordStrategy.js @@ -9,23 +9,17 @@ const discordLogin = new DiscordStrategy( clientID: process.env.DISCORD_CLIENT_ID, clientSecret: process.env.DISCORD_CLIENT_SECRET, callbackURL: `${domains.server}${process.env.DISCORD_CALLBACK_URL}`, - scope: ['identify', 'email'] // Request scopes + scope: ['identify', 'email'], // Request scopes + authorizationURL: 'https://discord.com/api/oauth2/authorize?prompt=none' // Add the prompt query parameter }, async (accessToken, refreshToken, profile, cb) => { try { - const discordId = profile.id; const email = profile.email; + const discordId = profile.id; - const existingUser = await User.findOne({ discordId }); - if (existingUser) { - return cb(null, existingUser); - } - - const userWithEmail = await User.findOne({ email }); - if (userWithEmail) { - userWithEmail.discordId = discordId; - await userWithEmail.save(); - return cb(null, userWithEmail); + const oldUser = await User.findOne({ email }); + if (oldUser) { + return cb(null, oldUser); } let avatarURL;