mirror of
https://github.com/20kaushik02/spotify-manager.git
synced 2025-12-06 09:04:06 +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 ?? "",
|
||||
id: resp.data.id,
|
||||
};
|
||||
|
||||
// res.status(200).send({ message: "OK" });
|
||||
res.redirect(process.env["SPOTMGR_APP_URI"] + "?login=success");
|
||||
logger.debug("New login.", { username: resp.data.display_name });
|
||||
req.session.save((err) => {
|
||||
if (err) {
|
||||
res.status(500).send({ message: "Login failed" });
|
||||
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;
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
10
index.ts
10
index.ts
@ -25,18 +25,16 @@ import logger from "./utils/logger.ts";
|
||||
const app = express();
|
||||
|
||||
// check env vars
|
||||
if (
|
||||
isNaN(Number(process.env["SPOTMGR_TRUST_PROXY"])) ||
|
||||
![0, 1].includes(Number(process.env["SPOTMGR_TRUST_PROXY"]))
|
||||
) {
|
||||
throw new TypeError("SPOTMGR_TRUST_PROXY must be 0 or 1");
|
||||
const trustProxySetting = Number(process.env["SPOTMGR_TRUST_PROXY"]);
|
||||
if (isNaN(trustProxySetting)) {
|
||||
throw new TypeError("SPOTMGR_TRUST_PROXY must be a number");
|
||||
}
|
||||
if (!process.env["SPOTMGR_SESSION_SECRET"]) {
|
||||
throw new TypeError("SPOTMGR_SESSION_SECRET cannot be undefined");
|
||||
}
|
||||
|
||||
// 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 });
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user