Merge branch 'Lino' of https://repositorio.acatlan.unam.mx/mcervantesag/api_directorio into Lino
This commit is contained in:
@@ -20,9 +20,9 @@ export class AuthService {
|
||||
) {}
|
||||
|
||||
async register(data: registerDto){
|
||||
const{username, 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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -2,8 +2,10 @@ import { IsEmail, IsNotEmpty, IsString, MinLength } from "class-validator";
|
||||
|
||||
export class UserDto{
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
name: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
password: string;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user