-
Notifications
You must be signed in to change notification settings - Fork 118
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
Custom errors in secretOrKeyProvider #394
Comments
Would you like to create a PR for this issue? |
Ah actually, I believe that you should be able to accomplish this by overriding the |
Awesome! This works as expected and resolves this issue. Thank you. |
The updated link for this example is here: https://docs.nestjs.com/recipes/passport#extending-guards |
I'm submitting a...
Current behavior
I'm using
@nestjs/passport
together withpassport-jwt
.In my situation, I'm using the
secretOrKeyProvider
option instead of thesecretOrKey
since the key needs to be fetched async. When something goes wrong in this function (and I end the call with providing an error to the callbackdone(err, undefined)
, then the library correctly returns anUnauthorizedException
.The feature request now is:
Whatever error is returned in the
done
callback, the nest passport package ALWAYS returns a standardUnauthorizedException
without extra information. Even when supplying more concrete info (for exampledone(new ForbiddenException('test'))
, this information gets lost and nest returns a standardUnauthorizedException
It would be really helpfull to be able to capture this more concrete info in this
secretOrKeyProvider
callback function.Below is a code example:
Expected behavior
Nest correctly returns the ForbiddenException as a result.
Minimal reproduction of the problem with instructions
The code example can be used directly as a Guard for testing any route.
What is the motivation / use case for changing the behavior?
Return more specific info to the user why the Authorization has failed. (instead of a simple
UnauthorizedError
)Environment
The text was updated successfully, but these errors were encountered: