@nestjs/jwt - Cannot read property 'challenge' of undefined
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
I’m getting the following error:
TypeError: Cannot read property 'challenge' of undefined
at allFailed (/Users/fpachecoibz/Documents/git/fpachecoibz-service/node_modules/passport/lib/middleware/authenticate.js:107:52)
at attempt (/Users/fpachecoibz/Documents/git/fpachecoibz-service/node_modules/passport/lib/middleware/authenticate.js:180:28)
at authenticate (/Users/fpachecoibz/Documents/git/fpachecoibz-service/node_modules/passport/lib/middleware/authenticate.js:362:7)
at Promise (/Users/fpachecoibz/Documents/git/fpachecoibz-service/node_modules/@nestjs/passport/dist/auth.guard.js:77:3)
at new Promise (<anonymous>)
at /Users/fpachecoibz/Documents/git/fpachecoibz-service/node_modules/@nestjs/passport/dist/auth.guard.js:69:83
at MixinAuthGuard.<anonymous> (/Users/fpachecoibz/Documents/git/fpachecoibz-service/node_modules/@nestjs/passport/dist/auth.guard.js:44:36)
at Generator.next (<anonymous>)
at /Users/fpachecoibz/Documents/git/fpachecoibz-service/node_modules/@nestjs/passport/dist/auth.guard.js:19:71
at new Promise (<anonymous>)
Expected behavior
Guard should block the request when I try to call the /user/all
route
Minimal reproduction of the problem with instructions
The project repository is this
Environment
Nest version: 5.3.0
For Tooling issues:
- Node version: 10.9.0
- Platform: MacOS
Others:
- @nestjs/jwt: 0.1.3
- @nestjs/passport: 5.0.0
- passport: 0.4.0
- passport-jwt: 4.0.0
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:11 (2 by maintainers)
Top Results From Across the Web
cannot read properties of undefined nestjs
Your MongoService needs to be marked with @Injectable() so that Nest can read the metadata of the constructor and set up the injection...
Read more >Cannot read properties of undefined (reading 'length')
This error can be thrown for a lot of reasons, as it is incredibly common to reference the length property of string or...
Read more >NestJs JWT - Access Tokens & Refresh Tokens - Ultimate Guide
In this video, I will be building a complete authentication module with logout and refresh functionality. I will also show how you can...
Read more >Authentication in a Nest.js Application with Neo4j
The method takes a User object (in this case a Node), pulls a set of properties from the node and uses the JwtService...
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
PassportModule
has to be injected everywhere where you want to take advantage ofdefaultStrategy
option. You should at least re-export module by putting it inside theexports
array. I just published 5.0.1 that includes more descriptive errors to anticipate such issues in the future.The error appears when I protect a route using:
But if we add ‘jwt’ inside AuthGuard(), works:
I only have one strategy, jwt.