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