Skip to content
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

Allow setting a session with the expires prop set #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

bttger
Copy link
Contributor

@bttger bttger commented Oct 11, 2022

The current code was setting the expire value always one day into the future even if the cookie.expires prop was set.

No worries, tests will follow 😅

The current code was setting the `expire` value always one day into the future even if the `cookie.expires` prop was set
@bttger bttger marked this pull request as ready for review October 12, 2022 10:36
@TimDaub
Copy link
Member

TimDaub commented Oct 13, 2022

from: https://github.com/expressjs/session

Note The expires option should not be set directly; instead only use the maxAge option.

Can you address your use case by using maxAge instead of expires? From what I know using expires has become an anti-pattern as everyone that's running a global internet service can't really be dealing with time zones and so defining a relative maxAge in e.g. seconds is much better.

If you're ok with using maxAge then I'd like to close this PR, thanks.

@bttger
Copy link
Contributor Author

bttger commented Oct 13, 2022

I am not using express but fastify and fastify-session. Internally it is setting the expires prop even when I am setting the maxAge prop. I don't like this behavior and don't understand why they decided to always convert both the expires and maxAge prop to cookie.expires.

Here in the test you can see what I mean.

@bttger
Copy link
Contributor Author

bttger commented Oct 13, 2022

I've just seen that it is not fastify who came up with this design choice but express 😅

cookie.maxAge

Specifies the number (in milliseconds) to use when calculating the Expires
Set-Cookie attribute. This is done by taking the current server time and adding
maxAge milliseconds to the value to calculate an Expires datetime.

I think the issue here is not dealing with many time zones (because the Expires value must always be in GMT and it gets "calculated") but because clients can be out of sync with the actual time.

Sorry for bothering you with this. I don't really like this design but I think your library would be the easiest place to "fix" the issue I have. Not sure if it's clever to ask the fastify maintainers to change the behavior of the maxAge prop who, I believe, would like to have a close API/behavior to express.

@TimDaub
Copy link
Member

TimDaub commented Oct 19, 2022

because the Expires value must always be in GMT and it gets "calculated"

I wasn't able to confirm this:

@TimDaub
Copy link
Member

TimDaub commented Oct 19, 2022

I don't understand your problem. From my understanding, both express/session and fastify/session set both expires and maxAge in a similar way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants