使用 express-session 时不保存 cookie

cookies not saving when using express-session

我正在使用 express-session 将 cookie 保存到我的浏览器中,以便我可以使用它进行身份验证。我正在使用 axios 从我的前端(React)向后端发送 post 请求,并使用 User.register 将新用户保存到数据库(mongodb)

我可以将用户保存到我的数据库中,但是我的浏览器中没有保存任何 cookie。

使用 axios 的前端 post 请求:

后端post请求处理程序

在您的服务器中添加此代码

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

客户端 axios 配置

  const Axios= axios.create({
    baseURL: "http://localhost:3001/",
    withCredentials: true,
});