const permissionLost = await authing.userPermissionList("USER ID")
{
totalCount: 1,
list: [
{
_id: '5e20082f4b6419665991fa57',
name: "invoice:submit",
description: '提交发票报销申请。',
}
],
rawList: ['invoice:submit']
}
const permissionLost = await authing.userRoleList("USER ID")
{
totalCount: 2,
list: [
{
_id: '5e20082f4b6419665991fa57',
name: 'Invoice Submitter',
description: '能使用发票工具创建并读取发票工具记录。'
},
{
_id: '5e20082f4b6419665991fa58',
name: 'Vacation Requester',
description: '能使用假期申请工具申请假期。'
},
],
rawList: [
"Invoice Submitter",
"Vacation Requester"
]
}
const permissionLost = await authing.userGroupList("USER ID")
{
totalCount: 2,
list: [
{
_id: '5e1fff324b6419665991f6b4',
name: 'employee',
description: '正式员工。'
},
{
_id: '5e1edcb34b6419665991f5d9',
name: 'intern',
description: '实习生。'
},
],
rawList: ["employee", "intern"]
}
app.get('/api/example', async (req, res) => {
const userId = req.user._id;
const res = await authing.userPermissionList(userId)
const { rawList: permissions } = res;
if(permissions.indexOf('invoice:submit') === -1){
res.json({
code: 403,
message: "没有权限访问"
})
}
// ...
})