File

src/iam/interceptors/user.interceptor.ts

Index

Methods

Constructor

constructor(userService: UserService)
Parameters :
Name Type Optional
userService UserService No

Methods

Async intercept
intercept(context: ExecutionContext, next: CallHandler)
Parameters :
Name Type Optional
context ExecutionContext No
next CallHandler No
Returns : Promise<Observable<any>>
import {
  Injectable,
  NestInterceptor,
  ExecutionContext,
  CallHandler,
} from "@nestjs/common";
import { Observable } from "rxjs";
import { UserService } from "../user/user.service";

@Injectable()
export class UserInterceptor implements NestInterceptor {
  constructor(private readonly userService: UserService) {}

  async intercept(
    context: ExecutionContext,
    next: CallHandler,
  ): Promise<Observable<any>> {
    const request = context.switchToHttp().getRequest();
    await this.userService.checkOrCreateUser(request.user.id);

    return next.handle();
  }
}

results matching ""

    No results matching ""