diff --git a/backend/api/controllers/user.js b/backend/api/controllers/user.js index f95cc6ac6..286a47b07 100644 --- a/backend/api/controllers/user.js +++ b/backend/api/controllers/user.js @@ -115,6 +115,17 @@ class UserController { static async linkDiscord(req, res, next) { try { const { uid } = req.decodedToken; + + let requser; + try { + requser = await UsersDAO.getUser(uid); + } catch (e) { + requser = null; + } + if (user?.banned === true) { + throw new MonkeyError(403, "Banned accounts cannot link with Discord"); + } + let discordFetch = await fetch("https://discord.com/api/users/@me", { headers: { authorization: `${req.body.data.tokenType} ${req.body.data.accessToken}`, @@ -141,9 +152,6 @@ class UserController { "This Discord account is already linked to a different account" ); } - if (user.banned === true) { - throw new MonkeyError(403, "Banned accounts cannot link with Discord"); - } await UsersDAO.linkDiscord(uid, did); await BotDAO.linkDiscord(uid, did); return res.status(200).json({