I have the following scenario with both my FE and BE hosted on Heroku's free dynos.
My Express BE sets a cookie in the following way on POST Login request:
router.post('/login', isGuest, async (req, res) => {
const { email, password } = req.body;
try {
let { token, userId, userEmail, userAvatar } = await authService.login({
email,
password,
});
res.status(200).json({
userId,
userEmail,
userAvatar,
});
res.cookie(AUTH_COOKIE_NAME, token, {
secure: true,
sameSite: 'none',
});
} catch (error) {
res.status(500).json({ message: error.message });
}
});
This is my CORS configuration:
const corsConfig = {
credentials: true,
origin: true,
};
This works great on Chrome and FF, but on Safari the cookie is not being set. I read through all the issues on Safari not being able to set cookies and tried to specify a domain in the cookie. I also tried chaining the response answer like this res.cookie(...).status(200).json()
but still had no luck.
Any ideas on what should I change so I can set the cookie successfully on Safari too?
If I can add any further information that could be helpful let me know.