Defining a JWT Structure
The authentication module works best if you define the structure of JWTs - JWT validation will include checking that JWTs match the structure defined via class-validator.
src/user/dto/jwt-payload.ts
import { Role } from "acl"; (1)
import { IsString } from "class-validator";
export class JWTPayload {
@IsString()
sub: string;
@IsString({
each: true,
})
roles: Role[];
}
1 | This example uses roles defined in a ACL package, created with Formulaic’s ACL Utilities. |