Browse Source

Clean up

pull/4682/head
Thomas Kaul 4 months ago
parent
commit
5fd20ea623
  1. 40
      apps/api/src/app/auth/api-key.strategy.ts

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

@ -24,32 +24,28 @@ export class ApiKeyStrategy extends PassportStrategy(
super({ header: HEADER_KEY_TOKEN, prefix: 'Api-Key ' }, false); super({ header: HEADER_KEY_TOKEN, prefix: 'Api-Key ' }, false);
} }
public async validate(apiKey: string): Promise<any> { public async validate(apiKey: string) {
try { const user = await this.validateApiKey(apiKey);
const user = await this.validateApiKey(apiKey);
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) {
if (hasRole(user, 'INACTIVE')) {
throw new HttpException(
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
StatusCodes.TOO_MANY_REQUESTS
);
}
await this.prismaService.analytics.upsert({ if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) {
create: { User: { connect: { id: user.id } } }, if (hasRole(user, 'INACTIVE')) {
update: { throw new HttpException(
activityCount: { increment: 1 }, getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
lastRequestAt: new Date() StatusCodes.TOO_MANY_REQUESTS
}, );
where: { userId: user.id }
});
} }
return user; await this.prismaService.analytics.upsert({
} catch (error) { create: { User: { connect: { id: user.id } } },
throw error; update: {
activityCount: { increment: 1 },
lastRequestAt: new Date()
},
where: { userId: user.id }
});
} }
return user;
} }
private async validateApiKey(apiKey: string) { private async validateApiKey(apiKey: string) {

Loading…
Cancel
Save