SHARE
TWEET

Untitled

a guest Nov 18th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. // Login - get user token
  4. export const loginUser = userData => dispatch => {
  5.   return axios
  6.     .post("/api/users/login", userData)
  7.     .then(res => {
  8.       // Save to localStorage
  9.       // Set token to localStorage
  10.       const { token } = res.data;
  11.       localStorage.setItem("jwtToken", token);
  12.       // Set token to Auth header
  13.       setAuthToken(token);
  14.       // Decode token to get user data
  15.       const decoded = jwt_decode(token);
  16.       // Set current user
  17.       dispatch(setCurrentUser(decoded));
  18.     })
  19.     .catch(err =>
  20.       dispatch({
  21.         type: GET_ERRORS,
  22.         payload: err.response.data
  23.       })
  24.     );
  25. };
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. OK, I Understand
 
Top