Se corrigió envio de correos y creacion de controller servicio
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user