Reputation: 9251
I have my front end running on one Heroku instance: fe.herokuapp.com
And my back end running on another instance: be.herokuapp.com
I want to set a same domain cookie when a user logs in from the front end.
I am using Koa cookies module to set the cookie like so:
cookies.set("accessToken", token, {
maxAge: 1000 * 60 * 24,
signed: true,
secure: process.env.NODE_ENV === "production",
httpOnly: true,
domain: process.env.ORIGIN_HOSTNAME || "localhost"
})
If it helps, I'm using a React front end and a Node back end (using Koa).
Via Postman, my back end returns the following set-cookie header:
accessToken=<access_token>; path=/; expires=Sun, 01 Sep 2019 16:27:24 GMT; domain=.herokuapp.com; secure; httponly
However, via my React app, I can't see any set-cookie headers.
My front end is using isomorphic-unfetch
library with credentials = "include"
. (perhaps this needs to be same-origin
since it's on the same subdomain?)
My two questions are:
fe.herokuapp.com
?Happy to post more code snippets if need be.
Upvotes: 4
Views: 841
Reputation: 457
herokuapp.app
is listed in Public suffix
List which means cookies are blocked from bein set to the domain "herokuapp.com"
you must use custom domain technique
Upvotes: 2
Reputation: 2010
Stuck with this issue for some time. What I figured out:
const app = new Koa()
app.proxy = true
cookies.set("accessToken", token, {
maxAge: 1000 * 60 * 24,
signed: true,
secure: process.env.NODE_ENV === "production",
httpOnly: true,
domain: process.env.ORIGIN_HOSTNAME || "localhost",
sameSite: 'none' // <-- add this
})
Before that I bought a domain for my app. Frontend app point to "domain.com", and Backend app point to "api.domain.com". But now I am not sure if it was necessary.
Upvotes: 0