scinote-web/app/javascript/packs/shared/actions/UsersActions.js

24 lines
552 B
JavaScript
Raw Normal View History

import axios from "../../app/axios";
2017-08-09 15:08:13 +08:00
import { CURRENT_USER_PATH } from "../../app/routes";
2017-08-09 21:21:02 +08:00
import { SET_CURRENT_USER } from "../../app/action_types";
2017-08-09 15:08:13 +08:00
function addCurrentUser(data) {
return {
type: SET_CURRENT_USER,
payload: data
};
}
export function getCurrentUser() {
return dispatch => {
axios
.get(CURRENT_USER_PATH, { withCredentials: true })
.then(({ data }) => {
dispatch(addCurrentUser(data.user));
})
.catch(error => {
console.log("get Current User Error: ", error);
});
};
}