NestJS circular services not working with Controller

Viewed 29

I have a circular dependency like so

Auth.service.ts

export class AuthService {
  constructor(
    @Inject(forwardRef(() => UserService))
    private userService: UserService,
  )

User.service.ts

export class UserService {
  constructor(
    @Inject(forwardRef(() => AuthService))
    private authService: AuthService,
  )

I have 3 controllers where I access these.

User.controller.ts

export class UserController {
  constructor(private readonly userService: UserService) {})

Auth.controller.ts

export class AuthController {
  constructor(private readonly authService: AuthService) {})

AuthUser.controller.ts

export class AuthUserController {
  constructor(
    private readonly authService: AuthService,
    private readonly userService: UserService,
  ) {}

I have a module.ts file where I'm setting everything up

@Module({
  imports: [],
  controllers: [
    AuthUserController,
    AuthController,
    UserController,
  ],
  providers: [
    AuthService,
    UserService,
  ],

I have a few endpoints in my controllers. They work fine from AuthController & UserController. But when calling from AuthUserController the classes are not being instantiated in the code. I'm not sure why or what I'm missing

0 Answers
Related