equ*_*ser 6 authentication proxy axios nuxt.js nuxtjs
然后使用nuxtjs/auth和nuxtjs/axiosnuxt 忽略我的代理配置。
过去我只使用 axios 进行身份验证。
现在我正在尝试使用 @nuxtjs/auth 模块。因为我使用单独的后端和 CORS,所以我需要使用 axios 代理进行身份验证。
但是身份验证策略local不使用代理,我不明白为什么。它总是尝试使用 nuxt URL。似乎 auth 完全忽略了我的代理。任何人都可以帮忙吗?
// nuxt.config
// ...
axios: {
proxy: true
},
proxy: {
'/api/': {
target: 'http://localhost:4000',
pathRewrite: { '^/api/': '' }
}
},
/*
** Auth Module Configuration
** See https://auth.nuxtjs.org/schemes/local.html
*/
auth: {
strategies: {
local: {
endpoints: {
login: { url: '/api/auth/login', method: 'post', propertyName: 'token' },
logout: { url: '/api/auth/logout', method: 'post' },
user: { url: '/api/auth/user', method: 'get', propertyName: 'user' }
}
}
}
},
// ..
Run Code Online (Sandbox Code Playgroud)
// Component
async userLogin() {
try {
let response = await this.$auth.loginWith('local', { data: this.login })
console.log(response)
} catch (err) {
console.log(err)
}
}
Run Code Online (Sandbox Code Playgroud)
我的 Nuxt 在 http://localhost:3000 上运行
我的客户端总是尝试连接到 http://localhost:3000/api/auth/login
但我需要 http://localhost:4000/auth/login
我使用最新的所有模块
小智 -2
对象proxy应该在axios对象之外,即
axios: {
proxy: true,
// Your other configurations
}
proxy: {
'/api/': {
target: 'http://localhost:4000',
pathRewrite: { '^/api/': '' }
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
665 次 |
| 最近记录: |