This commit is contained in:
Ilham Dwi Pratama S 2021-12-06 05:07:07 +07:00
parent 2b5abc7689
commit 74711e0823
3 changed files with 26 additions and 26 deletions

View File

@ -8,7 +8,7 @@ import { LoggerModule } from 'nestjs-pino';
import { TransactionModule } from './transaction/transaction.module'; import { TransactionModule } from './transaction/transaction.module';
import { ProductModule } from './product/product.module'; import { ProductModule } from './product/product.module';
import { ConfigurableModule } from './configurable/configurable.module'; import { ConfigurableModule } from './configurable/configurable.module';
import { AuthModule } from './auth/auth.module'; // import { AuthModule } from './auth/auth.module';
import configuration from './config/configuration'; import configuration from './config/configuration';
@Module({ @Module({
@ -48,11 +48,11 @@ import configuration from './config/configuration';
}, },
inject: [ConfigService], inject: [ConfigService],
}), }),
UsersModule, // UsersModule,
TransactionModule, TransactionModule,
ConfigurableModule, ConfigurableModule,
AuthModule, // AuthModule,
// ProductModule, ProductModule,
], ],
}) })
export class AppModule {} export class AppModule {}

View File

@ -1,22 +1,22 @@
import { PassportStrategy } from '@nestjs/passport'; // import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt'; // import { ExtractJwt, Strategy } from 'passport-jwt';
import { Injectable } from '@nestjs/common'; // import { Injectable } from '@nestjs/common';
import { AuthService } from '../auth/auth.service'; // import { AuthService } from '../auth/auth.service';
@Injectable() // @Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) { // export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(private readonly authService: AuthService) { // constructor(private readonly authService: AuthService) {
super({ // super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), // jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: process.env.SECRETKEY, // secretOrKey: process.env.SECRETKEY,
}); // });
} // }
async validate(payload: JwtPayload): Promise<UserDto> { // async validate(payload: JwtPayload): Promise<UserDto> {
const user = await this.authService.validateUser(payload); // const user = await this.authService.validateUser(payload);
if (!user) { // if (!user) {
throw new HttpException('Invalid token', HttpStatus.UNAUTHORIZED); // throw new HttpException('Invalid token', HttpStatus.UNAUTHORIZED);
} // }
return user; // return user;
} // }
} // }

View File

@ -2,8 +2,8 @@ import { IsNotEmpty } from 'class-validator';
export class CreateUserDto { export class CreateUserDto {
@IsNotEmpty() @IsNotEmpty()
firstName: string; username: string;
@IsNotEmpty() @IsNotEmpty()
lastName: string; password: string;
} }