Files
Iris_back/src/auth/auth.controller.ts
T
2026-02-26 14:22:33 -06:00

51 lines
1.3 KiB
TypeScript

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);
}
}
}