I have a react app deployed on Netlify with a custom https domain, and a node/express app deployed on Heroku (free plan, no custom domain).
All unprotected routes work. However, I can't access protected routes, because the auth cookie is never sent by the front-end. How so? Because the cookie is not properly sent by the server!
Here is how the cookie is sent:
return res
.status(200)
.cookie("myApp", token, {
expires: new Date(Date.now() + msPerDay * 14),
httpOnly: true,
secure: true,
})
.json({ user });
The index.js is:
app.use(cors({ credentials: true, origin: [process.env.CLIENT as string] }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(compression());
app.use(cookieParser());
In the chrome's application tab I can see that no cookie is set. However, it's properly filled in localhost!
How to fix this? If you need more code I'd be happy to provide it, but I don't know if the issue comes from the code itself or a network issue between heroku and my netlify domain... The client is of course whitelisted by cors.