Fix not logged in user error
parent
f54a348e03
commit
d0161f18ff
|
@ -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?) {
|
||||||
|
|
|
@ -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));
|
||||||
|
|
Loading…
Reference in New Issue