@nestjs/jwt - Cannot read property 'challenge' of undefined

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

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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
kamilmysliwieccommented, Sep 2, 2018

PassportModule has to be injected everywhere where you want to take advantage of defaultStrategy option. You should at least re-export module by putting it inside the exports array. I just published 5.0.1 that includes more descriptive errors to anticipate such issues in the future.

3reactions
fpachecoibzcommented, Sep 2, 2018

The error appears when I protect a route using:

@UseGuards(AuthGuard())

But if we add ‘jwt’ inside AuthGuard(), works:

@UseGuards(AuthGuard('jwt'))

I only have one strategy, jwt.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nestjs/jwt - Cannot read property 'challenge' of undefined
I use jwt tokens in my ...
Read more >
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 >

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