mirror of
https://github.com/immich-app/immich.git
synced 2025-12-23 17:25:11 +03:00
22 lines
626 B
TypeScript
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);
|
|
}
|
|
}
|