thesearentthedroids
thesearentthedroids

Reputation: 620

NestJS Injecting request or execution context in services

How can I inject the request or the execution context in a service?

Upvotes: 12

Views: 15395

Answers (1)

Thierry Falvo
Thierry Falvo

Reputation: 6290

Since version 6.0, current request can be injected into a service, with REQUEST token :

export class AppService {
  constructor(@Inject(REQUEST) private request) {}

  load() {
    const user = this.request.user;
  }
}

Upvotes: 20

Related Questions