Req.cookies is undefined whilst req.headers.cookie contains the cookies, I am using cookie-session and express. I am declaring cookie-session before the routes. For refrence I grabbed my code from this article: https://medium.com/@manishsharma8301/google-oauth-using-passport-js-how-to-get-started-46a200c1fec3
Only difference is that I am using spotify oauth instead.
app.use(
cors({
origin: "http://localhost:8888",
methods: "GET, HEAD, PUT, PATCH, POST, DELETE",
credentials: true
})
)
app.use(bodyParser.json());
app.use(cookieSession({
name: 'session-name',
keys: ['key1', 'key2']
}));
app.use(passport.initialize());
app.use(passport.session());
app.use('/', authRoutes);
app.listen(8888, () => console.log(`App listening on port ${8888}`));
As per doc:
So see if the cookie is attached to the req.session not req.cookie.
Reference :
https://www.npmjs.com/package/cookie-session#:~:text=Create%20a%20new,from%20the%20request.
An example which i got working with your code was
// Result of get('/') 1 view and increments on reload