2020-04-01 19:20:47 -07:00
|
|
|
import api from '../api';
|
|
|
|
import { importFetchedAccount } from './importer';
|
|
|
|
|
|
|
|
export const ME_FETCH_REQUEST = 'ME_FETCH_REQUEST';
|
|
|
|
export const ME_FETCH_SUCCESS = 'ME_FETCH_SUCCESS';
|
|
|
|
export const ME_FETCH_FAIL = 'ME_FETCH_FAIL';
|
2020-04-11 16:55:07 -07:00
|
|
|
export const ME_FETCH_SKIP = 'ME_FETCH_SKIP';
|
2020-04-01 19:20:47 -07:00
|
|
|
|
|
|
|
export function fetchMe() {
|
|
|
|
return (dispatch, getState) => {
|
2020-04-11 16:55:07 -07:00
|
|
|
const accessToken = getState().getIn(['auth', 'user', 'access_token']);
|
2020-04-14 11:44:40 -07:00
|
|
|
if (!accessToken) return dispatch({ type: ME_FETCH_SKIP });
|
2020-04-01 19:20:47 -07:00
|
|
|
dispatch(fetchMeRequest());
|
2020-04-14 11:44:40 -07:00
|
|
|
api(getState).get('/api/v1/accounts/verify_credentials').then(response => {
|
2020-04-01 19:20:47 -07:00
|
|
|
dispatch(fetchMeSuccess(response.data));
|
|
|
|
dispatch(importFetchedAccount(response.data));
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch(fetchMeFail(error));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function fetchMeRequest() {
|
|
|
|
return {
|
|
|
|
type: ME_FETCH_REQUEST,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function fetchMeSuccess(me) {
|
|
|
|
return {
|
|
|
|
type: ME_FETCH_SUCCESS,
|
2020-04-14 11:44:40 -07:00
|
|
|
me,
|
2020-04-01 19:20:47 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function fetchMeFail(error) {
|
|
|
|
return {
|
|
|
|
type: ME_FETCH_FAIL,
|
|
|
|
error,
|
|
|
|
skipAlert: true,
|
|
|
|
};
|
|
|
|
};
|