Advertisement
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
- })
- );
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement