npm i identity-admin
- Creating Dashboard with minimal Ui for mongoose models.
- Provide DashboardController for custom routing and middlewares.
- Provide multiple dashboard instances with diffrent routes.
- 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);
- 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);
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);
}
}
Dashboard(dashBoardConfig: DashboardConfig);
build(app: Application): void;
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
}