Theodo-UK / nestjs-admin

A generic administration interface for TypeORM entities
https://nestjs-admin.com
MIT License
536 stars 60 forks source link

custom authentication docs are confusing, incomplete and/or incorrect #150

Closed lerickson-control4 closed 4 years ago

lerickson-control4 commented 4 years ago

I am trying to follow the guide here: https://nestjs-admin.com/docs/custom-authentication, for providing custom authentication for the nestjs-admin app. There are a couple of issues with the docs and/or the code that I don't understand.

FIrst, there is no static method create() on the AdminAuthModuleFactory class. Rather, it's createAdminAuthModule(), but that method does not allow provisioning a credentialProvider property through the factory as per the docs. The type accepted by that call only allows adminCoreModule, not an instance of AdminAuthModuleConfig.

Second, assuming I could get past the first issue, the CredentialValidatorProvider type does not appear to be exported from nestjs-amin, at least not from the top-level index. So just creating the validator doesn't work either. Also, the AdminAuthModuleConfig interface is not exported at all, so I'm not sure how that type gets exposed either.

Short of tweaking the credential provider a little I haven't strayed very far from the docs at all. Is there something I'm missing here? Using version 0.3.0.

Here is the error output:

 TS2345: Argument of type '{ adminCoreModule: { module: typeof AdminCoreModuleFactory; controllers: (typeof DefaultAdminController)[]; providers: (typeof DefaultAdminNunjucksEnvironment | typeof DefaultAdminSite | { ...; } | { ...; } | { ...; })[]; exports: (typeof DefaultAdminNunjucksEnvironment | ... 3 more ... | { ...; })[]; }; credentialP...' is not assignable to parameter of type 'AdminAuthModuleConfig'.
  Object literal may only specify known properties, and 'credentialProvider' does not exist in type 'AdminAuthModuleConfig'.

ERROR in .../src/backoffice/credentialValidator.ts
./src/backoffice/credentialValidator.ts

ERROR in .../src/backoffice/credentialValidator.ts(2,10)
      TS2305: Module '"../../../../../../../Users/lerickson/dev/hospitality/hospitality-api/node_modules/nestjs-admin/dist/src"' has no exported member 'CredentialValidatorProvider'.
ishpagin commented 4 years ago

Hi, see my PR https://github.com/Theodo-UK/nestjs-admin/pull/151/commits/6f7396ae6fa1581c72dc30e92edc18a3b084afb8

ishpagin commented 4 years ago

createAdminAuthModule it's for creating auth module, to create core you need to use createAdminCoreModule instead of create.

ishpagin commented 4 years ago

I have issue with import { CredentialValidatorProvider } from 'nestjs-admin' too.. The TS say me:

Module '"../../node_modules/nestjs-admin/dist/src"' has no exported member 'CredentialValidatorProvider'.

@williamdclt can you tell us please how to get that provider?

ishpagin commented 4 years ago

@lerickson-control4 good news for us. I have found the sample with using the Validator of admin login. See here: https://github.com/Theodo-UK/nestjs-admin/blob/master/exampleApp/src/user/userCredentialValidator.ts

We mustn't use the CredentialValidatorProvider in the new way to do this.

This is solution.

williamdclt commented 4 years ago

Thank you @ishpartko for your PR! The docs are indeed somehow outdated, I do realise this is confusing and annoying. I struggle to find the time to maintain this library as well as it deserves, sadly. Hopefully it'll get better!