add refresh token

This commit is contained in:
Roland Schneider
2025-11-14 16:18:07 +01:00
parent 96af8e564b
commit d11b0c65e0
4 changed files with 35 additions and 30 deletions

View File

@@ -5,16 +5,20 @@ import { ConfigService } from '@nestjs/config';
import { Role } from './role.enum';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(configService: ConfigService) {
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
constructor(private configService: ConfigService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
// This is the critical fix: ensure the strategy uses the ConfigService
// to get the secret at runtime.
secretOrKey: configService.get<string>('JWT_SECRET') as string,
});
}
validate(payload: { sub: string; username: string; roles: Role[] }) {
// The payload is already validated by passport-jwt at this point,
// so we can trust its contents.
validate(payload: { sub: number; username: string; roles: Role[] }) {
return {
userId: payload.sub,
username: payload.username,