mirror of
https://github.com/20kaushik02/spotify-manager.git
synced 2025-12-06 09:54:07 +00:00
trust proxy setting, session save for redirect
This commit is contained in:
parent
1fbab107a2
commit
4a059ce6bd
@ -96,10 +96,17 @@ const callback: RequestHandler = async (req, res) => {
|
|||||||
username: resp.data.display_name ?? "",
|
username: resp.data.display_name ?? "",
|
||||||
id: resp.data.id,
|
id: resp.data.id,
|
||||||
};
|
};
|
||||||
|
req.session.save((err) => {
|
||||||
// res.status(200).send({ message: "OK" });
|
if (err) {
|
||||||
res.redirect(process.env["SPOTMGR_APP_URI"] + "?login=success");
|
res.status(500).send({ message: "Login failed" });
|
||||||
logger.debug("New login.", { username: resp.data.display_name });
|
logger.error("req.session.save", { err });
|
||||||
|
} else {
|
||||||
|
// res.status(200).send({ message: "OK" });
|
||||||
|
res.redirect(process.env["SPOTMGR_APP_URI"] + "?login=success");
|
||||||
|
logger.debug("New login.", { username: resp.data.display_name });
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
10
index.ts
10
index.ts
@ -25,18 +25,16 @@ import logger from "./utils/logger.ts";
|
|||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
// check env vars
|
// check env vars
|
||||||
if (
|
const trustProxySetting = Number(process.env["SPOTMGR_TRUST_PROXY"]);
|
||||||
isNaN(Number(process.env["SPOTMGR_TRUST_PROXY"])) ||
|
if (isNaN(trustProxySetting)) {
|
||||||
![0, 1].includes(Number(process.env["SPOTMGR_TRUST_PROXY"]))
|
throw new TypeError("SPOTMGR_TRUST_PROXY must be a number");
|
||||||
) {
|
|
||||||
throw new TypeError("SPOTMGR_TRUST_PROXY must be 0 or 1");
|
|
||||||
}
|
}
|
||||||
if (!process.env["SPOTMGR_SESSION_SECRET"]) {
|
if (!process.env["SPOTMGR_SESSION_SECRET"]) {
|
||||||
throw new TypeError("SPOTMGR_SESSION_SECRET cannot be undefined");
|
throw new TypeError("SPOTMGR_SESSION_SECRET cannot be undefined");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable this if you run behind a proxy (e.g. nginx)
|
// Enable this if you run behind a proxy (e.g. nginx)
|
||||||
app.set("trust proxy", process.env["SPOTMGR_TRUST_PROXY"]);
|
app.set("trust proxy", trustProxySetting);
|
||||||
|
|
||||||
const redisStore = new RedisStore({ client: redisClient });
|
const redisStore = new RedisStore({ client: redisClient });
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user