Hey there, I'm using supertokens in my NestJS app. I'm looking to have 2 different auth strategies, ...
g

gp01683

about 2 years ago
Hey there, I'm using supertokens in my NestJS app. I'm looking to have 2 different auth strategies, one for admin users and one for nomal users. I would like to have 2 different routes and 2 different supertokens service to I can customize sign in / signup options on both independently. Here's what I got at the moment: My abstracted identity module, following the supertokens doc:
export class IdentityAndAccessModule implements NestModule, OnModuleInit {
  ...

  static forRoot({ connectionURI, apiKey, appInfo, caslFactory }) {
    const providers: Provider[] = [
     ...
      {
        useValue: {
          appInfo,
          connectionURI,
          apiKey,
        },
        provide: ConfigInjectionToken,
      },
      SupertokensService,
      PrismaService,
    ];

    return {
      module: IdentityAndAccessModule,
      providers: providers,
      exports: providers,
    };
  }

...
}
Then my 2 auth modules, one for normal users and one for admin:
@Module({
  imports: [
    PrismaModule,
    // TODO: config
    IdentityAndAccessModule.forRoot({
      connectionURI: 'http://localhost:3567',
      appInfo: {
        appName: 'WC APP',
        apiDomain: 'http://localhost:3001',
        websiteDomain: 'http://localhost:3000',
        apiBasePath: '/auth',
        websiteBasePath: '/auth',
      },
      caslFactory: AppCaslFactory,
    }),
  ],
  providers: [AuthService, ...oauthProviders],
  exports: [AuthService, IdentityAndAccessModule],
  controllers: [],
})
export class CustomerAuthModule {}
and another one identical but using /admin/auth as base path for both API and website. My problem is that the first module registered in app.module.ts, will be available but not the other one. So /auth/signin works but /admin/auth/signin always return 404. Any idea? I guess it comes from my module being setup as singleton but can't find any way to have multiple instances using its own config