Skip to content

Commit

Permalink
Fix express() middleware cookies (#1217)
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowonpaper authored Oct 24, 2023
1 parent 00babe3 commit 7c6a84a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .auri/$15w731jp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
package: "lucia" # package name
type: "patch" # "major", "minor", "patch"
---

Fix `express()` middleware setting incorrect `Max-Age` cookie attribute
2 changes: 1 addition & 1 deletion documentation/content/guidebook/github-oauth/$express.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ app.get("/login/github", async (req, res) => {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
path: "/",
maxAge: 60 * 60
maxAge: 60 * 60 * 1000 // 1 hour
});
return res.status(302).setHeader("Location", url.toString()).end();
});
Expand Down
6 changes: 5 additions & 1 deletion packages/lucia/src/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ export const express = (): Middleware<[ExpressRequest, ExpressResponse]> => {
headers: createHeadersFromObject(req.headers)
},
setCookie: (cookie) => {
res.cookie(cookie.name, cookie.value, cookie.attributes);
const cookieMaxAge = cookie.attributes.maxAge;
res.cookie(cookie.name, cookie.value, {
...cookie.attributes,
maxAge: cookieMaxAge ? cookieMaxAge * 1000 : cookieMaxAge
});
}
} as const satisfies RequestContext;
return requestContext;
Expand Down

0 comments on commit 7c6a84a

Please sign in to comment.