Browse Source

fix(api): validate user existence in API key strategy

pull/7630/head
KenTandrian 3 days ago
parent
commit
a90a54e3bc
  1. 11
      apps/api/src/app/auth/api-key.strategy.ts

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

@ -66,7 +66,16 @@ export class ApiKeyStrategy extends PassportStrategy(
try { try {
const { id } = await this.apiKeyService.getUserByApiKey(apiKey); const { id } = await this.apiKeyService.getUserByApiKey(apiKey);
return this.userService.user({ id }); const user = await this.userService.user({ id });
if (!user) {
throw new HttpException(
getReasonPhrase(StatusCodes.UNAUTHORIZED),
StatusCodes.UNAUTHORIZED
);
}
return user;
} catch { } catch {
throw new HttpException( throw new HttpException(
getReasonPhrase(StatusCodes.UNAUTHORIZED), getReasonPhrase(StatusCodes.UNAUTHORIZED),

Loading…
Cancel
Save