Angular Auth Gaurd
Hey, Guys Learning is a long term process. While keeping yourself up-to-date with the latest feature of the legacy thing is a tedious task. But we should not be hesitant with that, because all the add-ons are based on the core basic principle. Yeah, the updates are in the coming is in the form of optimization/library or bug patch. So we should not ignore if we wish to keep our app updated and browser friendly.
Coming back to my Title. Angular Auth Gaurd. If you are junior dev or new to Angular let me tell you some scenario where you stuck and want to prevent the user to navigate to a certain page.
Yeah, correct some authenticated page !!
Here comes Angular Guard which helps you to add the hook based on your preferred condition. And rest is taken care of by them, to prevent the page to open.
Angular comes with Auth guard is pretty straight forward utility add on to use and secure your page navigation.
So, Yes If you are looking for login log out page restriction scenario this will help.
But how to add ...
Just put ng g guard gaurdName that's it :) // this is similar to service we know..
In the File, you will get a function called canActivateRoute.....
you just need condition which returns boolean based on your authentication use case.
And Don't forget to add this to parent all the Authenticated pages in the App.routing page.
Coming back to my Title. Angular Auth Gaurd. If you are junior dev or new to Angular let me tell you some scenario where you stuck and want to prevent the user to navigate to a certain page.
Yeah, correct some authenticated page !!
Here comes Angular Guard which helps you to add the hook based on your preferred condition. And rest is taken care of by them, to prevent the page to open.
Angular comes with Auth guard is pretty straight forward utility add on to use and secure your page navigation.
So, Yes If you are looking for login log out page restriction scenario this will help.
But how to add ...
Just put ng g guard gaurdName that's it :) // this is similar to service we know..
In the File, you will get a function called canActivateRoute.....
you just need condition which returns boolean based on your authentication use case.
And Don't forget to add this to parent all the Authenticated pages in the App.routing page.