-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: maxAge description in readme #227
Conversation
@@ -68,7 +68,7 @@ Prefix for the value of the cookie. This is useful for compatibility with `expre | |||
##### cookie | |||
The options object is used to generate the `Set-Cookie` header of the session cookie. May have the following properties: | |||
* `path` - The `Path` attribute. Defaults to `/` (the root path). | |||
* `maxAge` - A `number` in milliseconds that specifies the `Expires` attribute by adding the specified milliseconds to the current date. If both `expires` and `maxAge` are set, then `maxAge` is used. | |||
* `maxAge` - A `number` in seconds that specifies the `Expires` attribute by adding the specified seconds to the current date. If both `expires` and `maxAge` are set, then `maxAge` is used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you point out where it is being interpreted as seconds? I understand the cookie spec defines it as seconds, but the implementation looks to be in milliseconds:
Lines 42 to 46 in 25b4f6b
set maxAge (ms) { | |
this.expires = new Date(Date.now() + ms) | |
// we force the same originalMaxAge to match old behavior | |
this.originalMaxAge = ms | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! I was followed by the typings and they brought me here, which seems to be the issue with the typings, not with the readme. maxAge
from @fastify/cookie
is described like a value in seconds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are use cases setting maxAge
in milliseconds? Seems like it's a common practice to set in seconds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think we should swap out this cookie module with the one from fastify/cookie
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that would mean that major version should be increased, which doesn't seem like a significant change) So probably a fix to the typings would be more then enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see - can you point to where the issue is in types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are use cases setting
maxAge
in milliseconds?
JavaScript's date handling is based upon milliseconds, not seconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are use cases setting
maxAge
in milliseconds?JavaScript's date handling is based upon milliseconds, not seconds.
I meant that it's common to set the age for cookies in seconds. So from the dev side it's easier to think in this level of abstraction rather then how the language handles dates.
Hey @gurgunday (or whom it may concern), sorry for bringing up a stale issue again. I believe there is still an issue here. This is my most recent observation. In the typing file, @fastify/session/types/types.d.ts import { CookieSerializeOptions } from "@fastify/cookie"
...
export interface CookieOptions extends Omit<CookieSerializeOptions, 'signed'> {} This means when user hover over the property, they will believe that the unit is seconds, which contradicts the implementation. If we continue with the milliseconds implementation, more typescript users could build applications with the wrong assumption that the value is seconds. I see two options:
|
I think we should do both 😅 Can you first make a PR to main with the first option, and we can follow up with the second for the next branch |
See #245 |
Thanks for the try! |
There is a mistake in
maxAge
description - should beseconds
instead ofmilliseconds
Checklist
npm run test
andnpm run benchmark
and the Code of conduct