mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-18 15:13:21 +08:00
24 lines
527 B
JavaScript
24 lines
527 B
JavaScript
|
import axios from "axios";
|
||
|
import { CURRENT_USER_PATH } from "../../app/routes";
|
||
|
import { SET_CURRENT_USER } from "./types";
|
||
|
|
||
|
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);
|
||
|
});
|
||
|
};
|
||
|
}
|