--
This commit is contained in:
parent
8fcc733093
commit
231adbe93f
123 changed files with 16683 additions and 62496 deletions
13
frontend/src/auth/load.js
Normal file
13
frontend/src/auth/load.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/* eslint-disable no-underscore-dangle */
|
||||
import jwtDecode from 'jwt-decode';
|
||||
import store from '../redux/store';
|
||||
import setAuthToken from '../axios/AuthToken';
|
||||
|
||||
export default () => {
|
||||
const token = window.localStorage.getItem('auth-token');
|
||||
if (token) {
|
||||
const user = jwtDecode(token);
|
||||
store.dispatch({ type: 'SET_USER', user });
|
||||
setAuthToken(token);
|
||||
}
|
||||
};
|
||||
9
frontend/src/auth/logout.js
Normal file
9
frontend/src/auth/logout.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import setAuthToken from '../axios/AuthToken';
|
||||
import store from '../redux/store';
|
||||
|
||||
export default () => {
|
||||
localStorage.removeItem('auth-token');
|
||||
setAuthToken(null);
|
||||
store.dispatch({ type: 'CLEAR_USER' });
|
||||
window.location.reload();
|
||||
};
|
||||
Loading…
Reference in a new issue