sforkowany z mirror/soapbox
Make app repair itself if broken
rodzic
44f196fa99
commit
db7cfacff1
|
@ -17,7 +17,7 @@ const noOp = () => () => new Promise(f => f());
|
||||||
function initAuthApp() {
|
function initAuthApp() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const hasToken = hasAppToken(getState);
|
const hasToken = hasAppToken(getState);
|
||||||
const action = hasToken ? noOp : createAppAndToken;
|
const action = hasToken ? verifyApp : createAppAndToken;
|
||||||
return dispatch(action())
|
return dispatch(action())
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
dispatch(showAlertForError(error));
|
dispatch(showAlertForError(error));
|
||||||
|
@ -65,6 +65,14 @@ function createAppToken() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function verifyApp() {
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
return api(getState, 'app').get('/api/v1/apps/verify_credentials')
|
||||||
|
.then (response => dispatch(authAppCreated(response.data)))
|
||||||
|
.catch(error => dispatch(createAppAndToken()));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function createUserToken(username, password) {
|
function createUserToken(username, password) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const app = getState().getIn(['auth', 'app']);
|
const app = getState().getIn(['auth', 'app']);
|
||||||
|
|
Ładowanie…
Reference in New Issue