Role Base Authentication

The system ensures only authorized users can access specific routes based on their assigned roles.

  1. The main routing file defines route paths and lazy-loaded modules for various components based on the user's role.

src/app-routing.module.ts
...
{
    path: '',
    component: AdminLayout,
    canActivateChild: [AuthGuardChild],
    children: [
      {
        path: '',
        loadChildren: () => import('./demo/pages/dashboard/dashboard.module').then((m) => m.DashboardModule),
        data: { roles: [Role.Admin, Role.User] }
      },
      {
        path: 'dashboard',
        loadChildren: () => import('./demo/pages/dashboard/dashboard.module').then((m) => m.DashboardModule),
        data: { roles: [Role.Admin, Role.User] }
      },
      {
        path: 'widget',
        loadChildren: () => import('./demo/pages/widget/widget.module').then((m) => m.WidgetModule),
        data: { roles: [Role.Admin, Role.User] }
      },
      ...
    ]
}
...
  1. Child Routing Module: Defines the child routes and applies role-based access.

  1. Role Management

  1. Authentication Guard: This AuthGuardChild ensures that users can only access authorized routes.

Last updated