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 { const http = context.switchToHttp(); const response = http.getResponse(); return next.handle().pipe( tap((data) => { attachFedcmCookieFromAuthResult(response, this.jwt, data); }) ); } }