import { ExecutionContext, Injectable } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { AuthGuard } from '@nestjs/passport';
import { IS_NO_AUTH_TOKEN } from '../../common/decorator/no-token.decorator';

@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {
  constructor(private reflector: Reflector) {
    super();
  }

  canActivate(context: ExecutionContext) {
    const isNoAuthToken = this.reflector.getAllAndOverride<boolean>(
      IS_NO_AUTH_TOKEN,
      [context.getHandler(), context.getClass()],
    );
    if (isNoAuthToken) return true;
    return super.canActivate(context);
  }
}
