I have tried
JavaScript
x
4
1
res.setHeader(
2
"Set-Cookie",
3
cookie.serialize("name", "name2", { path: "/", domain: "localhost" })
4
and
JavaScript
1
4
1
res.setHeader(
2
"Set-Cookie",
3
cookie.serialize("name", "name2"))
4
and I have tried to set the cookie outright with
JavaScript
1
4
1
res.setHeader(
2
"Set-Cookie",
3
"name=name"})
4
but no cookie is set when I examine the res, and no cookie is received in my frontend. Everything is run locally. I do not understand why.
Advertisement
Answer
I found the answer. When using fetch() from the front end I didn’t set the credentials flag to include. When I included the flag it worked instantly.
JavaScript
1
4
1
return await fetch(
2
`url`,
3
{ credentials: "include" }
4