From 754f772762a9872903ec03433277a759531a5e23 Mon Sep 17 00:00:00 2001 From: Solomon Cammack Date: Wed, 12 Oct 2022 15:12:23 +0100 Subject: [PATCH] Add better error messaging if the authentication server is closed due to configuration --- server/src/discord/auth.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/server/src/discord/auth.js b/server/src/discord/auth.js index a91aec70..bc9bda34 100644 --- a/server/src/discord/auth.js +++ b/server/src/discord/auth.js @@ -2,7 +2,8 @@ const bodyParser = require("body-parser"); const fetch = require("node-fetch"); function discordEnvSet() { - return ["DISCORD_CLIENT_ID", "DISCORD_CLIENT_SECRET", "DISCORD_REDIRECT_URI"].every(key => !!process.env[key]); + return ["DISCORD_CLIENT_ID", "DISCORD_CLIENT_SECRET"].every(key => !!process.env[key]) + && ["DISCORD_REDIRECT_DOMAINS", "DISCORD_REDIRECT_URI"].some(key => !!process.env[key]); } function getRequestingDomain(origin) { @@ -14,7 +15,14 @@ function getRequestingDomain(origin) { } module.exports = ({ app, router, cors, Cache, io }) => { - if (!discordEnvSet()) return console.warn("Discord authentication on the server is disabled. Set DISCORD_ keys in server/.env to enable it."); + if (!discordEnvSet()) { + const tempAuthApp = router; + tempAuthApp.options("/*", cors()); + tempAuthApp.post("/*", cors(), (req, res) => res.status(503).send({ error: true, message: "Discord authentication is disabled" })); + app.use("/auth", tempAuthApp); + + return console.warn("Discord authentication on the server is disabled. Set DISCORD_ keys in server/.env to enable it."); + } const authApp = router; authApp.use(bodyParser.json());