5

If I replace the asynch/await below with a then(gAuth) construct my call to Google Auth Init works. At present the init() call never returns and the browser hangs.

Am I misunderstanding the requirements of "await"?

async function gInit() {
  // Check if already logged in with Google
  try {
    gAuth = await gapi.auth2.init({
      client_id: providers.google.clientId
    })
    alert("sign in: " + gAuth.isSignedIn.get());
  } catch (err) {
    alert(err.message || err.text)
    delete providers.google;
  }
}
10
  • 4
    This is probably an issue with gapi.auth2.init returning a promise that resolves with itself, thus creating an endless resolution loop. See github.com/google/google-api-javascript-client/issues/268 Commented Oct 13, 2017 at 0:04
  • Ah, sounds reasonable. I'll go back to .then() Thanks Commented Oct 13, 2017 at 0:10
  • @Phil What do you mean by "resolves with itself"? Commented Oct 13, 2017 at 0:15
  • 3
    @guest271314 init returns a GoogleAuth object. This object has a then method making it pass is-promise. The then method resolves with the GoogleAuth object itself so you can easily create an endless, recursive promise resolution loop. See the linked issue in my first comment Commented Oct 13, 2017 at 0:17
  • ... though it appears they've recently changed the API but not in any way that makes OP's code possible. The then method now resolves with the return value of its first, onInit argument. Not entirely clear what it does if that is omitted Commented Oct 13, 2017 at 0:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.