Files
IdP/apps/api-gateway/src/interceptors/fedcm-cookie.interceptor.ts
2026-06-29 12:17:25 +03:00

22 lines
735 B
TypeScript

import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { Observable, tap } from 'rxjs';
import type { Response } from 'express';
import { attachFedcmCookieFromAuthResult } from '../lib/fedcm-cookie';
@Injectable()
export class FedcmCookieInterceptor implements NestInterceptor {
constructor(private readonly jwt: JwtService) {}
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {
const http = context.switchToHttp();
const response = http.getResponse<Response>();
return next.handle().pipe(
tap((data) => {
attachFedcmCookieFromAuthResult(response, this.jwt, data);
})
);
}
}