I have an angular2 project,
I blocked some route components by using 'canActivate' Guard
For example: The guard check if the user is logged in and block components for registered users only.
But, I have a problem with the timing of the guard call.
When app load - I call to AutoLogin request (login with token). The guard called before the request finished.
So, If the user refreshed page with guard, the guard block the page before the request finished.
Is there any way to call to the guard when the request finished?
----UPDATE----
My code structure:
user.service include:
- Autologin call - return Observable
- EventEmitter for observe the user changes when changes happen (login, logout, update etc...)
- Function for get the current saved user
app.component include:
- The constructor call to autologin request - for load the updated user when enter to the site
loggedin.guard contain:
- check if user loggedin right now (not only if the token saved)
I want to check the guard again after the user changed after the autologin finished the request in the app.component