From 197dcc66efc7c36539cce4e754ba3d0c9e4e506b Mon Sep 17 00:00:00 2001 From: IO Date: Wed, 12 Jun 2024 21:26:05 -0600 Subject: [PATCH 1/2] coments --- src/auth/auth.service.ts | 2 +- src/users/dto/create-user.dto.ts | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index e23b824..4af6a98 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -18,7 +18,7 @@ export class AuthService { ) {} async register(data: registerDto){ - const{username, password,} = data; + const{password,} = data; //Seeks the password and if it finds it, it doesn't register if(await this.usersService.findOne(data.username)){ diff --git a/src/users/dto/create-user.dto.ts b/src/users/dto/create-user.dto.ts index 05d95e8..92df44e 100644 --- a/src/users/dto/create-user.dto.ts +++ b/src/users/dto/create-user.dto.ts @@ -2,10 +2,11 @@ import { IsEmail, IsNotEmpty, IsString, MinLength } from "class-validator"; export class CreateUserDto{ @IsString() - readonly name: string; - @IsNotEmpty() - @MinLength(10) - readonly password: string; + name: string; + + @IsString() + @IsNotEmpty() + password: string; } \ No newline at end of file From da6e9a4f76b23e2428532fe5cf0a6f5344347d05 Mon Sep 17 00:00:00 2001 From: IO Date: Thu, 13 Jun 2024 15:12:24 -0600 Subject: [PATCH 2/2] cors --- src/auth/auth.service.ts | 12 +++++++----- src/main.ts | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 5c227bf..fdd3bbb 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -20,9 +20,9 @@ export class AuthService { ) {} async register(data: registerDto){ - const{password,} = data; + const{username,password,} = data; - if(await this.usersService.findOne(data.username)){ + if(await this.usersService.findOne(username)){ throw new HttpException("User already exist",403); } @@ -36,11 +36,13 @@ export class AuthService { async signIn(data: registerDto) { - const{password} = data; - const user = await this.usersService.findOne(data.username); + const{username,password} = data; + const user = await this.usersService.findOne(username); + if (!user) { + throw new UnauthorizedException('Invalid credentials'); + } const checkPassword = await compare(password, (await user).password) - if (!checkPassword) { throw new UnauthorizedException(); } diff --git a/src/main.ts b/src/main.ts index 13cad38..260ded0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,6 +3,7 @@ import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); + app.enableCors();//activa cors await app.listen(3000); } bootstrap();