Skip to content

Commit

Permalink
feat: add extract from cookie to refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
LhonRafaat committed Oct 14, 2024
1 parent bb38b59 commit e355902
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/modules/auth/strategies/refresh.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Injectable, UnauthorizedException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { UsersService } from '../../users/users.service';
import { EnvConfig } from '../../../config.type';
import { IRequest } from '../../../common/helper/common-types';

/**
* Jwt Strategy Class
Expand All @@ -15,12 +16,19 @@ export class RefreshStrategy extends PassportStrategy(Strategy, 'refresh') {
private readonly userService: UsersService,
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
jwtFromRequest: ExtractJwt.fromExtractors([
ExtractJwt.fromAuthHeaderAsBearerToken(),
RefreshStrategy.extractFromCookie,
]),
ignoreExpiration: false,
secretOrKey: configService.get('REFRESH_SECRET'),
});
}

private static extractFromCookie(req: IRequest): string | null {
return req?.cookies?.access_token || null;
}

async validate({ iat, exp, _id }, done): Promise<boolean> {
const timeDiff = exp - iat;
if (timeDiff <= 0) {
Expand Down

0 comments on commit e355902

Please sign in to comment.