hydra-newmedia / passport-headerapikey

Api key authentication strategy for Passport, which only handles headers (not body fields).
28 stars 6 forks source link

ERROR [AuthGuard] undefined #15

Open aauffray opened 1 year ago

aauffray commented 1 year ago

My NestJS server logs an ERROR [AuthGuard] undefined in production, but everything works fine and the API key is checked correctly. I don't see the error locally.

Version : 1.2.2

My middleware :

import { Injectable, UnauthorizedException } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import Strategy from 'passport-headerapikey';

@Injectable()
export class HeaderApiKeyStrategy extends PassportStrategy(
  Strategy,
  'api-key',
) {
  constructor() {
    super({ header: 'X-API-KEY', prefix: '' }, true, async (apiKey, done) => {
      return this.validate(apiKey, done);
    });
  }

  public validate = (apiKey: string, done: (error: Error, data) => {}) => {
   // my API key validation
  };
}

Is there something serious I should check ?

adamgajzlerowicz commented 1 year ago

I have the same error. For me it is nest js + FacebookStrategy. It appears after the callback is called, and before I am back in the controller. I can't find what causes is either. Tried to debug it with stepping over.. still nothing. But the feature works 🤷🏼