You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Middlewares are run sequentially in the order they are bound.
As with middleware, guards run in the order in which they are bound.
This can be understood as the guards for the route are executed from top to bottom, in the order they appear in the source code. However, as I see, guards are executed in the reverse order.
Minimal reproduction of the problem with instructions
Specify this order in the documentation as it is already specified for the @UseGuards(Guard1, Guard2) case.
Change guard execution order so the guards are executed from top to bottom, as they appear in the source code. This option seems to be better from the user's point of view, because it will be easier to read the controller's source code, but it might break some existing code that expects reverse guards order.
Also, I would suggest introducing some kind of style guide for controller decorators' order (method => guards => interceptors => pipes => filters) and maintain this order in the documentation examples. Although, this is a subject for another issue.
What is the motivation / use case for changing the behavior?
I have created a NoAuth decorator that, as opposed to the Auth decorator, prevents authenticated users from accessing /auth/login, /auth/register and other authentication-related pages of MVC application.
This can be understood as the guards for the route are executed from top to bottom, in the order they appear in the source code. However, as I see, guards are executed in the reverse order.
This seems logical at first, but it's something fundamental about how decorators work in Typescript. They resolve in the opposite order that they are bound top-to-bottom, hence why above you get second then first in your logs.
Generally, it's actually a bad idea to use the same decorator multiple times due to overriding metadata, but the way Nest implemented the setting of meteadata means that you are able to call @UseGuards() several times with the metadata still being persisted.
Of your two solutions, documenting the behavior is probably going to be the only one possible, again, because of how decorators work in Typescript.
I'm submitting a...
Current behavior
The documentation states that:
This can be understood as the guards for the route are executed from top to bottom, in the order they appear in the source code. However, as I see, guards are executed in the reverse order.
Minimal reproduction of the problem with instructions
Output:
Expected behavior
There are two ways for resolving this issue:
@UseGuards(Guard1, Guard2)
case.Also, I would suggest introducing some kind of style guide for controller decorators' order (method => guards => interceptors => pipes => filters) and maintain this order in the documentation examples. Although, this is a subject for another issue.
What is the motivation / use case for changing the behavior?
I have created a
NoAuth
decorator that, as opposed to theAuth
decorator, prevents authenticated users from accessing/auth/login
,/auth/register
and other authentication-related pages of MVC application.I want to use it in the AuthController like that:
Now I need to change the order of these decorators to make it work as intended.
Environment
The text was updated successfully, but these errors were encountered: