Skip to content

Commit

Permalink
Add better error messaging if the authentication server is closed due…
Browse files Browse the repository at this point in the history
… to configuration
  • Loading branch information
slmnio committed Oct 12, 2022
1 parent 8f30b75 commit 754f772
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/src/discord/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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());
Expand Down

0 comments on commit 754f772

Please sign in to comment.