import { SignedUser } from '@api-interface' ; import { Injectable } from '@nestjs/common' ; import { JwtService } from '@nestjs/jwt' ; import { UserService } from '../user/user.service' ; import { JwtPayload } from './interfaces/jwt-payload.interface' ; @ Injectable ( ) export class AuthService { expiresIn = 3600 ; constructor ( private userService , private readonly jwtService ) { } async createToken ( username ) { const { firstName , lastName } = await this . userService . getUserByUsername ( username ) ; const payload = { username , firstName , lastName } ; const token = this . jwtService . sign ( payload ) ; return { expiresIn : this . expiresIn , token , username , firstName , lastName , } ; } async validateUser ( signedUser ) { if ( signedUser && signedUser . username ) { return Boolean ( this . userService . getUserByUsername ( signedUser . username ) ) ; } return false ; } }