diff --git a/src/app.module.ts b/src/app.module.ts index ce2cf6a..463420d 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -8,7 +8,6 @@ import { LoggerModule } from 'nestjs-pino'; import { TransactionModule } from './transaction/transaction.module'; import { ProductModule } from './product/product.module'; import { ConfigurableModule } from './configurable/configurable.module'; -// import { AuthModule } from './auth/auth.module'; import { AuthModule } from './auth/auth.module'; import configuration from './config/configuration'; @@ -53,6 +52,7 @@ import configuration from './config/configuration'; TransactionModule, ConfigurableModule, ProductModule, + AuthModule, ], }) export class AppModule {} diff --git a/src/auth/auth.module.ts b/src/auth/auth.module.ts index 75cbc4f..8d2d164 100644 --- a/src/auth/auth.module.ts +++ b/src/auth/auth.module.ts @@ -2,20 +2,12 @@ import { Module } from '@nestjs/common'; import { AuthService } from './auth.service'; import { UsersModule } from '../users/users.module'; import { PassportModule } from '@nestjs/passport'; -import { JwtModule, JwtStrategy } from 'passport-jwt'; +import { LocalStrategy } from './local.strategy'; import { AuthController } from './auth.controller'; @Module({ - imports: [ - UsersModule, - PassportModule.register({ - defaultStrategy: 'jwt', - property: 'user', - session: false, - }), - ], + imports: [UsersModule, PassportModule], + providers: [AuthService, LocalStrategy], controllers: [AuthController], - providers: [AuthService, JwtStrategy], - exports: [PassportModule, JwtModule], }) export class AuthModule {} diff --git a/src/auth/dto/input-login.dto.ts b/src/auth/dto/input-login.dto.ts deleted file mode 100644 index 813ba07..0000000 --- a/src/auth/dto/input-login.dto.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IsNotEmpty } from 'class-validator'; - -export class InputLoginDto { - @IsNotEmpty() - username: string; - - @IsNotEmpty() - password: string; -} diff --git a/src/auth/dto/response-login.dto.ts b/src/auth/dto/response-login.dto.ts deleted file mode 100644 index 3132636..0000000 --- a/src/auth/dto/response-login.dto.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IsNotEmpty } from 'class-validator'; - -export class ResponseLoginDto { - @IsNotEmpty() - username: string; - - @IsNotEmpty() - jwt: string; -} diff --git a/src/auth/local.strategy.ts b/src/auth/local.strategy.ts index 83541f4..b43a0aa 100644 --- a/src/auth/local.strategy.ts +++ b/src/auth/local.strategy.ts @@ -2,7 +2,6 @@ import { Strategy } from 'passport-local'; import { PassportStrategy } from '@nestjs/passport'; import { Injectable, UnauthorizedException } from '@nestjs/common'; import { AuthService } from './auth.service'; -import { User } from '../users/entities/user.entity'; @Injectable() export class LocalStrategy extends PassportStrategy(Strategy) { @@ -10,19 +9,13 @@ export class LocalStrategy extends PassportStrategy(Strategy) { super(); } - // async validate( - // username: string, - // password: string, - // ): Promise> { - // const user = await this.authService.validateUser({ - // username, - // password, - // }); - // - // if (!user) { - // throw new UnauthorizedException(); - // } - // - // return user; - // } + async validate(username: string, password: string): Promise { + const user = await this.authService.validateUser(username, password); + + if (!user) { + throw new UnauthorizedException(); + } + + return user; + } } diff --git a/src/users/dto/create-user.dto.ts b/src/users/dto/create-user.dto.ts index 2147aed..0f42d58 100644 --- a/src/users/dto/create-user.dto.ts +++ b/src/users/dto/create-user.dto.ts @@ -1,4 +1,4 @@ -import { IsNotEmpty, IsUUID } from 'class-validator'; +import { IsNotEmpty, IsOptional, IsUUID, ValidateIf } from 'class-validator'; export class CreateUserDto { @IsNotEmpty() @@ -10,6 +10,9 @@ export class CreateUserDto { @IsUUID() roleId: string; + @ValidateIf((o) => { + return !!o.superior; + }) @IsUUID() superior: string; } diff --git a/yarn.lock b/yarn.lock index 5581f74..4400fb7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1504,7 +1504,7 @@ avvio@^7.1.2: fastq "^1.6.1" queue-microtask "^1.1.2" -axios@0.24.0: +axios@0.24.0, axios@^0.24.0: version "0.24.0" resolved "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz" integrity sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==