#UseGuards annotation always return unauthorized

7 messages · Page 1 of 1 (latest)

hardy lance
#

hello i have a problem with authgaurds.

My problem is what every i do i always recive a 401 stauts code and the canActivate method in the guard not even getting called:

Controller:

export class LeadController {
  private readonly logger = new Logger(LeadController.name);
  constructor() {}

  @Post()
  @UseGuards(ApikeyGuard)
  create(@Body() createLeadDto: CreateLeadDto, @Req() request: Request) {
    return 'valid';
  }
}

Guard:

@Injectable()
export class ApiKeyGuard implements CanActivate {
  private readonly logger = new Logger(ApikeyGuard.name);
  constructor() {} // private readonly zohoAuthService: ZohoAuthService, // private zohoService: ZohoRestService,

  async canActivate(context: ExecutionContext): Promise<boolean> {
    this.logger.log('called');
    return true;
  }
}

did i have missed something ?

dim pewter
#

You always get a 404? Or a 403?

hardy lance
#

401

#

my bad

dim pewter
#

401, that's usually an error from a passport AuthGuard(), do you have any of those set globally?

hardy lance
#

🤯

#

thx