add: role in jwt

This commit is contained in:
ilham
2021-12-09 21:30:10 +07:00
parent 19c951c331
commit a057088a93
2 changed files with 56 additions and 38 deletions

View File

@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import { UsersService } from '../users/users.service';
import { hashPassword } from '../helper/hash_password';
import { JwtService } from '@nestjs/jwt';
import { User } from '../users/entities/user.entity';
@Injectable()
export class AuthService {
@@ -22,10 +23,11 @@ export class AuthService {
return null;
}
async login(user: any) {
async login(user: User) {
const payload = {
username: user.username,
sub: user.userId,
sub: user.id,
role: user.roles.name,
};
return {