Browse Source

fix the change of PassportStrategy from @nestjs/passport

pull/4270/merge^2
HarukaKishida 3 months ago
parent
commit
48659063a2
  1. 16
      apps/api/src/app/auth/api-key.strategy.ts

16
apps/api/src/app/auth/api-key.strategy.ts

@ -21,13 +21,15 @@ export class ApiKeyStrategy extends PassportStrategy(
private readonly prismaService: PrismaService, private readonly prismaService: PrismaService,
private readonly userService: UserService private readonly userService: UserService
) { ) {
super( super({ header: HEADER_KEY_TOKEN, prefix: 'Api-Key ' }, true);
{ header: HEADER_KEY_TOKEN, prefix: 'Api-Key ' }, }
true,
async (apiKey: string, done: (error: any, user?: any) => void) => { public validate = async (
apiKey: string,
done: (error: any, user?: any) => void
) => {
try { try {
const user = await this.validateApiKey(apiKey); const user = await this.validateApiKey(apiKey);
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) { if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) {
if (hasRole(user, 'INACTIVE')) { if (hasRole(user, 'INACTIVE')) {
throw new HttpException( throw new HttpException(
@ -50,9 +52,7 @@ export class ApiKeyStrategy extends PassportStrategy(
} catch (error) { } catch (error) {
done(error, null); done(error, null);
} }
} };
);
}
private async validateApiKey(apiKey: string) { private async validateApiKey(apiKey: string) {
if (!apiKey) { if (!apiKey) {

Loading…
Cancel
Save