diff --git a/server/src/discord/auth.js b/server/src/discord/auth.js index 5c9d685f..acfe8f9c 100644 --- a/server/src/discord/auth.js +++ b/server/src/discord/auth.js @@ -1,5 +1,6 @@ const bodyParser = require("body-parser"); const fetch = require("node-fetch"); +const { updateRecord } = require("../action-utils/action-utils"); function discordEnvSet() { return ["DISCORD_CLIENT_ID", "DISCORD_CLIENT_SECRET"].every(key => !!process.env[key]) @@ -146,6 +147,11 @@ module.exports = ({ app, router, cors, Cache, io }) => { let airtable = await getAirtablePlayer(discord); + if (![discord.username, `${discord.username}#${discord.discriminator}`].includes(airtable.discord_tag)) { + const updatedUsername = discord.discriminator === "0" ? discord.username : `${discord.username}#${discord.discriminator}`; + await updateRecord(Cache, "Players", airtable, { "Discord Tag": updatedUsername }); + } + return { discord, airtable }; }