Files
immich/server/apps/immich/src/modules/immich-auth/strategies/api-key.strategy.ts
Jason Rasmussen 414893a687 fix(server): auth strategies (#1459)
* fix(server): auth strategies

* chore: tests
2023-01-27 23:12:11 -06:00

22 lines
626 B
TypeScript

import { APIKeyService, AuthUserDto } from '@app/domain';
import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { IStrategyOptions, Strategy } from 'passport-http-header-strategy';
export const API_KEY_STRATEGY = 'api-key';
const options: IStrategyOptions = {
header: 'x-api-key',
};
@Injectable()
export class APIKeyStrategy extends PassportStrategy(Strategy, API_KEY_STRATEGY) {
constructor(private apiKeyService: APIKeyService) {
super(options);
}
validate(token: string): Promise<AuthUserDto | null> {
return this.apiKeyService.validate(token);
}
}