Skip to content

Commit

Permalink
bug(Fix jwt malformed error)Fix jwt malformed error [#169646191]
Browse files Browse the repository at this point in the history
  • Loading branch information
raymond42 committed Nov 9, 2019
1 parent e49d71b commit b5183ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/app/middleware/checkToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import jwdDecoded from 'jwt-decode';

const checkToken = () => next => action => {
try {
const token = jwdDecoded(localStorage.token);
console.log(token);
} catch (error) {
if (localStorage.token) {
window.location.assign('/login');
}
localStorage.token = '';
localStorage.username = '';
}
next(action);
};

export default checkToken;
5 changes: 3 additions & 2 deletions src/app/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { createStore, applyMiddleware } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import thunk from 'redux-thunk';
import rootReducer from '../reducers';
import checkToken from '../middleware/checkToken';

const initialState = {};

const middleware = [checkToken, thunk];
const store = createStore(
rootReducer,
initialState,
composeWithDevTools(applyMiddleware(thunk)),
composeWithDevTools(applyMiddleware(...middleware)),
);

export default store;

0 comments on commit b5183ee

Please sign in to comment.