From c6ec02429dd49c0275d93cbad410b6ab24dfe230 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 8 Mar 2016 13:34:00 +0100 Subject: [PATCH] Log user out only if necessary on failed user data request --- app/routes/application.js | 9 +++++++-- app/services/auth.js | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/routes/application.js b/app/routes/application.js index f43b37d2..02b70a72 100644 --- a/app/routes/application.js +++ b/app/routes/application.js @@ -9,8 +9,13 @@ export default TravisRoute.extend(BuildFaviconMixin, { this._super.apply(this, arguments); return this.get('auth').refreshUserData().then( () => { this.setupPendo(); - }, () => { - return this.get('auth').signOut(); + }, (xhr) => { + // if xhr is not defined it means that scopes are not correct, + // so log the user out. Also log the user out if the response is 401 + // or 403 + if(!xhr || (xhr.status === 401 || xhr.status === 403)) { + return this.get('auth').signOut(); + } }); }, diff --git a/app/services/auth.js b/app/services/auth.js index 0487cfef..fa74fb06 100644 --- a/app/services/auth.js +++ b/app/services/auth.js @@ -140,7 +140,7 @@ export default Ember.Service.extend({ data.user.token = user.token; this.storeData(data, this.get('sessionStorage')); this.storeData(data, this.get('storage')); - return Travis.trigger('user:refreshed', data.user); + Travis.trigger('user:refreshed', data.user); } } else { return Ember.RSVP.Promise.reject();