import { Injectable } from '@nestjs/common' ; import { JwtService } from '@nestjs/jwt' ; import { User , UserService } from '../shared/user' ; import type { JwtPayload , Payload } from './auth.interface' ; @ Injectable ( ) export class AuthService { constructor ( private jwt , private user ) { } public async validateUser ( username , password ) { const user = await this . user . fetch ( username ) ; if ( user && user . password === password ) { const { password : pass , ... result } = user ; return result ; } return null ; } public signJwt ( user ) { const payload = { sub : user . userId , username : user . username , roles : user . roles } ; return { access_token : this . jwt . sign ( payload ) , } ; } }