passport module provided options are not working
See original GitHub issueI’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:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
2- Export the
PassportModule
and make sure to include theAuthModule
anywhere you use the guardSeems 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