nestjs/passport

Guard Order Scope affects order of execution

Kagu-chan opened this issue · 2 comments

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When using Passport and having other guard depending on it, passport may not be activatable globally.
I implemented an AutorizationGuard (CASL) which depends on the user provided by the Authentication Module.

If we use the Guard via UseGuard, it works as expected
If we use the Guard via { provide: APP_GUARD }, the Guard gets executed before the Passport Middleware, giving us no user entity to validate anything against

Minimum reproduction code

https://github.com/Kagu-chan/passport-test

Steps to reproduce

No response

Expected behavior

Provide the current user record no matter how we guard the application.

Package version

8.0.1

Passport version

0.4.1

NestJS version

8.0.11

Node.js version

16.13.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

I tried installing the sample code - with passport 0.5.*, the dependecy tree seems to be broken

I'm curious: as passport is what sets req.user, how do you propose we set it when a guard runs before the AuthGuard (i.e. before passport)? It is currently documented the order that guards run in

Guess i forgot this bit and tested it out with registering the Auth Guard globally as well. This way it works now, thanks for the hint.