identity-admin
TypeScript icon, indicating that this package has built-in type declarations

1.26.7 • Public • Published

Identity Admin Dashboard

Build Status

How to install

npm i identity-admin

Features

  • Creating Dashboard with minimal Ui for mongoose models.
  • Provide DashboardController for custom routing and middlewares.
  • Provide multiple dashboard instances with diffrent routes.

Create new unAuthenticated Dashboard:

  • Create new instance from Dashboard.
  • Provide Resources array of resources file.
  • Build the instance after mongoose setup by passing app instance to the build function.
const dashboard: Dashboard = new Dashboard({ resources:[ <Resource: IResourceFile> ]);
dashboard.build(app);

To create new Authenticated Dashboard:

  • Create new instance from Dashboard.
  • Provide Resources array of resources file.
  • Provide authenticate function which take AdminCredentials as parameter and return a promise of boolean or user data.
  • Provide cookiesConfiguration (cookie name and cookie secret).
  • Build the instance after mongoose setup by passing app instance to the build function.
const dashboard = new Dashboard({
        resources: [ UserResource ],
        cookiesConfiguration: {
            cookiesSecret: "cokieieSecret",
            cookieName: "connect.sid"
        },
        authenticate: async (credentials: AdminCredentials) => {
            const user = await Admin.findOne({ email: credentials.email });
            if (user) {
                const matched = await bcrypt.compare(credentials.password, user.encryptedPassword);
                if (matched) {
                    return user;
                }
            }
            return false;
        }
    })
dashboard.build(app);

To create new CustomRoutes Dashboard:

This method require to implement your own view and new react app

  • Create new controller class with invirsify-express-utils notaitions and extend ActionController.
  • Create new controller class with invirsify-express-utils notaitions and extend ResourceController.
  • Create new controller class with invirsify-express-utils notaitions and extend DashboardController.
  • Provide resource file and repository in super constructor.
  • Following class will create new route /v1/contries ***Now you can pass any auth middlewares you want
@controller('/v1/actions', defaultHeaders)
export default class ActionsController extends ActionController{
  
  constructor(
      @inject(TYPES.IResources) private resources: IResourceFile[]) {
      super(resources);
  }
}
@controller('/v1/resources', defaultHeaders)
export default class ResourcesController extends ResourceController{
  
  constructor(
      @inject(TYPES.IResources) private resources: IResourceFile[]) {
      super(resources);
  }
}
@controller('/v1/contries', defaultHeaders)
export default class CountryController extends DashboardController{
  
  constructor(
      @inject(TYPES.ICountryRepository) private countryRepository: CountryRepository,
      @inject(TYPES.ICountryResource) private countryResource: IResourceFile  ) {

      super(CountryResource, countryRepository);
  }
}

Documentaion:

    Dashboard(dashBoardConfig: DashboardConfig);
    build(app: Application): void;

Dashboard:

Dashboard constructor to create new instance from idntity-admin.

  • dashBoardConfig:
{
  resources: IResourceFile[]; // Array of resources files.
  rootPath?: string; // optional root path default to  /dashboard
  localesOptions?: i18n.ConfigurationOptions; // locales options for custom dashboard
  cookiesConfiguration: CookieConfiguration; // cookies configuration in case of authenticated dashboard
  authenticate?: AuthenticateMiddleWare; // authenticate function used to login the admin.
}
  • IResourceFile For resource file example check IResourceFile

  • CookieConfiguration

{
  cookiesSecret: string; // cookie secret to handle sessions
  cookieName: string; // cookie name as appeared in browser
}

Readme

Keywords

none

Package Sidebar

Install

npm i identity-admin

Weekly Downloads

75

Version

1.26.7

License

ISC

Unpacked Size

29.1 MB

Total Files

209

Last publish

Collaborators

  • mohamed-ismail
  • tareksalah