Bug 1433823 - Fix incorrect async handling during TPS login flow. r?markh
MozReview-Commit-ID: 7hnKlg7qGWA
--- a/services/sync/tps/extensions/tps/resource/auth/fxaccounts.jsm
+++ b/services/sync/tps/extensions/tps/resource/auth/fxaccounts.jsm
@@ -82,19 +82,16 @@ var Authentication = {
return false;
}
Logger.logInfo("Fetching mail (from restmail) for user " + username);
let restmailURI = `https://www.restmail.net/mail/${encodeURIComponent(username)}`;
let triedAlready = new Set();
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.
messages.sort((a, b) => new Date(b.receivedAt) - new Date(a.receivedAt));
for (let m of messages) {
// We look for a link that has a x-link that we haven't yet tried.
if (!m.headers["x-link"] || triedAlready.has(m.headers["x-link"])) {
continue;
@@ -109,16 +106,19 @@ var Authentication = {
} catch (e) {
Logger.logInfo("Warning: Failed to follow confirmation link: " + Log.exceptionStr(e));
}
}
if (i === 0) {
// 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);
},
async deleteEmail(user) {
let username = this._getRestmailUsername(user);
if (!username) {