Refactor fetchMe() function
This commit is contained in:
parent
bf2f1e0cdf
commit
95d3b72f9b
1 changed files with 10 additions and 4 deletions
|
@ -6,14 +6,20 @@ export const ME_FETCH_SUCCESS = 'ME_FETCH_SUCCESS';
|
|||
export const ME_FETCH_FAIL = 'ME_FETCH_FAIL';
|
||||
export const ME_FETCH_SKIP = 'ME_FETCH_SKIP';
|
||||
|
||||
function hasToken(getState) {
|
||||
const accessToken = getState().getIn(['auth', 'user', 'access_token']);
|
||||
return Boolean(accessToken);
|
||||
}
|
||||
|
||||
export function fetchMe() {
|
||||
return (dispatch, getState) => {
|
||||
const accessToken = getState().getIn(['auth', 'user', 'access_token']);
|
||||
if (!accessToken) {
|
||||
dispatch({ type: ME_FETCH_SKIP });
|
||||
return;
|
||||
|
||||
if (!hasToken(getState)) {
|
||||
dispatch({ type: ME_FETCH_SKIP }); return;
|
||||
};
|
||||
|
||||
dispatch(fetchMeRequest());
|
||||
|
||||
api(getState).get('/api/v1/accounts/verify_credentials').then(response => {
|
||||
dispatch(fetchMeSuccess(response.data));
|
||||
dispatch(importFetchedAccount(response.data));
|
||||
|
|
Loading…
Reference in a new issue