-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat(sessions): implement ttl and flash #12693
Conversation
|
Can you update the RFC with the relative information, so we can review the PR? |
@ematipico the RFC has been updated |
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.
Code-wise, I would add more test cases, especially for middleware and rewrites. I also left some questions in the RFC around the .flash
.
Astro.session.flash('flash-value', `Flashed value at ${new Date().toISOString()}`); | ||
return Astro.redirect('/'); |
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 we add more cases, such as:
- usage with
Astro.rewrite
- usage with the
next("/some-route")
(the other form of rewrite): see if the value changes when the next middleware function read from.flash
- usage with multiple middleware functions e.g.
sequence(fn1, fn2)
@@ -138,10 +147,19 @@ export class AstroSession<TDriver extends SessionDriverName = any> { | |||
this.#cookieSet = true; | |||
} | |||
this.#data ??= new Map(); | |||
this.#data.set(key, value); | |||
const lifetime = ttl ?? this.#config.ttl; | |||
const expires = typeof lifetime === 'number' ? Date.now() + lifetime * 1000 : lifetime; |
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 we add a comment that explains the 1000
?
Changes
Adds support for session data expiry. This includes:
ttl
config optionttl
argument toset
session.flash()
, which expires the data after the next requestTesting
Added unit tests
Docs