• p

    porcellus

    6 months ago
    No silly questions 🙂 I'll copy an example here in a sec, that was intended as a very highlevel/quick summary of what I'm doing.
  • p

    porcellus

    6 months ago
    You could do something like this:
    ts
    import {
        MiddlewareConsumer,
        Module,
        NestModule,
        DynamicModule,
        FactoryProvider,
        ModuleMetadata,
      } from '@nestjs/common';
      
    import { ConfigInjectionToken, AuthModuleConfig } from './config.interface';
      
    type ModuleRootConf = Omit<FactoryProvider<AuthModuleConfig>, "provide" | "scope"> & Pick<ModuleMetadata, 'imports'>;
    
      @Module({
        providers: [],
        exports: [],
        controllers: [],
      })
      export class AuthModule implements NestModule {
        configure(consumer: MiddlewareConsumer) {
        }
      
        static forRoot({ useFactory, inject, imports }: ModuleRootConf): DynamicModule {
          return {
            providers: [
              {
                useFactory,
                inject,
                provide: ConfigInjectionToken,
              },
            ],
            imports,
            exports: [],
            module: AuthModule,
          };
        }
      }
  • p

    porcellus

    6 months ago
    oh one thing I skipped is adding middleware in
    configure
    , you should do that I just didn't have the full setup locally 😄
  • p

    porcellus

    6 months ago
    the main thing is the new
    forRoot
    interface. maybe it'd be better renamed to
    forRootAsync
  • p

    porcx

    6 months ago
    @User Sorry again. It worked Thanks alot. But can you give me an idea what this line is doing
    type ModuleRootConf = Omit<FactoryProvider<AuthModuleConfig>, "provide" | "scope"> & Pick<ModuleMetadata, 'imports'>;
  • p

    porcellus

    6 months ago
    Sure. It's a bit convoluted 😄
  • p

    porcellus

    6 months ago
    So: the new config object you want to pass to
    forRoot
    is made up of two parts:- We want you to add everything necessary for a
    FactoryProvider
    that will provide an
    AuthModuleConfig
    , but we are overriding the provide option and scope could mess with some things so we don't want to allow those (hence the
    Omit
    )- You may need to import something in the factory you added so we want to allow an imports prop just like you would configure for a normal modules (so
    Pick
    the imports prop from the
    ModuleMetadata
    )
  • -|Maix|

    -|Maix|

    6 months ago
    Hi, I found this library (and ecosystem) and I would like to use it but there isn't a library for the language I wish to use (Rust), so I thought of creating a backend sdk in Rust. I am only starting to research on how it should be made. I wanted to know if there was a lot of magic that happens in the backend sdk ? Having a good documentation of the APIs will surely help but I'm not sure it is enought and I might need to read some of another backend SDK. If i end up needing to read an SDK which one do you think will be the best ? (Either Node.js or python as I don't know Go). For now this is just a thought in my head as I don't want to jump into this big project without thinking about it before
  • -|Maix|

    -|Maix|

    6 months ago
    As I understand currently the backend SDK provides a set of http endpoints and translate it for the core to understand
  • r

    rp

    6 months ago
    I wanted to know if there was a lot of magic that happens in the backend sdk ? There is indeed a lot happening in the backend SDK.
    If i end up needing to read an SDK which one do you think will be the best ? You can read the supertokens-node one.
    As I understand currently the backend SDK provides a set of http endpoints and translate it for the core to understand Yes. So those endpoints exposed by the backend SDK (via a middleware) are called by the frontend. In turn the backend SDK calls the core. The backend SDK also does input normalisation and sanitisation + reading and setting cookies whenever needed. For effeciency purpose, the backend SDK also does stateless session verification.