Skip to content

[QUESTION] req.session.user undefined #929

@angelhdzmultimedia

Description

@angelhdzmultimedia
Node: 19.0.0
express-session: 1.17.3
typescript: 4.9.5
express: 4.18.2
@types/express: 4.17.17
@types/express: 1.17.6
tsx: 3.12.3
App Executed with: tsx src/main.ts

I've clicked every result in Google. I don't find the answer!!!

All the examples I see, does the same thing, yet, my req.session.user is undefined in the next requests after I make the request to /auth/login. In my case /auth/user.

I've tried many combinations of saveUninitialized and resave false/true.

Checked if I had the latest version of express-session.

I'm not using nodemon or tsx --watch, so no, the app restarting isn't reseting the cookies/session.

Then I make the post request to /auth/login, I console.log(req.session.user) and bam, all the user's data is there.

Then I make a get request to /auth/user, and req.session.user is undefined.

I tried using req.session.save() on /auth/login and req.session.reload() on /auth/user.
I've tried using req.session.regenerate().

I'm not using cookie: {secure: true} because I don't haven an HTTPS server.

I'm setting a very high maxAge.

Not using cookie-parser middleware as it's not needed anymore.

Tried moving the app.use(session({...})) to different places in the code.

I'm using Rapid API Client extension in VSCode to make the requests.

I'm using app.use('/api/v2', router) as prefix.

But I noticed something:

If I console.log the req parameter, there's a property sessionStore, which has a property sessions, and inside I can see my user's data!!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions