Bug 1433823 - Fix incorrect async handling during TPS login flow. r=markh

MozReview-Commit-ID: 4mcEcBvaKd

--HG--
extra : rebase_source : 5a7ce66bd0537e818d83cbcea7cde6b28854dd3d
This commit is contained in:
Thom Chiovoloni 2018-01-30 16:24:31 -05:00
parent d0f8d4d9cc
commit 6488e9aeb0
2 changed files with 25 additions and 15 deletions

View File

@ -32,6 +32,11 @@ var Authentication = {
return !!(await this.getSignedInUser());
},
async isReady() {
let user = await this.getSignedInUser();
return user && user.verified;
},
_getRestmailUsername(user) {
const restmailSuffix = "@restmail.net";
if (user.toLowerCase().endsWith(restmailSuffix)) {
@ -41,17 +46,20 @@ var Authentication = {
},
async shortWaitForVerification(ms) {
let userData = this.getSignedInUser();
let userData = await this.getSignedInUser();
let timeoutID;
let timeoutPromise = new Promise(resolve => {
timeoutID = setTimeout(() => {
Logger.logInfo(`Warning: no verification after ${ms}ms.`);
resolve();
}, ms);
});
await Promise.race([
fxAccounts.whenVerified(userData),
new Promise(resolve => {
setTimeout(() => {
Logger.logInfo(`Warning: no verification after ${ms}ms.`);
resolve();
}, ms);
})
fxAccounts.whenVerified(userData)
.finally(() => clearTimeout(timeoutID)),
timeoutPromise,
]);
userData = this.getSignedInUser();
userData = await this.getSignedInUser();
return userData && userData.verified;
},
@ -79,9 +87,6 @@ var Authentication = {
const tries = 10;
const normalWait = 2000;
for (let i = 0; i < tries; ++i) {
if (await this.shortWaitForVerification(normalWait)) {
return true;
}
let resp = await fetch(restmailURI);
let messages = await resp.json();
// Sort so that the most recent emails are first.
@ -106,6 +111,9 @@ var Authentication = {
// first time through after failing we'll do this.
await fxAccounts.resendVerificationEmail();
}
if (await this.shortWaitForVerification(normalWait)) {
return true;
}
}
// One last try.
return this.shortWaitForVerification(normalWait);

View File

@ -1179,7 +1179,7 @@ var TPS = {
* Login on the server
*/
async Login(force) {
if ((await Authentication.isLoggedIn()) && !force) {
if ((await Authentication.isReady()) && !force) {
return;
}
@ -1217,8 +1217,10 @@ var TPS = {
} else {
Weave.Svc.Prefs.reset("firstSync");
}
this.Login(false);
if (!await Weave.Service.login()) {
// We need to complete verification.
await this.Login(false);
}
++this._syncCount;
this._triggeredSync = true;