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

State in cookie doesn't changes on Fastify #113

Open
5d-jh opened this issue Jul 30, 2024 · 0 comments
Open

State in cookie doesn't changes on Fastify #113

5d-jh opened this issue Jul 30, 2024 · 0 comments

Comments

@5d-jh
Copy link

5d-jh commented Jul 30, 2024

When using with @fastify/passport and @fastify/secure-session, sometimes authentication doesn't work. It sends Forbidden on callback url which corresponds to verify step in this library.

After some inspection, I found that @fastify/secure-session doesn't flushes any changes made on the library. I resolved this issue by calling touch method every time when it's being modified.

--- a/lib/state/session.js
+++ b/lib/state/session.js
@@ -49,6 +49,7 @@ SessionStore.prototype.store = function(req, ctx, appState, meta, cb) {
 
   if (!req.session[key]) { req.session[key] = {}; }
   req.session[key].state = state;
+  req.session.touch();
 
   cb(null, handle);
 };
@@ -81,6 +82,7 @@ SessionStore.prototype.verify = function(req, handle, cb) {
   if (Object.keys(req.session[key]).length === 0) {
    delete req.session[key];
   }
+  req.session.touch();
 
   if (state.handle !== handle) {
    return cb(null, false, { message: 'Invalid authorization request state.' });

My suggestion is to call touch method if it's available for fastify compatibility

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

No branches or pull requests

1 participant