Created
October 29, 2019 11:10
-
-
Save iamburakcoskun/c5a1a7ecd6a8660c31435569e6d788b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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