After adding a domain to heroku the cookies stopped being set. They are completely missing. They worked fine without the additional domain.
Thats my code. I tried adding cors but nothing changed.
const sessionOptions = {
store,
name: 'c_ie',
secret,
resave: false,
saveUninitialized: false,
proxy: true,
cookie: {
httpOnly: true,
sameSite: 'none',
secure: true, //https
expires: Date.now() + 1000 * 60 * 60 * 24 * 7,
maxAge: 1000 * 60 * 60 * 24 * 7
}
}
app.use(session(sessionOptions));
app.use(
cors({
origin: "https://mydomain.herokuapp.com/",
credentials: true
})
);
app.set('trust proxy', 1);
I added "two" domains to Heroku: www.mydomain.com and mydomain.com
DNS runs threw cloudflare.
www domain: CNAME www link by heroku that points to the www domain non-www domain: CNAME @ link by heroku that points to non-www domain
the non www-domain is being redirected to the www domain.
I tried changing the sessionOptions a lot but nothing seems to work for me. Have been trying the past 2 weeks..
Solution:
I switched cloudflare proxy to dns only. Thats it.