diff --git a/twistter-frontend/src/App.js b/twistter-frontend/src/App.js index f076cee..bec4ac6 100644 --- a/twistter-frontend/src/App.js +++ b/twistter-frontend/src/App.js @@ -36,14 +36,19 @@ const theme = createMuiTheme(themeObject); const token = localStorage.FBIdToken; if (token) { - const decodedToken = jwtDecode(token); - if (decodedToken.exp * 1000 < Date.now()) { - store.dispatch(logoutUser); + try { + const decodedToken = jwtDecode(token); + if (decodedToken.exp * 1000 < Date.now()) { + store.dispatch(logoutUser()); + window.location.href = "/login"; + } else { + store.dispatch({ type: SET_AUTHENTICATED }); + axios.defaults.headers.common['Authorization'] = token; + store.dispatch(getUserData()); + } + } catch (invalidTokenError) { + store.dispatch(logoutUser()); window.location.href = "/login"; - } else { - store.dispatch({ type: SET_AUTHENTICATED }); - axios.defaults.headers.common['Authorization'] = token; - store.dispatch(getUserData()); } }