You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aConnect-UX/src/app/shared/guards/gauth.guard.ts

27 lines
655 B
TypeScript

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;
}
}
}