How can I solve "Strategy#authenticate must be overridden by subclass" error in Nestjs

2.1k Views Asked by At

I'm getting this error when I make a POST request to auth/login

[Nest] 8344   - 10/07/2020, 17:59:32   [ExceptionsHandler] Strategy#authenticate must be overridden by subclass +811577ms

Error: Strategy#authenticate must be overridden by subclass at LocalStrategy.Strategy.authenticate (/home/damy/Projects/snippets/Typescript/simple-crud-with-nest/node_modules/passport-strategy/lib/strategy.js:21:9) at attempt (/home/damy/Projects/snippets/Typescript/simple-crud-with-nest/node_modules/passport/lib/middleware/authenticate.js:366:16) at authenticate (/home/damy/Projects/snippets/Typescript/simple-crud-with-nest/node_modules/passport/lib/middleware/authenticate.js:367:7) at /home/damy/Projects/snippets/Typescript/simple-crud-with-nest/node_modules/@nestjs/passport/dist/auth.guard.js:87:3 at new Promise () at /home/damy/Projects/snippets/Typescript/simple-crud-with-nest/node_modules/@nestjs/passport/dist/auth.guard.js:79:83 at MixinAuthGuard. (/home/damy/Projects/snippets/Typescript/simple-crud-with-nest/node_modules/@nestjs/passport/dist/auth.guard.js:48:36) at Generator.next () at /home/damy/Projects/snippets/Typescript/simple-crud-with-nest/node_modules/@nestjs/passport/dist/auth.guard.js:20:71 at new Promise ()

This is my local strategy code nestjs local strategy code

1

There are 1 best solutions below

4
On

You need to install and use passport-local. passport is an abstract implementation, and the Strategy from it is an abstract class meaning it can't be ran directly. If you use passport-local instead, the implementation is already there.