最近我开始学习如何使用 Nuxtjs,在学习如何使用其 Auth 模块时我遇到了一个问题。
我能够登录,并且想检查帐户的范围,我尝试使用“Auth”的“scopeKey”属性来执行此操作。从后端我从数据库获取“范围”,它可以是“用户”或“管理员”。
我尝试设置范围
scopeKey: 'scope'
Run Code Online (Sandbox Code Playgroud)
但我在检查时发现范围是“未定义”/“空”
this.$auth.hasScope('admin') / this.$auth.hasScope('user')
Run Code Online (Sandbox Code Playgroud)
或“this.$auth.hasScope(admin)”将“scopeKey”设置为时返回空值
scopeKey: 'data.scope'
Run Code Online (Sandbox Code Playgroud)
或者
scopeKey: 'user.scope'
Run Code Online (Sandbox Code Playgroud)
这是我的身份验证策略:
auth: {
strategies: {
local: {
scopeKey: 'scope',
endpoints: {
login: {
url: 'api/auth/login',
method: 'post',
propertyName: 'token',
},
logout: {
url: 'api/auth/logout',
method: 'get'
},
user: {
url: 'api/me',
method: 'get',
propertyName: data
}
}
}
},
redirect: {
login: '/auth/login',
logout: '/',
callback: '/auth/login',
home: '/dash/'
}
}
Run Code Online (Sandbox Code Playgroud)
这是我登录时 auth 模块读取的 json 示例:
"data": {
"id": 2,
"name": "test1", …Run Code Online (Sandbox Code Playgroud)