From 86403afdc232d4ac61e9975d9b2850e9fc0986eb Mon Sep 17 00:00:00 2001 From: Alex Feyerke Date: Mon, 19 Oct 2015 11:40:39 +0200 Subject: [PATCH 1/5] feat(error-handling,login): redirect to login on 403, token expiration --- app/controllers/login.js | 2 ++ app/routes/authenticated.js | 13 ++++++++----- app/templates/login.hbs | 4 +++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/controllers/login.js b/app/controllers/login.js index 0c7c2e6..e93f17b 100644 --- a/app/controllers/login.js +++ b/app/controllers/login.js @@ -1,6 +1,8 @@ import Ember from 'ember'; export default Ember.Controller.extend({ + queryParams: ['expired'], + expired: null, reset: function() { this.setProperties({ diff --git a/app/routes/authenticated.js b/app/routes/authenticated.js index ca9973a..93d6b28 100644 --- a/app/routes/authenticated.js +++ b/app/routes/authenticated.js @@ -4,20 +4,23 @@ export default Ember.Route.extend({ // Before the model is loaded, check if the admin is signed in, and redirect to login if not beforeModel: function(transition) { if (!window.hoodieAdmin.account.isSignedIn()) { - this.redirectToLogin(transition); + this.redirectToLogin(transition, false); } }, - redirectToLogin: function(transition) { + redirectToLogin: function(transition, expired) { + // Only show the "please log in again" message if explicitly requested + expired = expired || false; var loginController = this.controllerFor('login'); loginController.set('attemptedTransition', transition); - this.transitionTo('login'); + this.transitionTo('login', {expired: expired}); }, actions: { error: function(reason, transition) { - if (reason.status === 401) { - this.redirectToLogin(transition); + // If the token has expired, send back to login + if (reason.status === 401 || reason.status === 403) { + this.redirectToLogin(transition, true); } else { console.log('Something went wrong: ', reason); } diff --git a/app/templates/login.hbs b/app/templates/login.hbs index 325f2c3..85abd00 100644 --- a/app/templates/login.hbs +++ b/app/templates/login.hbs @@ -4,7 +4,9 @@