I'm working on implementing a simple authentication in a Nest project.
When I add
@UseGuards(AuthGuard('local'))
to my controller I have the following Error :
ERROR [ExceptionHandler] Cannot read property '__guards__' of undefined
at /home/cedric/Bureau/programmation/project_bank/project/node_modules/@nestjs/core/scanner.js:147:152
I followed all the Nest official documentation to do this.
My controller is
@UseGuards(AuthGuard('local'))
@Post('login')
async login(@Request() req) {
console.log(req.body.username);
return req.body.username;
}
and my auth.guard.ts
@Injectable()
export class LocalAuthGuard extends AuthGuard('local') {}
I'd say this is a dependency version mismatch issue.
You need to ensure that @nestjs/platform-express
, @nestjs/core
and @nestjs/common
are in the same version (I believe that only the minor slice matters).