Files
back_end_oudelaa/src/modules/auth/strategies/super-admin-jwt.strategy.ts
T

25 lines
867 B
TypeScript

import { Injectable, UnauthorizedException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { JwtPayload } from '../../../common/interfaces/jwt-payload.interface';
@Injectable()
export class SuperAdminJwtStrategy extends PassportStrategy(Strategy, 'superadmin-jwt') {
constructor(configService: ConfigService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: configService.get<string>('superAdmin.accessSecret', { infer: true }) ?? '',
});
}
validate(payload: JwtPayload): JwtPayload {
if (payload.tokenType !== 'superadmin_access') {
throw new UnauthorizedException('Invalid superadmin token');
}
return payload;
}
}