BE/src/interceptors/logout.interceptor.ts

31 lines
739 B
TypeScript
Raw Normal View History

2025-06-16 15:53:15 +05:30
// refresh-token.interceptor.ts
import {
Injectable,
NestInterceptor,
ExecutionContext,
CallHandler,
BadRequestException,
} from '@nestjs/common';
import { Observable } from 'rxjs';
@Injectable()
export class LogoutInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const request = context.switchToHttp().getRequest();
const refreshToken = request.cookies?.refresh_token;
if (!refreshToken) {
throw new BadRequestException('Refresh token not found in cookies');
}
// Attach refresh token to request object for later use
request.user = {
...(request.user || {}),
refreshToken,
};
return next.handle();
}
}