Fix not logged in user error

pull/10/head
Florian Hartwich 2017-09-23 12:05:51 +02:00
parent f54a348e03
commit d0161f18ff
2 changed files with 4 additions and 4 deletions

View File

@ -1,7 +1,6 @@
import {Injectable} from "@angular/core"; import {Injectable} from "@angular/core";
import {Headers, Http, RequestMethod} from "@angular/http"; import {Headers, Http, RequestMethod} from "@angular/http";
import {Router} from "@angular/router"; import {Router} from "@angular/router";
import {LoginService} from "./login-service/login-service";
import {CookieService} from "ngx-cookie-service"; import {CookieService} from "ngx-cookie-service";
@Injectable() @Injectable()
@ -13,8 +12,9 @@ export class HttpClient {
} }
createAuthorizationHeader() { createAuthorizationHeader() {
let currentUser = JSON.parse(this.cookieService.get('currentUser')); const cookieField = this.cookieService.get('currentUser');
if (currentUser) { if (cookieField) {
const currentUser = JSON.parse(cookieField);
if (new Date().getTime() <= Date.parse(currentUser.tokenExpireDate)) { if (new Date().getTime() <= Date.parse(currentUser.tokenExpireDate)) {
let headers = new Headers(); let headers = new Headers();
headers.append('x-access-token', currentUser.token); headers.append('x-access-token', currentUser.token);
@ -25,6 +25,7 @@ export class HttpClient {
this.router.navigate(['/login']) this.router.navigate(['/login'])
} }
} }
} }
get(url, searchParams?) { get(url, searchParams?) {

View File

@ -21,7 +21,6 @@ export class LoginService {
.map((response: Response) => { .map((response: Response) => {
// login successful if there's a jwt token in the response // login successful if there's a jwt token in the response
let user = response.json(); let user = response.json();
console.log(user);
if (user && user.token) { if (user && user.token) {
// store user details and jwt token in cookie // store user details and jwt token in cookie
this.cookieService.set('currentUser', JSON.stringify(user)); this.cookieService.set('currentUser', JSON.stringify(user));