Bug 1433823 - Fix incorrect async handling during TPS login flow. r?markh draft
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Tue, 20 Feb 2018 15:49:29 -0500
changeset 757569 c86defd7aabea402ce1b191169ba9c27dce2d9d9
parent 757568 da1b61115374c48fe3c537d6830f0e2abb6dfc7d
push id99779
push userbmo:tchiovoloni@mozilla.com
push dateTue, 20 Feb 2018 20:49:47 +0000
reviewersmarkh
bugs1433823
milestone60.0a1
Bug 1433823 - Fix incorrect async handling during TPS login flow. r?markh MozReview-Commit-ID: 7hnKlg7qGWA
services/sync/tps/extensions/tps/resource/auth/fxaccounts.jsm
--- 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) {