Skip to content

Instantly share code, notes, and snippets.

@avatsaev
Last active March 2, 2017 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avatsaev/9e13cc15fd77130045f1890a6518b250 to your computer and use it in GitHub Desktop.
Save avatsaev/9e13cc15fd77130045f1890a6518b250 to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
import {CanActivate, Router} from "@angular/router";
import {Angular2TokenService} from "angular2-token";
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private authTokenService:Angular2TokenService,
private router:Router){}
canActivate() {
if(this.authTokenService.userSignedIn()){
return true;
}else{
this.router.navigate(['/']);
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment