0

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. :)

Cat DBB
  • 1
  • 3
  • 1
    Does this answer your question? [CORS: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true](https://stackoverflow.com/questions/19743396/cors-cannot-use-wildcard-in-access-control-allow-origin-when-credentials-flag-i) – Heiko Theißen May 01 '23 at 11:17
  • Incidentally, those `sameSite` and `secure` properties make no sense in the context of Express.js's CORS middleware. – jub0bs May 01 '23 at 11:31

0 Answers0