nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.44k stars 7.6k forks source link

19-auth-jwt can't accept example request #9168

Closed Derrreks closed 2 years ago

Derrreks commented 2 years ago

Is there an existing issue for this?

Current behavior

The sample code specified for add Passport authentication errors out when using the example specified in the docs with the following error:

[Nest] 34573  - 02/13/2022, 2:13:07 PM   ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'validateUser')
TypeError: Cannot read properties of undefined (reading 'validateUser')
    at LocalStrategy.<anonymous> (/Users/derek/Documents/code/oncall/server/src/auth/strategies/local.strategy.ts:13:41)
    at Generator.next (<anonymous>)
    at /Users/derek/Documents/code/oncall/server/dist/auth/strategies/local.strategy.js:14:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/derek/Documents/code/oncall/server/dist/auth/strategies/local.strategy.js:10:12)
    at LocalStrategy.validate (/Users/derek/Documents/code/oncall/server/dist/auth/strategies/local.strategy.js:28:16)
    at LocalStrategy.<anonymous> (/Users/derek/Documents/code/oncall/server/node_modules/@nestjs/passport/dist/passport/passport.strategy.js:20:55)
    at Generator.next (<anonymous>)
    at /Users/derek/Documents/code/oncall/server/node_modules/@nestjs/passport/dist/passport/passport.strategy.js:8:71
    at new Promise (<anonymous>)

I have tested this both by following the docs to create from scratch and by copying the full example code directly.

Minimum reproduction code

N/A

Steps to reproduce

  1. Download sample project 19
  2. npm install
  3. npm run start
  4. In a new terminal, curl -X POST http://localhost:3000/auth/login -d '{"username": "john", "password": "changeme"}' -H "Content-Type: application/json" (The example given: https://docs.nestjs.com/security/authentication)
  5. Note error in server logs.

Expected behavior

It should return a token!

Package

Other package

No response

NestJS version

No response

Packages versions

N/A

Node.js version

No response

In which operating systems have you tested?

Other

No response

jmcdo29 commented 2 years ago

Just cloned the repo, navigated to sample/19-auth-jwt, and npm i and npm run start:dev, and made a curl to /auth/login with -d 'username=john&password=changeme'. Got an access token back no problem. The example runs fine.

Please provide a minimum reproduction repository.

micalevisk commented 2 years ago

me too.

(Linux)