From c507dfa6c4828cf9d532100ca7015c9309971c59 Mon Sep 17 00:00:00 2001 From: Rokt33r Date: Wed, 21 Oct 2015 09:25:42 +0900 Subject: [PATCH] add Invalid token handler --- browser/main/index.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/browser/main/index.js b/browser/main/index.js index 624509b4..afc757f7 100644 --- a/browser/main/index.js +++ b/browser/main/index.js @@ -41,13 +41,19 @@ ReactDOM.render(( loadingCover.parentNode.removeChild(loadingCover) // Refresh user information - fetchCurrentUser() - .then(function (res) { - let user = res.body - store.dispatch(updateUser(user)) - }) - .catch(function (err) { - console.error(err.message) - console.log('Fetch failed') - }) + if (auth.user() != null) { + fetchCurrentUser() + .then(function (res) { + let user = res.body + store.dispatch(updateUser(user)) + }) + .catch(function (err) { + if (err.status === 401) { + auth.clear() + if (window != null) window.location.reload() + } + console.error(err.message) + console.log('Fetch failed') + }) + } })