feat: basic login
This commit is contained in:
parent
10984f65a5
commit
141f3e0e5c
|
@ -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 {}
|
||||
|
|
|
@ -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 {}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
import { IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class InputLoginDto {
|
||||
@IsNotEmpty()
|
||||
username: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
password: string;
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
import { IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class ResponseLoginDto {
|
||||
@IsNotEmpty()
|
||||
username: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
jwt: string;
|
||||
}
|
|
@ -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<Omit<User, 'password'>> {
|
||||
// const user = await this.authService.validateUser({
|
||||
// username,
|
||||
// password,
|
||||
// });
|
||||
//
|
||||
// if (!user) {
|
||||
// throw new UnauthorizedException();
|
||||
// }
|
||||
//
|
||||
// return user;
|
||||
// }
|
||||
async validate(username: string, password: string): Promise<any> {
|
||||
const user = await this.authService.validateUser(username, password);
|
||||
|
||||
if (!user) {
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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==
|
||||
|
|
Loading…
Reference in New Issue
Block a user