From c0a9bb5c487c0a0e4d2cce7dc545a3b9d4de0131 Mon Sep 17 00:00:00 2001 From: Matthew Ross Date: Sat, 16 Jul 2016 18:13:16 -0400 Subject: [PATCH] Cleanup --- src/app/shared/auth/auth.guard.ts | 8 ++------ src/app/shared/auth/auth.service.ts | 14 +++----------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/app/shared/auth/auth.guard.ts b/src/app/shared/auth/auth.guard.ts index 9f47709..7d2814e 100644 --- a/src/app/shared/auth/auth.guard.ts +++ b/src/app/shared/auth/auth.guard.ts @@ -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() { diff --git a/src/app/shared/auth/auth.service.ts b/src/app/shared/auth/auth.service.ts index 72cfa2b..29fe542 100644 --- a/src/app/shared/auth/auth.service.ts +++ b/src/app/shared/auth/auth.service.ts @@ -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); });