Hi, I am using nuxt programmatically and using serverMiddleware with it's own express instance which modifies req.user on some api endpoints.
However, when I navigate to different routes after mutating req.user, nuxt is overriding req.user with one from an earlier state. I believe it is because the serverMiddleware version and nuxt are using different instances of connect under the hood.
Has anyone else experienced this, and how have you dealt with it?
I can confirm the connect.sid is the same for both the nuxt routes and api routes.
Thank you.
req.user being mutated in api and nuxt routes.
req.user is not mutated in nuxt routes.
Here are steps to repro, adding a few route handlers to the auth example from https://nuxtjs.org/examples/auth-routes/:
app.get('*', function (req, res,next) {
if (!req.session.user) req.session.user = "jimmy"
next()
})
app.get('/mutate', function (req, res) {
req.session.user = "bob"
res.send(200)
})
app.get('/user', function (req, res) {
res.send(req.session.user)
})
/page/123. /user // outputs "jimmy"/mutate // OK/user // outputs "bob" — good! /page/123/user // outputs "jimmy" — ???So it seems as though nuxt is not picking up the changes to req.session that are happening.
@nikkwong Can you add a Codesandbox please (just fork the referred example and add your changes)?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:
Issues that are labeled as 🕐Pending will not be automatically marked as stale.
Most helpful comment
Here are steps to repro, adding a few route handlers to the auth example from https://nuxtjs.org/examples/auth-routes/:
/page/123./user// outputs "jimmy"/mutate// OK/user// outputs "bob" — good!/page/123/user// outputs "jimmy" — ???So it seems as though nuxt is not picking up the changes to req.session that are happening.