diff --git a/api/src/unraid-api/auth/api-key.service.ts b/api/src/unraid-api/auth/api-key.service.ts index 4a7ad6edb..63eb90d17 100644 --- a/api/src/unraid-api/auth/api-key.service.ts +++ b/api/src/unraid-api/auth/api-key.service.ts @@ -35,11 +35,29 @@ export class ApiKeyService implements OnModuleInit { async onModuleInit() { this.memoryApiKeys = await this.loadAllFromDisk(); + await this.cleanupLegacyInternalKeys(); if (environment.IS_MAIN_PROCESS) { this.setupWatch(); } } + private async cleanupLegacyInternalKeys() { + const legacyNames = ['CliInternal', 'ConnectInternal']; + const keysToDelete = this.memoryApiKeys.filter((key) => legacyNames.includes(key.name)); + + if (keysToDelete.length > 0) { + try { + await this.deleteApiKeys(keysToDelete.map((key) => key.id)); + this.logger.log(`Cleaned up ${keysToDelete.length} legacy internal keys`); + } catch (error) { + this.logger.debug( + error, + `Failed to delete legacy internal keys: ${keysToDelete.map((key) => key.name).join(', ')}` + ); + } + } + } + public async findAll(): Promise { return this.memoryApiKeys; }