I am using nestjs and having an issue with using guards to authenticate a request.
import { PassportStrategy } from '@nestjs/passport';
import { Injectable, UnauthorizedException, HttpStatus, Logger } from '@nestjs/common';
import { Strategy } from 'passport-localapikey-update';
import { size } from 'lodash';
import { AuthService } from './auth.service';
@Injectable()
export class ApiKeyStrategy extends PassportStrategy(Strategy, 'localapikey') {
constructor(private readonly authService: AuthService) {
super();
}
async validate(token: string) {
Logger.log('HERE!!!!!!!!!!!!!!', 'ApiKeyStrategy'); // Not printed
const data = await this.authService.authenticateClient(token);
if (!size(data)) {
throw new UnauthorizedException('Unauthorized');
}
return data;
}
}
The @UseGuards(AuthGuard('localapikey'))
doesn't execute and throws 401 error.
None of the logs are printed.