Last active
April 3, 2019 06:37
-
-
Save ova2/d65be135d3e79b0ce7634a54022d0ed5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Injectable({ | |
| providedIn: 'root' | |
| }) | |
| export class LoggedInGuard implements CanActivate { | |
| protected constructor(private _router: Router, _store: CoreStore) { } | |
| public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> { | |
| return this._store.ready$.then(() => this.toResult(), () => this.toResult()); | |
| } | |
| private toResult(): boolean { | |
| const isLoggedIn = !!this._store.state.authToken; | |
| if (!isLoggedIn) { | |
| this._router.navigate(['/login']); | |
| } | |
| return isLoggedIn; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment