如何查看Nestjs上的用户角色

发布于 2025-02-06 21:20:09 字数 236 浏览 1 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2025-02-13 21:20:09

您能没有扩展的基本控制器并将装饰器添加到构造函数之类的东西吗?

另外,请查看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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文