Refreshing the user token: just... don't even. Fixes #56, #73

This commit is contained in:
Alex Gleason 2020-05-17 16:31:54 -05:00
parent 8eba7af308
commit b78e923f83
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -1,6 +1,5 @@
import api from '../api';
import { importFetchedAccount } from './importer';
import { refreshUserToken } from './auth';
export const ME_FETCH_REQUEST = 'ME_FETCH_REQUEST';
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';
const hasToken = getState => getState().hasIn(['auth', 'user', 'access_token']);
const noOp = () => new Promise(f => f());
export function fetchMe() {
return (dispatch, getState) => {
if (!hasToken(getState)) {
dispatch({ type: ME_FETCH_SKIP }); return;
dispatch({ type: ME_FETCH_SKIP }); return noOp();
};
dispatch(refreshUserToken()).then(() => {
dispatch(fetchMeRequest());
return api(getState).get('/api/v1/accounts/verify_credentials').then(response => {
dispatch(fetchMeSuccess(response.data));
});
dispatch(fetchMeRequest());
return api(getState).get('/api/v1/accounts/verify_credentials').then(response => {
dispatch(fetchMeSuccess(response.data));
}).catch(error => {
dispatch(fetchMeFail(error));
});