I'm sure there is a better way to do this but I can't seem to wrap my head around it right now.
We have several admin areas that only those in an admin role should get to, and have a custom standard guard for this.
We are also using AngularFire guards for general authenticated user routes that redirect to the login page if you are not logged in.
Right now, if you attempt to go to the admin route but are not an admin, you are not redirected.
For a really clean flow I would like the following to happen when attempting to access an admin route:
- If you pass the admin guard (are an admin role) allow you access
- If you are not an admin, but are logged in, send you to your user dashboard
- If you are not logged in send you to the login page
Right now I am chaining my guards like the following:
{
path: 'some-admin-path',
loadChildren: () => import('../components/some-admin.module')
.then(m => m.SomeAdminModule),
canActivate: [AdminGuard], ...canActivate(redirectLoggedInToDashboard), ...canActivate(redirectUnauthorizedToLogin)
},
{
However, this is a bit long and can be messy to use for all of our admin guards. How would I wrap all this up into a single AngularFire guard constant that I can use in the ...canActivate method?