Files
bigcapital/packages/server/src/modules/Auth/strategies/Jwt.strategy.ts
2025-04-07 11:51:24 +02:00

25 lines
801 B
TypeScript

import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { AuthSigninService } from '../commands/AuthSignin.service';
import { JwtPayload } from '../Auth.interfaces';
import { ConfigService } from '@nestjs/config';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
constructor(
private readonly authSigninService: AuthSigninService,
private readonly configService: ConfigService,
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: configService.get('jwt.secret'),
});
}
validate(payload: JwtPayload) {
return this.authSigninService.verifyPayload(payload);
}
}