From the course: Building Angular and ASP.NET Web API Apps

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Secure routes with Angular Guards

Secure routes with Angular Guards

- [Instructor] In this part, you learn how to create and how to use an AuthGuard. In Angular, AuthGuard is a feature used to protect routes from unauthorized access. This way you ensure that certain parts of your app are only accessible to users who do meet certain conditions. Now, conditions for the users can be as simple as just to check if the user is authenticated or not, but you can also have more complex conditions, like for example, to check if the user has a certain role, they have a certain claim, and much more. To better understand this concept, let us go to our project. Now in here in this project, you can either use the Angular CLI, and for that, you just type ng generate guard, and then just provide the guard name. Or you can just create a folder manually, just type guards. Then right click in here, add a file. The file is going to be auth.guard.ts. Then inside here, we are just going to create a constant, export const authGuard. This will not take any parameters. And…

Contents