SHARE
TWEET

Untitled




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- // Login - get user token
- export const loginUser = userData => dispatch => {
- return axios
- .post("/api/users/login", userData)
- .then(res => {
- // Save to localStorage
- // Set token to localStorage
- const { token } = res.data;
- localStorage.setItem("jwtToken", token);
- // Set token to Auth header
- setAuthToken(token);
- // Decode token to get user data
- const decoded = jwt_decode(token);
- // Set current user
- dispatch(setCurrentUser(decoded));
- })
- .catch(err =>
- dispatch({
- type: GET_ERRORS,
- payload: err.response.data
- })
- );
- };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.