如何查看Nestjs上的用户角色
我正在使用Nestjs进行一个项目。
我想防止除一个控制器以外的所有控制器中具有特定角色的用户。
我知道,将 @role(userrole.guest)
@useguard(coledguard)添加 添加到每个控制器。
但是我有很多控制器,并且将一遍又一遍地添加更多的控制器。
有没有办法像中间件一样一次完成所有操作?
谢谢你!
I am making a project using nestjs.
I want to prevent users with a specific role in all controllers except for one controller.
I know, add @UseGuard(RoleGuard)
@Role(UserRole.Guest)
to each controller.
But I have a lot of controllers, and more will be added over and over again.
Is there a way to do it all at once like middleware?
thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能没有扩展的基本控制器并将装饰器添加到构造函数之类的东西吗?
另外,请查看
useGlobalpipes
查看是否可以帮助共享请求逻辑。Could you not have a base controller that you extend and add the decorator to the constructor or something?
Also, check out
useGlobalPipes
to see if that can help with shared request logic.