mirror of
https://github.com/CaramelFur/Picsur.git
synced 2025-11-12 23:05:39 +01:00
change jwt data
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user