Question:
There was no answer to the question I left before, so I’m writing again.Please understand.
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!
Answer:
NestJS authentication provides different mechanisms like:For your specific use case, with the first mechanism, you can extend your auth guard to check if the user has a specific role.
If you have better answer, please add a comment about this, thank you!