3

Is it possible to trigger AuthGuard within a component?

The purpose for this is if some logic fails, then it triggers the AuthGuard where AuthGuard holds the logic to navigate user until they have completed the tasks given in that page.

roger
  • 1,225
  • 2
  • 17
  • 33
  • How authGuard is holding the path to next page. If you want to navigate you could do using `router.navigate[youraddress]` – Eldho Sep 20 '18 at 06:42
  • You need to use the if conditions in case if error occur you can call the AuthGuard Service – Exterminator Sep 20 '18 at 06:43
  • You should redirect on your own, authguard is to protect a route – Pratap A.K Sep 20 '18 at 06:44
  • @Eldho I am trying to use the single responsibility principle, but the main reason for this is, `AuthGuard` holds the logic to direct to and store current path when user completes tasks on the other page. – roger Sep 20 '18 at 06:46
  • @Exterminator how do you do it? treat `AuthGuard` service as normal service when we call it? – roger Sep 20 '18 at 06:48
  • 1
    route guards are interfaces which can tell the router whether or not it should allow navigation to a requested route. https://ryanchenkie.com/angular-authentication-using-route-guards IMHO guards should not have any logic rather than basic authentication & roles checking – Eldho Sep 20 '18 at 06:50
  • 1
    Yes, you can use it or you can create a function in a service that will return value then you can use the value to redirect it or you can redirect from that function as well. – Exterminator Sep 20 '18 at 06:51

0 Answers0