我是 nuxt 的新手,我想使用 nuxt 身份验证, 这是我在 nuxt.config.js 中的配置:
auth: {
strategies: {
local: {
token: {
property: 'data.success.data.access_token',
type: 'Bearer'
},
user: {
property: 'data.success.data.user',
autoFetch: true
},
endpoints: {
login: {url: process.env.BASE_URL_API + '/authentication', method: 'post'},
logout: { url: process.env.BASE_URL_API + '/_revoke', method: 'post' },
user: { url: process.env.USER_INFO_URL, method: 'get', propertyName: "data.success.data.user" }
}
},
}
}
这是我从 vue 组件登录的代码
this.$auth.loginWith("local", {
data: {
email: this.auth_email,
password: this.auth_password,
type: this.at,
action: this.actions
}
}).then((response) => { console.log(response) })
还有来自我后端的响应结构(我使用的是 laravel)
{
... ,// some data from laravel like config and else
data: {
success: {
data: {
access_token: "here my token",
user: Object, // my user data
// ... and here some other data
}
}
}
}
登录运行良好,我在 console.log 上得到了预期的响应,但我的状态未设置;登录后,当我检查 vue 工具 vuex 时,busy、loggedIn 和 user 都设置为 false,我的配置有什么问题?,文档说在 property 和 propertyName 上,我们可以根据 json 响应将 complexe 值设置为 data.token 或 data.user .
我的用户获取需要持有令牌才能获得它,我认为这是第一个问题,但我试图将路由放在中间件之外,但同样的事情发生了。