然后使用nuxtjs/auth
和nuxtjs/axios
nuxt忽略了我的代理配置。
过去,我只使用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' }
}
}
}
},
// ..
// Component
async userLogin() {
try {
let response = await this.$auth.loginWith('local', { data: this.login })
console.log(response)
} catch (err) {
console.log(err)
}
}
我的Nuxt在http:// localhost:3000上运行
我的客户端始终尝试连接到http:// localhost:3000 / api / auth / login
但是我需要http:// localhost:4000 / auth / login
我使用最新的所有模块