Robert Markovski
Robert Markovski

Reputation: 94

Angular 5 / Node Express each request uses new session

I am developing an application in Angular 5 which connects to my server in NodeJS.

I add the user in the req.session object after the user is logged in.

When I make a second request from Angular 5 app to retrieve something from the API, the req.session doesn't contain the user and the req.sessionId is always different.

How can I make the session persistent?

Here are the session and cookieParser middlewares:

app.use(cookieParser(config.secret))

app.use(session({
    secret: config.secret,
    saveUninitialized: false,
    resave: false,
    cookie: {
        httpOnly: true,
        secure: false
    }
}))

Upvotes: 0

Views: 445

Answers (1)

Robert Markovski
Robert Markovski

Reputation: 94

It was a CORS related issue. I needed to include { withCredentials: true } in the http request options in Angular.

Upvotes: 0

Related Questions