环回 ACL 隐藏 'apikey' 列
Loopback ACL hide 'apikey' column
我有一个用户模型,其中一列是 'apikey'。我只希望 'apikey' 只能由其用户访问。
我是否应该使用不同的模型,例如 'Account' 哪些列是 'apikey' 及其 ID,并为该模型创建 ACL?
或者,我应该调整远程方法吗?
关于如何做到这一点有什么建议吗?
我会根据用户权限删除 属性 apikey
,然后再给客户端回复。
这是一个代码示例,您应该根据自己的需要进行调整。
User.afterRemote('findById', (context, user, next) => {
let userId = context.req.accessToken.userId
if (!userId || user.id !== userId) {
context.result.apykey = undefined
}
next()
})
我有一个用户模型,其中一列是 'apikey'。我只希望 'apikey' 只能由其用户访问。
我是否应该使用不同的模型,例如 'Account' 哪些列是 'apikey' 及其 ID,并为该模型创建 ACL?
或者,我应该调整远程方法吗?
关于如何做到这一点有什么建议吗?
我会根据用户权限删除 属性 apikey
,然后再给客户端回复。
这是一个代码示例,您应该根据自己的需要进行调整。
User.afterRemote('findById', (context, user, next) => {
let userId = context.req.accessToken.userId
if (!userId || user.id !== userId) {
context.result.apykey = undefined
}
next()
})