Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
  3. import { Observable } from 'rxjs/Rx';
  4. import { MockAuthenticationService } from './authentication/authentication.service';
  5. @Injectable()
  6. export class AsynchronousGuard implements CanActivate {
  7. constructor(private router: Router, private auth: MockAuthenticationService) {}
  8. canActivate(route:ActivatedRouteSnapshot,
  9. state:RouterStateSnapshot):Observable<boolean>|boolean {
  10. this.auth.subscribe((authenticated) => {
  11. if (authenticated) {
  12. return true;
  13. }
  14. this.router.navigateByUrl('/login');
  15. return false;
  16. });
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement