Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: non HTTP requests are undefined in built-in AuthGuard #121

Merged
merged 1 commit into from
Mar 10, 2022

Conversation

replio-it
Copy link

Hi all, nice to meet you and these project.

the AuthGuard also comes into operation when requests that are not HTTP arrive such as amqp (rabbit MQ).
In fact, there are modules such as @golevelup/nestjs-rabbitmq that provide a decorator that works in a similar way to the http core decorator provided by nest, and therefore subject to middleware.
The module's built-in AuthGuard does not detect the undefined returned by the extractRequest function, causing an exception just after reading request.cookies.

the workaround I found immediately is to use the decorator @Unprotected() thus entering the condition isUnprotected

The real solution instead could be to insert a simple condition whereby if request is undefined, the guard returns true (because it is out of its competence).

I am therefore sending you a pr with the solution I have undertaken, hoping that from your point of view it can be really decisive

regards

@ferrerojosh
Copy link
Owner

Only a linting problem, should be no issue to merge.

@ferrerojosh ferrerojosh merged commit 4f6152a into ferrerojosh:master Mar 10, 2022
@replio-it
Copy link
Author

nice!

@inpercima
Copy link

Hi at all,

good to see someone else has same problems. We are using mqtt and also get the error around "request.cookies". The solutions helps us for the AuthGuard but we are getting similar problem in the RoleGuard. Should we insert the same condition in the RoleGuard? Will this be a correct solution?

@ferrerojosh
Copy link
Owner

Hi at all,

good to see someone else has same problems. We are using mqtt and also get the error around "request.cookies". The solutions helps us for the AuthGuard but we are getting similar problem in the RoleGuard. Should we insert the same condition in the RoleGuard? Will this be a correct solution?

I think RoleGuard shouldn't process anything at all without being handled by AuthGuard before, I'll do this change myself along with the check for request.cookies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants