Req.user未定义,但在通过Postman应用发送相同的帖子请求时工作正常

时间:2019-06-25 06:03:06

标签: node.js reactjs passport.js

当我通过提取将发布请求发送到我的节点服务器时,它成功地序列化了用户,但req.user却未定义。但是在Postman中测试时效果很好

我尝试在获取请求中包含凭据:“ include”。然后出现错误,指出“无法加载http://localhost:4444/login:对预检请求的响应未通过访问控制检查:响应中的'Access-Control-Allow-Origin'标头的值不能为通配符'* “当请求的凭据模式为'include'时。因此不允许访问来源'http://localhost:3000'。”出来。

我包括了

app.use(
  cors({
    credentials: true,
    origin: "http://localhost:3000/sign-in"
  })
);

但是跨源请求仍然存在

这是我的提取要求的代码

fetch("http://localhost:4444/login", {
      method: "POST",
      headers: {
        "Content-Type": "application/json"
      },
      credentials: "include",
      body: JSON.stringify({
        username: this.state.username,
        password: this.state.password
      })
    })

0 个答案:

没有答案