diff --git a/.source b/.source index 63031eab79f..bb5dee11b0b 160000 --- a/.source +++ b/.source @@ -1 +1 @@ -Subproject commit 63031eab79f8b5f6321d98d69a99c0fc7c6fe8c9 +Subproject commit bb5dee11b0b7ca83cb35085be1ec06ec22fe5715 diff --git a/apps/api/src/app/environments-v1/usecases/generate-unique-api-key/generate-unique-api-key.usecase.ts b/apps/api/src/app/environments-v1/usecases/generate-unique-api-key/generate-unique-api-key.usecase.ts index d43aa23ab62..18b0ba8f37a 100644 --- a/apps/api/src/app/environments-v1/usecases/generate-unique-api-key/generate-unique-api-key.usecase.ts +++ b/apps/api/src/app/environments-v1/usecases/generate-unique-api-key/generate-unique-api-key.usecase.ts @@ -31,7 +31,6 @@ export class GenerateUniqueApiKey { const hashedApiKey = createHash('sha256').update(apiKey).digest('hex'); const environment = await this.environmentRepository.findByApiKey({ - key: apiKey, hash: hashedApiKey, }); diff --git a/libs/application-generic/src/services/auth/community.auth.service.ts b/libs/application-generic/src/services/auth/community.auth.service.ts index 982ab5c6242..0ff2cbc5694 100644 --- a/libs/application-generic/src/services/auth/community.auth.service.ts +++ b/libs/application-generic/src/services/auth/community.auth.service.ts @@ -350,12 +350,6 @@ export class CommunityAuthService implements IAuthService { ); } - @CachedEntity({ - builder: ({ apiKey }: { apiKey: string }) => - buildAuthServiceKey({ - apiKey, - }), - }) private async getApiKeyUser({ apiKey }: { apiKey: string }): Promise<{ environment?: EnvironmentEntity; user?: UserEntity; @@ -364,7 +358,6 @@ export class CommunityAuthService implements IAuthService { const hashedApiKey = createHash('sha256').update(apiKey).digest('hex'); const environment = await this.environmentRepository.findByApiKey({ - key: apiKey, hash: hashedApiKey, }); @@ -373,16 +366,7 @@ export class CommunityAuthService implements IAuthService { return { error: 'API Key not found' }; } - let key = environment.apiKeys.find((i) => i.hash === hashedApiKey); - - if (!key) { - /* - * backward compatibility - delete after encrypt-api-keys-migration execution - * find by decrypted key if key not found, because of backward compatibility - * use-case: findByApiKey found by decrypted key, so we need to validate by decrypted key - */ - key = environment.apiKeys.find((i) => i.key === apiKey); - } + const key = environment.apiKeys.find((i) => i.hash === hashedApiKey); if (!key) { return { error: 'API Key not found' }; diff --git a/libs/dal/src/repositories/environment/environment.repository.ts b/libs/dal/src/repositories/environment/environment.repository.ts index 6dcc7c49fc1..883e4fff7ac 100644 --- a/libs/dal/src/repositories/environment/environment.repository.ts +++ b/libs/dal/src/repositories/environment/environment.repository.ts @@ -58,9 +58,8 @@ export class EnvironmentRepository extends BaseRepository { diff --git a/libs/dal/src/repositories/environment/environment.schema.ts b/libs/dal/src/repositories/environment/environment.schema.ts index ac4fc1d0081..e9388aafa6b 100644 --- a/libs/dal/src/repositories/environment/environment.schema.ts +++ b/libs/dal/src/repositories/environment/environment.schema.ts @@ -77,6 +77,10 @@ environmentSchema.index({ _organizationId: 1, }); +environmentSchema.index({ + 'apiKeys.hash': 1, +}); + export const Environment = (mongoose.models.Environment as mongoose.Model) || mongoose.model('Environment', environmentSchema);