2

Setup: I have a LoggedInGuard (injected with AuthService). In AuthService's constructor I've subscribed to http.get to set this.loggedIn = true based on the response from server.

Question: When user is already logged in (another tab or some other time in past) and directly lands on a route (which is LoggedInGuard guarded) by the time http.get completes, LoggedInGuard checks on the this.loggedIn and assumes user is not logged in. How to block the guard until http.get completes ?

Anand Rockzz
  • 6,072
  • 5
  • 64
  • 71
  • The desired behavior is how guards work by default. Perhaps you have a bug. Did you forget to `return`? – Aluan Haddad Mar 21 '17 at 00:52
  • `canActivate` can return an `Observable`, so return one that includes your HTTP request in its composition. – cartant Mar 21 '17 at 00:55
  • @cartan oh yeah, but the reason I did **not** use it is: In LoggedInGuard, i have extra logic: if the user is **not** loggedIn, I need to `this.router.navigate(['/auth/login']);` – Anand Rockzz Mar 21 '17 at 01:13

0 Answers0