axios post 请求的 CORS 问题,不适用于凭据

时间:2021-06-09 21:07:55

标签: javascript express cookies axios cors

登录代码(前端)


const res = await axios.post(config.url, {
   email,
   password
  }, {
    withCredentials: true
})

后端代码

(使用 cookie 解析器)

// cookie response
res.cookie("auth-token", token);
// Express cors middleware

app.use(cors({
  credentials: true
}));

浏览器给我们的错误是 The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.

尝试切换配置,无论如何都不起作用。

0 个答案:

没有答案