import { Injectable, OnInit } from '@angular/core';
import { CanActivateChild, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';

@Injectable()
export class AuthService implements CanActivateChild, OnInit {

    constructor(private router: Router) {
    }

    ngOnInit() {
    }

    canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        if (window.localStorage.getItem('token')) {
            return true;
        } else {
            this.router.navigate(['/extra']);
            return false;
        }
    }
}
