This commit is contained in:
Matthew Ross 2016-07-16 18:13:16 -04:00
parent c55f91811a
commit c0a9bb5c48
2 changed files with 5 additions and 17 deletions

View File

@ -1,15 +1,11 @@
import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import { CanActivate } from '@angular/router';
import { AuthService } from './auth.service';
import { ApiResponse } from '../index';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router) {
constructor(private authService: AuthService) {
}
canActivate() {

View File

@ -24,20 +24,12 @@ export class AuthService {
return this.http.post('api/authenticate', token, { headers: header }).
map(res => {
let response: ApiResponse = res.json();
this.checkStatus(res);
if (res.status === 200 && response.data.length) {
this.activeUser = response.data[1];
}
return true;
return this.activeUser !== null;
}).
catch((res, caught) => {
let response: ApiResponse = res.json();
this.activeUser = null;
localStorage.removeItem(this.jwtKey);
this.router.navigate(['']);
this.checkStatus(res);
return Observable.of(false);
});