This commit is contained in:
Roland Schneider
2025-10-27 17:34:48 +01:00
parent dd5e170e52
commit a676398ac4
14 changed files with 834 additions and 15 deletions

19
src/auth/jwt.strategy.ts Normal file
View File

@@ -0,0 +1,19 @@
import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { ConfigService } from '@nestjs/config';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(private configService: ConfigService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: configService.get<string>('JWT_SECRET') as string,
});
}
validate(payload: { sub: string; username: string }) {
return { userId: payload.sub, username: payload.username };
}
}