import { Inject, Injectable, PLATFORM_ID } from '@angular/core'; import { CanActivate, Router } from '@angular/router'; import { isPlatformBrowser } from '@angular/common'; import { AuthService } from '../../services/auth.service'; @Injectable({ providedIn: 'root' }) export class GAuth implements CanActivate { constructor(private authservice: AuthService, private router: Router, @Inject(PLATFORM_ID) private platformId: object) { } canActivate() { if (this.authservice.IsLoggedIn()){ return true; } else { if(isPlatformBrowser(this.platformId)) this.router.navigate(['login']); return false; } } }