但未保存在浏览器中"/>
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,但未保存在浏览器中
发布评论