Axios 即使 withCredentials:true 也不会发送 cookie
Axios is not sending cookies even with withCredentials:true
我的 node.js nuxtjs 应用程序有问题。我正在向 api 发送带有 axios 的请求,并且在登录请求时我通常会收到 cookie。一切都适用于从服务器接收 cookie,但是当我获取另一个页面时,cookie 不会随之发送。这是我在 nodejs 上的选项:
let options = { credentials: true, origin: "http://localhost:3000" };
app.use(cors(options))
这是 axios 请求:
export default async function ({ store, redirect }) {
try {
const res = await axios.get('http://127.0.0.1:5000/test', {
withCredentials: true,
credentials: 'include',
allowCredentials: true,
})
console.error(res)
store.commit('setAccess', res.data.access)
} catch {
return redirect('/register')
}
}
有什么想法吗?谢谢你的时间。
证明我的错误。我认为 nuxtjs 中间件在客户端是 运行,这是不正确的。所以没有发送cookie。我通过重定向到 auth 页面(可以是 运行 一些不错的纺车)并将刷新令牌提交到服务器并获取新令牌来解决它。
感谢您的时间和想法!
我的 node.js nuxtjs 应用程序有问题。我正在向 api 发送带有 axios 的请求,并且在登录请求时我通常会收到 cookie。一切都适用于从服务器接收 cookie,但是当我获取另一个页面时,cookie 不会随之发送。这是我在 nodejs 上的选项:
let options = { credentials: true, origin: "http://localhost:3000" };
app.use(cors(options))
这是 axios 请求:
export default async function ({ store, redirect }) {
try {
const res = await axios.get('http://127.0.0.1:5000/test', {
withCredentials: true,
credentials: 'include',
allowCredentials: true,
})
console.error(res)
store.commit('setAccess', res.data.access)
} catch {
return redirect('/register')
}
}
有什么想法吗?谢谢你的时间。
证明我的错误。我认为 nuxtjs 中间件在客户端是 运行,这是不正确的。所以没有发送cookie。我通过重定向到 auth 页面(可以是 运行 一些不错的纺车)并将刷新令牌提交到服务器并获取新令牌来解决它。
感谢您的时间和想法!