Skip to content

Commit

Permalink
fix(cookie): update cookie settings based on environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Cali93 committed Jul 13, 2023
1 parent f10c708 commit c1c8317
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
5 changes: 0 additions & 5 deletions src/handlers/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ export const verifyAndSignIn = async (req: Request, res: Response) => {

const message = new SiweMessage(req.body.message);
const fields = await message.validate(req.body.signature);
console.log({
isProd: process.env.NODE_ENV === "production",
fieldsNonce: fields.nonce,
sessionNonce: req.session.nonce,
});
if (fields.nonce !== req.session.nonce) {
res.status(422).json({
message: `Invalid nonce.`,
Expand Down
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if (!REDIS_PASSWORD) {

// Initialize redis client
const redisClient = new Redis({
host: REDIS_HOST ?? "redis",
host: "localhost" ?? "redis",
port: REDIS_PORT ? parseInt(REDIS_PORT, 10) : 6379,
password: REDIS_PASSWORD,
});
Expand All @@ -62,6 +62,7 @@ app.disable("x-powered-by");
// Enable body parser
app.use(express.json());
app.use(cookieParser(COOKIE_SECRET));
app.set("trust proxy", 1);

const isProd = process.env.NODE_ENV === "production";
const isDev = process.env.NODE_ENV === "development";
Expand Down Expand Up @@ -97,11 +98,12 @@ app.use(
Session({
name: COOKIE_NAME,
secret: COOKIE_SECRET,
resave: true,
saveUninitialized: true,
resave: false,
saveUninitialized: false,
cookie: {
secure: isDev ? false : true,
sameSite: isProd || "none",
sameSite: isProd ? "strict" : "none",
maxAge: 144 * 60 * 60 * 1000,
httpOnly: true,
},
})
Expand Down

0 comments on commit c1c8317

Please sign in to comment.