0

How does @nestjs/passport attach authentication to a gateway GraphQL module? Assuming my application looks like this:

// ./app.module.ts

@Module({
  providers: [JwtAuthGuard],
  imports: [
    AuthModule,
    GraphQLModule.forRoot<ApolloGatewayDriverConfig>({
      driver: ApolloGatewayDriver,
      server: {
        path: '/api',
        context: ({ req }) => ({ req }),
      },
      gateway: {
        supergraphSdl: /* ... */,
        buildService: /* ... */,
      },
    }),
  ],
})
export class AppModule {}

And the guard has been setup through the provider:

// auth/auth.module.ts

@Module({
  imports: [PassportModule.register({ defaultStrategy: 'jwt' })],
  providers: [
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard,
    },
    JwtStrategy,
  ],
  exports: [PassportModule],
})
export class AuthModule {}

The APP_GUARD isn't being called on each subsequent request made the GraphQL gateway server. I would expect that the functions nside JwtAuthGuard would be called.

bashaus
  • 1,614
  • 1
  • 17
  • 33

0 Answers0