Role Base Authentication
The system ensures only authorized users can access specific routes based on their assigned roles.
The main routing file defines route paths and lazy-loaded modules for various components based on the user's role.
`
// angular imports
import { Routes } from '@angular/router';
// project import
import { AdminComponent } from './theme/layout/admin/admin.component';
import { GuestComponent } from './theme/layout/guest/guest.component';
import { authGuardChild } from './theme/shared/_helpers/auth.guard';
import { Role } from './theme/shared/_helpers/role';
const routes: Routes = [
.....
{
path: '',
component: AdminComponent,
canActivateChild: [AuthGuardChild],
children: [
{
path: '',
loadComponent: () => import('./demo/dashboard/default/default.component').then((c) => c.DefaultComponent),
data: { roles: [Role.Admin, Role.User] }
},
{
path: 'default',
loadComponent: () => import('./demo/dashboard/default/default.component').then((c) => c.DefaultComponent),
data: { roles: [Role.Admin, Role.User] }
},
{
path: 'analytics',
loadComponent: () => import('./demo/dashboard/analytics/analytics.component').then((c) => c.AnalyticsComponent),
data: { roles: [Role.Admin] }
},
....
]
....
}
Child Routing Module: Defines the child routes and applies role-based access.
Role Management
Authentication Guard: This
AuthGuardChildensures that users can only access authorised routes.
Last updated