Errores arreglados
This commit is contained in:
@@ -7,11 +7,14 @@ import { LoginDto } from './dto/login.dto';
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
constructor( private readonly authService:AuthService){}
|
||||
|
||||
@Post("registro")
|
||||
registro(@Body() registroDto:CreateUsuarioDto ){
|
||||
return this.authService.registro(registroDto);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Post("login")
|
||||
login(@Body() loginDto:LoginDto){
|
||||
return this.authService.login(loginDto);
|
||||
|
||||
@@ -2,13 +2,13 @@ import { Module } from '@nestjs/common';
|
||||
import { AuthController } from './auth.controller';
|
||||
import { AuthService } from './auth.service';
|
||||
import { UsuariosModule } from 'src/usuarios/usuarios.module';
|
||||
import { JwtModule, JwtService } from '@nestjs/jwt';
|
||||
import { UsuariosService } from 'src/usuarios/usuarios.service';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
|
||||
|
||||
|
||||
@Module({
|
||||
imports:[UsuariosModule,
|
||||
imports:[
|
||||
UsuariosModule,
|
||||
JwtModule,
|
||||
JwtModule.register({
|
||||
global:true,
|
||||
@@ -18,6 +18,7 @@ import { UsuariosService } from 'src/usuarios/usuarios.service';
|
||||
}),
|
||||
],
|
||||
controllers: [AuthController],
|
||||
providers: [AuthService,UsuariosService, JwtService]
|
||||
providers: [AuthService],
|
||||
exports:[AuthService]
|
||||
})
|
||||
export class AuthModule {}
|
||||
|
||||
+24
-13
@@ -1,9 +1,12 @@
|
||||
import { BadRequestException, Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable, UnauthorizedException, InternalServerErrorException } from '@nestjs/common';
|
||||
import { UsuariosService } from 'src/usuarios/usuarios.service';
|
||||
import * as argon2 from 'argon2';
|
||||
import { LoginDto } from './dto/login.dto';
|
||||
import { CreateUsuarioDto } from 'src/usuarios/dto/create-usuario.dto';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Usuario } from 'src/usuarios/entities/usuario.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
@@ -11,22 +14,30 @@ export class AuthService {
|
||||
private readonly usuarioService:UsuariosService,
|
||||
private readonly jwtService:JwtService
|
||||
){}
|
||||
//Pendiente
|
||||
//Pendiente tipoUsuario
|
||||
async registro({nombre, contraseña,tipoUsuario}: CreateUsuarioDto){
|
||||
const usuario= await this.usuarioService.findOneByName(nombre)
|
||||
|
||||
const usuario = await this.usuarioService.findOneByName(nombre);
|
||||
if(usuario){
|
||||
throw new BadRequestException("Nombre de usuario ya existente");
|
||||
}
|
||||
const hashedContraseña= await argon2.hash(contraseña) ;
|
||||
|
||||
await this.usuarioService.create({
|
||||
nombre,
|
||||
contraseña:hashedContraseña,
|
||||
tipoUsuario,
|
||||
});
|
||||
|
||||
return{
|
||||
message:"Usuario registrado exitosamente " };
|
||||
|
||||
try{
|
||||
const hashedContraseña = await argon2.hash(contraseña);
|
||||
|
||||
await this.usuarioService.create({
|
||||
nombre,
|
||||
contraseña: hashedContraseña,
|
||||
tipoUsuario,
|
||||
});
|
||||
|
||||
return {
|
||||
message: "Usuario registrado exitosamente"
|
||||
};
|
||||
}catch(error){
|
||||
|
||||
throw new InternalServerErrorException('Error al crear el usuario');
|
||||
}
|
||||
}
|
||||
|
||||
async login({nombre, contraseña}:LoginDto){
|
||||
|
||||
Reference in New Issue
Block a user