i use expessJS, cookiePaser and try access cookie but it always return undefined eventhough it has been set on browser
this is options cors
<code>app.use(
cors({
origin: "http://localhost:3000",
credentials: true,
})
);
app.use(cookieParser());
</code>
<code>app.use(
cors({
origin: "http://localhost:3000",
credentials: true,
})
);
app.use(cookieParser());
</code>
app.use(
cors({
origin: "http://localhost:3000",
credentials: true,
})
);
app.use(cookieParser());
this is fetch
<code>const res = await fetch("http://localhost:3001/api/auth/signin", {
method: "POST",
credentials: 'include',
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(formData),
});
</code>
<code>const res = await fetch("http://localhost:3001/api/auth/signin", {
method: "POST",
credentials: 'include',
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(formData),
});
</code>
const res = await fetch("http://localhost:3001/api/auth/signin", {
method: "POST",
credentials: 'include',
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(formData),
});
this is set cookie
<code>res.cookie("access_token", token, {
httpOnly: true,
expires: new Date(Date.now() + 24 * 60 * 60 * 1000),
sameSite: 'None',
})
</code>
<code>res.cookie("access_token", token, {
httpOnly: true,
expires: new Date(Date.now() + 24 * 60 * 60 * 1000),
sameSite: 'None',
})
</code>
res.cookie("access_token", token, {
httpOnly: true,
expires: new Date(Date.now() + 24 * 60 * 60 * 1000),
sameSite: 'None',
})
Every time I access the cookie it returns undefined.
New contributor
kain1910 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.