import { Injectable } from '@nestjs/common' ; import { UserService } from '../user/user.service' ; import * as bcrypt from 'bcrypt' ; import { JwtService } from '@nestjs/jwt' ; @ Injectable ( ) export class AuthService { constructor ( private usersService , private jwtService ) { } async validateUser ( username , password ) { const user = await this . usersService . findByUsername ( username ) ; if ( user && await bcrypt . compare ( password , user . password ) ) { const { ... result } = user ; return result ; } return null ; } async login ( user ) { const payload = { username : user . username , sub : user . userId } ; return { 'access_token' : this . jwtService . sign ( payload ) , } ; } }