Cleanup
This commit is contained in:
parent
c55f91811a
commit
c0a9bb5c48
@ -1,15 +1,11 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CanActivate, Router } from '@angular/router';
|
import { CanActivate } from '@angular/router';
|
||||||
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
|
||||||
import 'rxjs/add/observable/of';
|
|
||||||
|
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
import { ApiResponse } from '../index';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthGuard implements CanActivate {
|
export class AuthGuard implements CanActivate {
|
||||||
constructor(private authService: AuthService, private router: Router) {
|
constructor(private authService: AuthService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
canActivate() {
|
canActivate() {
|
||||||
|
@ -24,20 +24,12 @@ export class AuthService {
|
|||||||
|
|
||||||
return this.http.post('api/authenticate', token, { headers: header }).
|
return this.http.post('api/authenticate', token, { headers: header }).
|
||||||
map(res => {
|
map(res => {
|
||||||
let response: ApiResponse = res.json();
|
this.checkStatus(res);
|
||||||
|
|
||||||
if (res.status === 200 && response.data.length) {
|
return this.activeUser !== null;
|
||||||
this.activeUser = response.data[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}).
|
}).
|
||||||
catch((res, caught) => {
|
catch((res, caught) => {
|
||||||
let response: ApiResponse = res.json();
|
this.checkStatus(res);
|
||||||
this.activeUser = null;
|
|
||||||
localStorage.removeItem(this.jwtKey);
|
|
||||||
|
|
||||||
this.router.navigate(['']);
|
|
||||||
|
|
||||||
return Observable.of(false);
|
return Observable.of(false);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user