Skip to content

Instantly share code, notes, and snippets.

@iamburakcoskun
Created October 29, 2019 11:10
Show Gist options
  • Save iamburakcoskun/c5a1a7ecd6a8660c31435569e6d788b7 to your computer and use it in GitHub Desktop.
Save iamburakcoskun/c5a1a7ecd6a8660c31435569e6d788b7 to your computer and use it in GitHub Desktop.
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router} from "@angular/router";
import { Injectable } from "@angular/core";
import { AuthService } from "../_services/auth.service";
import { AlertifyService } from '../_services/alertify.service';
@Injectable()
export class LoginGuard implements CanActivate {
constructor(private authservice: AuthService, private router: Router, private alertify:AlertifyService) {}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): boolean {
let logged = this.authservice.isLoggedIn();
if (logged) {
return true;
}
this.router.navigate(["home"]);
this.alertify.error("Sayfaya erişim için sisteme giriş yapmalısınız!");
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment