kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
rodzic
8eba7af308
commit
b78e923f83
|
@ -1,6 +1,5 @@
|
||||||
import api from '../api';
|
import api from '../api';
|
||||||
import { importFetchedAccount } from './importer';
|
import { importFetchedAccount } from './importer';
|
||||||
import { refreshUserToken } from './auth';
|
|
||||||
|
|
||||||
export const ME_FETCH_REQUEST = 'ME_FETCH_REQUEST';
|
export const ME_FETCH_REQUEST = 'ME_FETCH_REQUEST';
|
||||||
export const ME_FETCH_SUCCESS = 'ME_FETCH_SUCCESS';
|
export const ME_FETCH_SUCCESS = 'ME_FETCH_SUCCESS';
|
||||||
|
@ -11,19 +10,19 @@ export const ME_PATCH_REQUEST = 'ME_PATCH_REQUEST';
|
||||||
export const ME_PATCH_FAIL = 'ME_PATCH_FAIL';
|
export const ME_PATCH_FAIL = 'ME_PATCH_FAIL';
|
||||||
|
|
||||||
const hasToken = getState => getState().hasIn(['auth', 'user', 'access_token']);
|
const hasToken = getState => getState().hasIn(['auth', 'user', 'access_token']);
|
||||||
|
const noOp = () => new Promise(f => f());
|
||||||
|
|
||||||
export function fetchMe() {
|
export function fetchMe() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
|
|
||||||
if (!hasToken(getState)) {
|
if (!hasToken(getState)) {
|
||||||
dispatch({ type: ME_FETCH_SKIP }); return;
|
dispatch({ type: ME_FETCH_SKIP }); return noOp();
|
||||||
};
|
};
|
||||||
|
|
||||||
dispatch(refreshUserToken()).then(() => {
|
|
||||||
dispatch(fetchMeRequest());
|
dispatch(fetchMeRequest());
|
||||||
|
|
||||||
return api(getState).get('/api/v1/accounts/verify_credentials').then(response => {
|
return api(getState).get('/api/v1/accounts/verify_credentials').then(response => {
|
||||||
dispatch(fetchMeSuccess(response.data));
|
dispatch(fetchMeSuccess(response.data));
|
||||||
});
|
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(fetchMeFail(error));
|
dispatch(fetchMeFail(error));
|
||||||
});
|
});
|
||||||
|
|
Ładowanie…
Reference in New Issue