Use this file to discover all available pages before exploring further.
Aibar SRL App implements a two-tier role model stored directly in the JWT payload. Every authenticated user is assigned either the administrador or empleado role at account creation. The role determines which routes a user can activate and which items appear in the sidebar navigation. Role enforcement happens at two layers simultaneously: Angular route guards block unauthorized navigation at the router level before any component is rendered, and the Sidebar component filters its own menu items at the UI level so that admin-only links are never shown to employees.
AuthService.getRol() decodes the JWT payload on demand and returns the rol claim. Because this reads from sessionStorage on every call, it always reflects the current token without any extra state management.
Aibar SRL App uses two functional CanActivateFn guards. Both are pure functions that rely on Angular’s inject() to access AuthService and Router — no class boilerplate required.
authGuard
adminGuard
authGuard protects every route inside the main layout. It checks the reactive isLoggedIn signal synchronously. If the signal is false, the user is redirected to /login and navigation is cancelled.
Reads authService.isLoggedIn() — the Angular signal, not a network call.
Returns true immediately if a session token exists.
Redirects to /login and returns false if no token is found.
adminGuard is applied on top of authGuard for routes that require administrator privileges. It calls authService.getRol() and compares the result against the string 'administrador'. Non-admin authenticated users are redirected to /viajes — the default landing page for employees — rather than being shown an error page.
Decodes the JWT payload via getRol() to read the rol claim.
Returns true only when the role is exactly 'administrador'.
Redirects authenticated non-admin users to /viajes and returns false.
adminGuard is always layered on top ofauthGuard. For a user to reach an admin route, both guards must pass: authGuard confirms a valid session exists, then adminGuard confirms the session belongs to an administrator. An unauthenticated visitor hits authGuard first and is sent to /login before adminGuard is ever evaluated.
The application’s route configuration is defined in app.routes.ts. All authenticated routes are nested under a shared Layout shell that carries canActivate: [authGuard]. Admin-only routes additionally declare canActivate: [adminGuard].
The app.routes.ts file currently defines the /auditoria path twice — once without adminGuard and once with it. Angular’s router matches the first definition it encounters, so the unguarded entry takes precedence in practice. The second adminGuard-protected entry has no effect as written. This is a known issue in the source that should be resolved by keeping only the adminGuard-protected definition.
The table below summarizes the guard coverage per route:
Route guards stop unauthorized navigation at the router, but the Sidebar component goes one step further — it hides admin-only links from employees entirely, so they never see menu items they cannot access.Each menu item carries a soloAdmin flag. The itemsVisibles getter evaluates authService.getRol() and filters out any item whose soloAdmin is true when the current user is not an administrator:
The sidebar template binds to itemsVisibles rather than itemsMenu, so employees see exactly five navigation items (Viajes, Choferes, Camiones, Multas, Combustible) while administrators see all seven.
empleado view
Sees: Viajes, Choferes, Camiones, Multas, Combustible.Attempting to navigate directly to /auditoria or /usuarios triggers adminGuard and redirects to /viajes.
administrador view
Sees all seven items including Auditoría and Usuarios.Has unrestricted access to every route in the application.