I have create localhost website (http://127.0.0.1:5500/registerPage.html) fetch data with POST methods to my API. It running public on vercel's server. So have adding credentials:"includes"
into fetch options like code below.
fetch("https://testing-eight-rosy.vercel.app/api/account/register", {
method: "POST",
body: JSON.stringify({
"pwd": pwd,
"username": new_username,
"password": new_password
}),
headers: {
"Content-type": "application/json",
},
credentials: 'include',
})
.then(res => {
console.log(res);
return res.json();
})
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
Before, I start fetch. I got TypeError: Failed to fetch
. I'm very confuse because, I already accept CORS in my API like my this's code below.
expressApp.use(cors({
origin: "*",
credentials: true,
sameSite: "none",
secure: true,
}));
I'm very confuse please help me. I try to fix this bug all the day and, I'm newbie. :)