Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions src/lib/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,24 +200,33 @@ function request(command, data, type = 'post') {
if (!reauthenticating && responseData.jsonCode === 407 && data.doNotRetry !== true) {
reauthenticating = true;
return Ion.get(IONKEYS.CREDENTIALS)
.then(({login, password}) => xhr('Authenticate', {
useExpensifyLogin: false,
partnerName: CONFIG.EXPENSIFY.PARTNER_NAME,
partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD,
partnerUserID: login,
partnerUserSecret: password,
twoFactorAuthCode: ''
})
.then((response) => {
reauthenticating = false;
return setSuccessfulSignInData(response);
.then((credentials) => {
// The first time we load the app we won't have credentials to re-authenticate with
// so we send the user to the signin page
if (!credentials || !credentials.login || !credentials.password) {
return redirectToSignIn();
}

// If we have login credentials stored in Ion, we use them to re-authenticate
return xhr('Authenticate', {
useExpensifyLogin: false,
partnerName: CONFIG.EXPENSIFY.PARTNER_NAME,
partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD,
partnerUserID: credentials.login,
partnerUserSecret: credentials.password,
twoFactorAuthCode: ''
})
.then(() => xhr(command, data, type))
.catch(() => {
reauthenticating = false;
redirectToSignIn();
return Promise.reject();
}));
.then((response) => {
reauthenticating = false;
return setSuccessfulSignInData(response);
})
.then(() => xhr(command, data, type))
.catch(() => {
reauthenticating = false;
redirectToSignIn();
return Promise.reject();
});
});
}
return responseData;
});
Expand Down