I cannot see the cookies using fetch in react but I can see the cookies in thunderclient

<Button
onClick={async () => {
console.log("log bth clk");
const response = await fetch("http://localhost:3000/login", {
mode: "cors",
method: "POST",
headers: {
"Content-Type": "application/json;charset=utf-8",
},
// credentials: "same-origin",
credentials: "include",
body: JSON.stringify({ username, password }),
});
const headers = response.headers;
const json = await response.json();
if (response.status == 400) {
setErrors(json.errors);
} else {
console.log(json, headers, headers.get("a"));
}
// console.log(errors, json);
}}
>
Login
</Button>
<Button
onClick={async () => {
console.log("log bth clk");
const response = await fetch("http://localhost:3000/login", {
mode: "cors",
method: "POST",
headers: {
"Content-Type": "application/json;charset=utf-8",
},
// credentials: "same-origin",
credentials: "include",
body: JSON.stringify({ username, password }),
});
const headers = response.headers;
const json = await response.json();
if (response.status == 400) {
setErrors(json.errors);
} else {
console.log(json, headers, headers.get("a"));
}
// console.log(errors, json);
}}
>
Login
</Button>
SERVER
res.cookie('a', 1).status(200).json({ msg: "Pass match", accessToken })
res.cookie('a', 1).status(200).json({ msg: "Pass match", accessToken })
OUTPUT in image what am i doing wrong?
No description
4 Replies
ἔρως
ἔρως8mo ago
is the cookie set to http only?
Satcha Takam
Satcha Takam8mo ago
for a more clear and concise code I think you should use the axios library for the fetch operations along with try/catch syntax
Electronic
Electronic8mo ago
Have you checked your application tab in dev tools and it isn't their What you console logged isn't supposed to have the cookies in the log
ἔρως
ἔρως8mo ago
wrong ping
Want results from more Discord servers?
Add your server