Fix not logged in user error
parent
f54a348e03
commit
d0161f18ff
|
@ -1,7 +1,6 @@
|
|||
import {Injectable} from "@angular/core";
|
||||
import {Headers, Http, RequestMethod} from "@angular/http";
|
||||
import {Router} from "@angular/router";
|
||||
import {LoginService} from "./login-service/login-service";
|
||||
import {CookieService} from "ngx-cookie-service";
|
||||
|
||||
@Injectable()
|
||||
|
@ -13,8 +12,9 @@ export class HttpClient {
|
|||
}
|
||||
|
||||
createAuthorizationHeader() {
|
||||
let currentUser = JSON.parse(this.cookieService.get('currentUser'));
|
||||
if (currentUser) {
|
||||
const cookieField = this.cookieService.get('currentUser');
|
||||
if (cookieField) {
|
||||
const currentUser = JSON.parse(cookieField);
|
||||
if (new Date().getTime() <= Date.parse(currentUser.tokenExpireDate)) {
|
||||
let headers = new Headers();
|
||||
headers.append('x-access-token', currentUser.token);
|
||||
|
@ -25,6 +25,7 @@ export class HttpClient {
|
|||
this.router.navigate(['/login'])
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
get(url, searchParams?) {
|
||||
|
|
|
@ -21,7 +21,6 @@ export class LoginService {
|
|||
.map((response: Response) => {
|
||||
// login successful if there's a jwt token in the response
|
||||
let user = response.json();
|
||||
console.log(user);
|
||||
if (user && user.token) {
|
||||
// store user details and jwt token in cookie
|
||||
this.cookieService.set('currentUser', JSON.stringify(user));
|
||||
|
|
Loading…
Reference in New Issue