Processing routes with authorization guard
Our application is complete and the routing works as expected. But there is a small problem. If you try to hit the http://localhost:4200/agent or http://localhost:4200/jobrequest URL without logging in, the app will redirect you to the respective page. This is happening since our routes are not protected.
To protect our routes, Angular has provided the AuthGuard
interfaces. We will implement them to protect unauthorized access to our application.
You can get more details about different types of route guards from the Angular website. Here, we will implement the CanActivate
route guard.
To check user authorization before the route is activated, we will use the CanActivate
guard.
We will generate two guards: one for our job request feature and another one for our agent feature. We can generate guards to restrict access for each route, but since our requirement is to allow user access for all job request features and agent access...