-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Pass session to cookie session factory allowing to modify cookie based on session data #3278
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
base: vapor-5
Are you sure you want to change the base?
Pass session to cookie session factory allowing to modify cookie based on session data #3278
Conversation
I'm writing tests now for this functionality |
This is a no go at the moment as it changes the public API. Here's an example of doing it via middleware https://github.com/brokenhandsio/SteamPress/blob/vapor4/Sources/SteamPress/Middleware/BlogRememberMeMiddleware.swift |
@0xTim, unfortunately, the above solution doesn't work with Vapor 4. I can understand that breaking public API won't go to the Vapor 4 release. Could you consider including it in Vapor 5? |
2b3228f
to
f9178da
Compare
@0xTim I've rebased changes over |
We can definitely look at improving the usability and API for Vapor 5. But that solution should work fine for Vapor 4 since I built it for that |
Hmm, I've tried almost all things, and |
Register the remember me middleware before the sessions middleware and it should work |
When I registered it, before I couldn't access session because it not initalized and fatalError is triggered. |
@rafalwojcik can you show the code? Because the session should be initialised on the way in and then read by the remember me middleware on the way out |
7a05c39
to
374a162
Compare
f9178da
to
ea7e34a
Compare
Motivation
I was struggling to implement a “Remember me” feature for user login. Even after adding middleware like the snippet below, the SessionMiddleware kept overriding my cookie values.
Idea
My proposed solution is to pass the session itself to the cookie factory. This approach allows reading session values set during user login and overriding the default session behavior.
Usage
With this code, the session expires after one day if the user doesn’t select “Remember me,” and after seven days if they do.
Question
Is there another way to solve this issue without requiring any changes from my PR?