add rbac basics

This commit is contained in:
Roland Schneider
2025-10-28 11:04:35 +01:00
parent a676398ac4
commit 7bf514b2aa
17 changed files with 293 additions and 34 deletions

View File

@@ -2,10 +2,11 @@ import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { ConfigService } from '@nestjs/config';
import { Role } from './role.enum';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(private configService: ConfigService) {
constructor(configService: ConfigService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
@@ -13,7 +14,11 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
});
}
validate(payload: { sub: string; username: string }) {
return { userId: payload.sub, username: payload.username };
validate(payload: { sub: string; username: string; roles: Role[] }) {
return {
userId: payload.sub,
username: payload.username,
roles: payload.roles,
};
}
}