import { Injectable } from '@angular/core' ; import { CanActivate , Router } from '@angular/router' ; import { GameService } from './game.service' ; @ Injectable ( { providedIn : 'root' } ) export class LoggedInGuard implements CanActivate { constructor ( private router , private gameService ) { } async canActivate ( ) { const hasPlayer = this . gameService . hasPlayer ; const id = this . gameService . loggedIn ; if ( ! hasPlayer ) { if ( id ) return true ; this . router . navigate ( [ '/home' ] ) ; return false ; } return hasPlayer ; } }