change jwt data

This commit is contained in:
rubikscraft
2022-03-21 23:23:32 +01:00
parent d11c8f9083
commit 0b65d496c3
4 changed files with 19 additions and 14 deletions

View File

@@ -13,7 +13,10 @@ export class AuthManagerService {
async createToken(user: EUserBackend): Promise<string> {
const jwtData: JwtDataDto = plainToClass(JwtDataDto, {
user,
user: {
username: user.username,
roles: user.roles,
},
});
const errors = await strictValidate(jwtData);

View File

@@ -1,8 +1,7 @@
import {
Inject,
Injectable,
Logger,
UnauthorizedException
Logger
} from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { plainToClass } from 'class-transformer';
@@ -23,14 +22,14 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
});
}
async validate(payload: any): Promise<EUserBackend> {
async validate(payload: any): Promise<EUserBackend | false> {
const jwt = plainToClass(JwtDataDto, payload);
const errors = await strictValidate(jwt);
if (errors.length > 0) {
this.logger.warn(errors);
throw new UnauthorizedException();
return false;
}
return jwt.user;