diff --git a/backend/src/controllers/auth.controller.ts b/backend/src/controllers/auth.controller.ts index 028aa17..ddc58d8 100644 --- a/backend/src/controllers/auth.controller.ts +++ b/backend/src/controllers/auth.controller.ts @@ -103,7 +103,7 @@ export const refreshToken = async (req: Request, res: Response) => { } }; -export const createApiKey = async (req: Request, res: Response) => { +export const createApiKey = async (_req: Request, res: Response) => { const logger = container.get(LoggerService); logger.verbose('Create API key request received'); @@ -111,26 +111,12 @@ export const createApiKey = async (req: Request, res: Response) => { try { const apiKey = await authService.createApiKey(); - return res.status(201).json({ apiKey }); + return res.status(201).json(apiKey); } catch (error) { handleError(res, error, 'creating API key'); } }; -export const deleteApiKeys = async (req: Request, res: Response) => { - const logger = container.get(LoggerService); - logger.verbose('Delete API keys request received'); - - const authService = container.get(AuthService); - - try { - await authService.deleteApiKeys(); - return res.status(202).send(); - } catch (error) { - handleError(res, error, 'deleting API keys'); - } -}; - export const getApiKeys = async (_req: Request, res: Response) => { const logger = container.get(LoggerService); logger.verbose('Get API keys request received'); @@ -139,8 +125,22 @@ export const getApiKeys = async (_req: Request, res: Response) => { try { const apiKeys = await authService.getApiKeys(); - return res.status(200).json({ apiKeys }); + return res.status(200).json(apiKeys); } catch (error) { handleError(res, error, 'getting API keys'); } }; + +export const deleteApiKeys = async (_req: Request, res: Response) => { + const logger = container.get(LoggerService); + logger.verbose('Delete API keys request received'); + + const authService = container.get(AuthService); + + try { + await authService.deleteApiKeys(); + return res.status(204).send(); + } catch (error) { + handleError(res, error, 'deleting API keys'); + } +}; diff --git a/backend/src/helpers/password.helper.ts b/backend/src/helpers/password.helper.ts index a1b8c9f..8eba937 100644 --- a/backend/src/helpers/password.helper.ts +++ b/backend/src/helpers/password.helper.ts @@ -13,7 +13,7 @@ export class PasswordHelper { } // Generate a secure API key using uid with a length of 32 characters - static generateApiKey(): { key: string; creationDate: string } { - return { key: `ovmeet-${uid(32)}`, creationDate: new Date().toISOString() }; + static generateApiKey(): { key: string; creationDate: number } { + return { key: `ovmeet-${uid(32)}`, creationDate: new Date().getTime() }; } } diff --git a/backend/src/services/storage/storage.service.ts b/backend/src/services/storage/storage.service.ts index d8cceaa..0edb8b3 100644 --- a/backend/src/services/storage/storage.service.ts +++ b/backend/src/services/storage/storage.service.ts @@ -568,18 +568,18 @@ export class MeetStorageService< return await this.saveCacheAndStorage(userRedisKey, storageUserKey, user); } - async saveApiKey(apiKeyData: { key: string; creationDate: string }): Promise { + async saveApiKey(apiKeyData: { key: string; creationDate: number }): Promise { const redisKey = RedisKeyName.API_KEYS; const storageKey = this.keyBuilder.buildApiKeysKey(); this.logger.debug(`Saving API key to Redis and storage: ${redisKey}`); - await this.saveCacheAndStorage(redisKey, storageKey, apiKeyData); + await this.saveCacheAndStorage(redisKey, storageKey, [apiKeyData]); } - async getApiKeys(): Promise<{ key: string; creationDate: string }[]> { + async getApiKeys(): Promise<{ key: string; creationDate: number }[]> { const redisKey = RedisKeyName.API_KEYS; const storageKey = this.keyBuilder.buildApiKeysKey(); this.logger.debug(`Retrieving API key from Redis and storage: ${redisKey}`); - const apiKeys = await this.getFromCacheAndStorage<{ key: string; creationDate: string }[]>( + const apiKeys = await this.getFromCacheAndStorage<{ key: string; creationDate: number }[]>( redisKey, storageKey );