From 7d637e84e458ad02a1979465886fcc2e6829da8b Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Fri, 8 Sep 2017 14:59:31 +0100 Subject: [PATCH] Fix race condition in login --- src/app/providers/api-service.ts | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/app/providers/api-service.ts b/src/app/providers/api-service.ts index c892d1c..da05708 100644 --- a/src/app/providers/api-service.ts +++ b/src/app/providers/api-service.ts @@ -55,21 +55,23 @@ export class ApiService { } public login(data) { - const login_event = this.http.post( - this.apiUrl + '/login', - data - ).map( response => response.json() ); - login_event.subscribe( - result => { - this.setSessionKey(result.session_key); - this.setUserInfo( - result.email, - result.display_name || result.name + return this.http + .post( + this.apiUrl + '/login', + data + ) + .map( + result => { + const json = result.json(); + this.setSessionKey(json.session_key); + this.setUserInfo( + json.email, + json.display_name || json.name ); - this.setUserType(result.user_type); - } - ); - return login_event; + this.setUserType(json.user_type); + return json; + } + ); } public logout() {