Cleanup
This commit is contained in:
parent
c55f91811a
commit
c0a9bb5c48
@ -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() {
|
||||
|
@ -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);
|
||||
});
|
||||
|
Reference in New Issue
Block a user