I have a node js service application and a react frontend. I am using Discord oauth and express sessions for authentication to my application frontend.
Everything works flawlessly when running both on locally but I found that when deploying my applications to heroku, my service is setting the cookie to the service's home domain meaning my frontend cannot use it.
(for example the cookie domain is being set to 'fakeservice.herokuapp.com' instead of 'fakefrontend.herokuapp.com)
Obviously this worked locally as both applications were running on local host meaning the cookie host was identical anyway.
Below is by piece of code that is setting the cookie, however if I try and edit the domain or path of the cookie, it wont save to the browser.
The only thing I can change and still have it save is the MaxAge.
All solutions I have read seem to set this domain element in the cookie object but again this stops my cookie from being saved to the browser.
Any help or guidance anyone could give would be greatly apperciated.
app.use(session({
secret: SECRET_GOES_HERE,
store: new Store({
url: MONGODB_URI,
mongoOptions: {useNewUrlParser: true, useUnifiedTopology: true}
}),
cookie: {
maxAge: 7200000,
domain: '.herokuapp.com' << adding this breaks cookie save
},
resave: false,
saveUninitialized: false,
}))
app.use( cors({
credentials: true,
origin:['.herokuapp.com']
}));