import 'rxjs/add/operator/do' ; import 'rxjs/add/operator/map' ; import 'rxjs/add/operator/take' ; import { Injectable } from '@angular/core' ; import { CanActivate , Router } from '@angular/router' ; import { Observable } from 'rxjs/Observable' ; import { AuthService } from './auth.service' ; @ Injectable ( ) export class AuthGuard implements CanActivate { constructor ( private authService , private router ) { } canActivate ( ) { return this . authService . authState$ . take ( 1 ) . map ( authState => ! ! authState ) . do ( authenticated => { if ( ! authenticated ) { this . router . navigate ( [ '/sign-in' ] ) ; } } ) ; } }