import { Injectable } from '@angular/core' ; import { CanActivate , ActivatedRouteSnapshot , RouterStateSnapshot , Router } from '@angular/router' ; import { Observable } from 'rxjs' ; import Auth from '@aws-amplify/auth' ; @ Injectable ( { providedIn : 'root' } ) export class UnauthGuard implements CanActivate { constructor ( private _router ) { } canActivate ( next , state ) { return Auth . currentAuthenticatedUser ( ) . then ( ( ) => { this . _router . navigate ( [ 'auth/profile' ] ) ; return false ; } ) . catch ( ( ) => { return true ; } ) ; } }