Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

519 B
Raw Blame
import { Injectable } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { HeaderAPIKeyStrategy } from 'passport-headerapikey'
import { ApiKeyService } from '../../api-key/api-key.service'

@Injectable()
export class ApiKeyStrategy extends PassportStrategy(
  HeaderAPIKeyStrategy,
  'api-key',
) {
  constructor(private readonly keys: ApiKeyService) {
    super({ header: 'X-Api-Key', prefix: '' }, false)
  }

  validate(apiKey: string) {
    return this.keys.authenticate(apiKey)
  }
}