parent
aadd9f56a0
commit
1215803a40
@ -21,38 +21,31 @@ export class ApiKeyStrategy extends PassportStrategy(
|
|||||||
private readonly prismaService: PrismaService,
|
private readonly prismaService: PrismaService,
|
||||||
private readonly userService: UserService
|
private readonly userService: UserService
|
||||||
) {
|
) {
|
||||||
super({ header: HEADER_KEY_TOKEN, prefix: 'Api-Key ' }, true);
|
super({ header: HEADER_KEY_TOKEN, prefix: 'Api-Key ' }, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async validate(
|
public async validate(apiKey: string) {
|
||||||
apiKey: string,
|
const user = await this.validateApiKey(apiKey);
|
||||||
done: (error: any, user?: any) => void
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
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(
|
||||||
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
|
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
|
||||||
StatusCodes.TOO_MANY_REQUESTS
|
StatusCodes.TOO_MANY_REQUESTS
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
await this.prismaService.analytics.upsert({
|
|
||||||
create: { User: { connect: { id: user.id } } },
|
|
||||||
update: {
|
|
||||||
activityCount: { increment: 1 },
|
|
||||||
lastRequestAt: new Date()
|
|
||||||
},
|
|
||||||
where: { userId: user.id }
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
done(null, user);
|
await this.prismaService.analytics.upsert({
|
||||||
} catch (error) {
|
create: { User: { connect: { id: user.id } } },
|
||||||
done(error, null);
|
update: {
|
||||||
|
activityCount: { increment: 1 },
|
||||||
|
lastRequestAt: new Date()
|
||||||
|
},
|
||||||
|
where: { userId: user.id }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async validateApiKey(apiKey: string) {
|
private async validateApiKey(apiKey: string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user