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

feat(@nestjs/passport): segregate authenticate opts from module opts #1610

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rodrigo-speller
Copy link

@rodrigo-speller rodrigo-speller commented Mar 20, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #947

  • AuthGuard's constructor receives, by injection, the AuthModuleOptions object, that's responsible to configure the module of this library;
  • AuthGuard.getAuthenticateOptions returns an object that matches the interface IAuthModuleOptions;
  • AuthGuard.canActivate obtain the options from getAuthenticateOptions and merges it with the injected options of the AuthGuard instance;
  • AuthGuard.canActivate pass the merged options to passport.authenticate.

What is the new behavior?

  • AuthGuard's constructor receives, by injection, the AuthModuleOptions object, that's responsible to configure the module of this library within authenticateOptions property to generate the options parameter to call passport.authenticate function.
  • AuthGuard.getAuthenticateOptions returns an object that matches the passport.AuthenticateOptions interface;
  • AuthGuard.canActivate obtain the options from getAuthenticateOptions and merges it with the authenticateOptions from the injected options of the AuthGuard instance;
  • AuthGuard.canActivate pass the merged options to passport.authenticate.

Does this PR introduce a breaking change?

  • Yes
  • No

If the user defines some authenticate option when registering the authentication module by the module options, it must be defined inside authenticateOptions property.

// before:
PassportModule.register({
  defaultStrategy: 'local',
  session: true,
  failureRedirect: '/access-denied',
  successRedirect: '/home'
})

// after:
PassportModule.register({
  defaultStrategy: 'local',
  session: true,
  authenticateOptions: {
    failureRedirect: '/access-denied',
    successRedirect: '/home'
  }
})

Other information

No more information.

@kamilmysliwiec
Copy link
Member

This introduces a major breaking change. Could we, instead of adding another nested configuration object, just strip AuthModule-specific props?

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.

3 participants