From 238ce0289c196008a53c7ef03628534dab3505df Mon Sep 17 00:00:00 2001 From: Andrii Arsenin Date: Tue, 7 Apr 2026 12:40:03 +0300 Subject: [PATCH] feat(auth): add GET /keys to list available key identifiers --- src/auth/auth.controller.ts | 9 ++++++++- src/auth/auth.service.ts | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 48cdbe9..c0f74bd 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Post } from '@nestjs/common'; +import { Body, Controller, Get, Post } from '@nestjs/common'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { AuthService } from './auth.service'; import { LoginDto } from './dto/login.dto'; @@ -8,6 +8,13 @@ import { LoginDto } from './dto/login.dto'; export class AuthController { constructor(private readonly authService: AuthService) {} + @Get('keys') + @ApiOperation({ summary: 'List available key identifiers from the keys directory' }) + @ApiResponse({ status: 200, description: 'List of key names', schema: { properties: { keys: { type: 'array', items: { type: 'string' } } } } }) + listKeys(): { keys: string[] } { + return { keys: this.authService.listKeys() }; + } + @Post('login') @ApiOperation({ summary: 'Log in using a file key and return the session token' }) @ApiResponse({ status: 201, description: 'Login successful', schema: { properties: { token: { type: 'string' }, sessionName: { type: 'string' } } } }) diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 269f92a..d564e80 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -40,6 +40,13 @@ export class AuthService { ); } + listKeys(): string[] { + if (!fs.existsSync(this.keysDir)) return []; + return fs.readdirSync(this.keysDir) + .filter(f => f.endsWith('.json')) + .map(f => path.basename(f, '.json')); + } + async login(keyId: string, sessionName?: string): Promise<{ token: string; sessionName: string }> { const resolvedSession = sessionName ?? crypto.randomUUID();