Express 返回 Cookie,但未保存在浏览器中

编程入门 行业动态 更新时间:2024-10-27 10:31:30

Express 返回 Cookie,<a href=https://www.elefans.com/category/jswz/34/1771168.html style=但未保存在浏览器中"/>

Express 返回 Cookie,但未保存在浏览器中

我将我的登录请求从前端发送到后端,后端服务器只返回 cookie,它在 ssl/lock 区域可见,但不保存在应用程序选项卡中

我使用 axios 发送请求,将 Crredentials 设置为 true

    const api = axios.create({
  baseURL: "http://localhost:8080",
  withCredentials: true,
  headers: {
    "Content-type": "application/json",
    "Access-Control-Allow-Credentials": "true",
    "Access-Control-Allow-Origin": "http://localhost:3000",
  },
});
export const loginManager = async (values) => {
  try {
    const response = await api.post("auth/login", values, {
      withCredentials: true,
      headers: {
        "Content-type": "application/json",
        "Access-Control-Allow-Origin": "http://localhost:3000",
      },
    });

    return response?.data;
  } catch (error) {
    if (error.response) {
      // The request was made and the server responded with a status code
      // that falls out of the range of 2xx
      return error.response.data;
    } else if (error.request) {
      // The request was made but no response was received
      // `error.request` is an instance of XMLHttpRequest in the browser
      // and an instance of http.ClientRequest in node.js

      return error.request;
    } else {
      // Something happened in setting up the request that triggered an Error

      return error.message;
    }
  }
};
回答如下:

更多推荐

Express 返回 Cookie,但未保存在浏览器中

本文发布于:2024-05-13 15:23:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1759842.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:但未   器中   Express   Cookie

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!