import { Controller, Post, Body, Get, Query, UnauthorizedException, } from '@nestjs/common'; import { AuthService } from './auth.service'; @Controller('auth') export class AuthController { constructor(private readonly authService: AuthService) { } // ===================== LOGIN ===================== @Post('login') async login( @Body('usuario') usuario: string, @Body('password') password: string, ) { try { const token = await this.authService.login(usuario, password); return token; // { access_token: '...' } } catch (error) { throw new UnauthorizedException(error.message); } } // ===================== VERIFICAR TOKEN ===================== @Get('verify') async verify(@Query('token') token: string) { try { const payload = await this.authService.jwtVerificar(token); return { valid: true, payload }; } catch (error) { throw new UnauthorizedException(error.message); } } // ===================== ACTUALIZAR CONTRASEÑA ADMIN ===================== @Post('update-password') async updatePassword() { try { const newPassword = await this.authService.update_password(); return { message: 'Contraseña actualizada correctamente.', contraseña: newPassword }; } catch (error) { throw new UnauthorizedException(error.message); } } }