I'm developing a nodejs web application, in that I have multiple subdomains like domain.com, sub1.domain.com, sub2.domain.com etc.
if user logs in to sub1.domain.com and gets redirected to domain.com or sub2.domin.com it will give as not logged in,
How can I maintain this session across sub-domains and in main-domain?
I'm using express, nodejs, mongodb.
app.use(session({
secret: "secrete key",
store: new MongoStore({
db: "session-db"
})
}));
I tried setting up like this, didn't work:
app.use(session({
secret: "secret key",
cookie: { domain:'.yourdomain.com'}, // here I used '.localhost'
store: new MongoStore({
db: "session-db"
})
}));