Spaces:
Sleeping
Sleeping
Download src/modules/auth/auth-validate.controller.ts from jinksQspider/openWa: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/jinksQspider/openWa/resolve/main/src/modules/auth/auth-validate.controller.ts
- Command line
-
hf download hf://spaces/jinksQspider/openWa/src/modules/auth/auth-validate.controller.ts
-
curl -L -o auth-validate.controller.ts https://huggingface.co/spaces/jinksQspider/openWa/resolve/main/src/modules/auth/auth-validate.controller.ts
1.36 kB
| import { Controller, Post, Headers, HttpCode, HttpStatus } from '@nestjs/common'; | |
| import { ApiTags, ApiOperation, ApiResponse, ApiHeader } from '@nestjs/swagger'; | |
| import { AuthService } from './auth.service'; | |
| import { createLogger } from '../../common/services/logger.service'; | |
| ('auth') | |
| ('auth') | |
| export class AuthValidateController { | |
| private readonly logger = createLogger('AuthValidateController'); | |
| constructor(private readonly authService: AuthService) {} | |
| ('validate') | |
| (HttpStatus.OK) | |
| ({ summary: 'Validate an API key' }) | |
| ({ name: 'X-API-Key', description: 'API key to validate' }) | |
| ({ status: 200, description: 'API key is valid' }) | |
| ({ status: 401, description: 'Invalid or missing API key' }) | |
| async validate(('x-api-key') apiKey?: string): Promise<{ valid: boolean; role?: string }> { | |
| if (!apiKey) { | |
| return { valid: false }; | |
| } | |
| try { | |
| const keyEntity = await this.authService.validateApiKey(apiKey); | |
| if (keyEntity && keyEntity.isActive) { | |
| return { valid: true, role: keyEntity.role }; | |
| } | |
| return { valid: false }; | |
| } catch (error) { | |
| this.logger.warn('API key validation error', { error: error instanceof Error ? error.message : String(error) }); | |
| return { valid: false }; | |
| } | |
| } | |
| } | |