Files
dvbooking/src/auth/jwt.strategy.ts
Roland Schneider 7bf514b2aa add rbac basics
2025-10-28 11:04:35 +01:00

25 lines
735 B
TypeScript

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(configService: ConfigService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: configService.get<string>('JWT_SECRET') as string,
});
}
validate(payload: { sub: string; username: string; roles: Role[] }) {
return {
userId: payload.sub,
username: payload.username,
roles: payload.roles,
};
}
}