gpt4 book ai didi

roles - 在 Meanjs 中添加用户角色

转载 作者:行者123 更新时间:2023-12-04 03:24:23 26 4
gpt4 key购买 nike

最近我开始使用MeanJs,它非常神奇,但我不明白一些东西。我需要为我的后端创建一个简单的用户管理。

他们在官方博客上说:

New usability features: Added roles to the User model - the defaults are ‘user’ and ‘admin’, you can add and remove them as needed.

经过搜索,我找到了一些例子,但所有这些都是关于meanio,而不是meanjs,meanio中有一个包MEAN-ADMIN可以为我们做这件事,但在meanjs中我没有找到。

有人知道实现用户管理的最佳方法吗?一些例子?

谢谢大家。

最佳答案

meanjs 生成器内置了一些基本的用户角色。角色是用户模型上的一个数组。

roles: {
type: [{
type: String,
enum: ['user', 'admin']
}],
default: ['user']
},

要添加具有管理员角色的用户,只需在保存之前将其附加到用户对象即可。

user.roles = ['admin'];

如果您想使用管理员和用户之外的角色,您需要将 then 添加到类型枚举中。

关于roles - 在 Meanjs 中添加用户角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28702324/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com