question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

passport module provided options are not working

See original GitHub issue

I’m submitting a…


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Registering Passport module with options doesn’t seem to work

PassportModule.registerAsync({
      useFactory: () => ({
        property: 'account',
      }),
    }),

The property attached to the request is still named user instead or account

Expected behavior

property is account and not user

Minimal reproduction of the problem with instructions

EDIT: https://codesandbox.io/s/passport-not-working-u0his?file=/src/app.controller.ts

git repo: https://github.com/gimyboya/nest-passport-not-working

What is the motivation / use case for changing the behavior?

Configure Passport to attache the result returned by the verify function from the strategy class as an object named account instead of user

Environment


Nest version: 7.4.2
 
For Tooling issues:
- Node version: v12.16.2
- Platform:  Windows

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
gimyboyacommented, Aug 25, 2020

For anyone facing this in the future, here is the solution provided by @jmcdo29 :

1- start by including the optional options in the guard constructor and pass it down to the super constructor as it turns out that the super constructor was not having the options passed down to it.

constructor(
    private readonly jwtService: JwtService,
    private readonly accountService: AccountService,
    private authService: AuthService,
    @Optional() options: AuthModuleOptions,
  ) {
    super(options);
  }

2- Export the PassportModule and make sure to include the AuthModule anywhere you use the guard

1reaction
squareloop1commented, Nov 27, 2020

Seems not to work for global guards. Property setting is not getting passed to the ctor if the guard is defined globally and it ist not picking up the custom property name.

// Edit: It is working, when defining the global guards in AuthModule instead of AppModule

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passport Authentication System Not Working - node.js
I found 2 issues. First: In the app.js file, after you configure the LocalStrategy, you have to call done after you check the...
Read more >
The Ultimate Guide to Passport JS - DEV Community ‍ ‍
In this post, I am going to walk through why the Passport-JWT authentication strategy is a simple, secure solution for small teams and...
Read more >
Passport.js - Documentation
Overview. Passport is authentication middleware for Node.js. It is designed to serve a singular purpose: authenticate requests.
Read more >
Node JS with Passport Authentication simplified - Medium
The main Passport JS library deals with already authenticated users, and does not play any part in actually authenticating the users.
Read more >
Authenticate Users With Node ExpressJS and Passport.js
Solve hard problems faster with Node.js training from Osio Labs. ... Passport strategies are separate modules created to suit individual means of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found