react-oauth icon indicating copy to clipboard operation
react-oauth copied to clipboard

`useGoogleLogin` silently does nothing if invoked too soon

Open ArmorDarks opened this issue 5 months ago • 0 comments

Problem

If this code is invoked right on page load, it often does nothing:

const login = useGoogleLogin(...)

login()

The issue happens because callbacks are internally waiting for the Google script to finish loading and scriptLoadedSuccessfully to be true. See here.

However, if Google script took too long to load due to a bad network, or loading failed completely, invoking it will just do nothing, and there will be no errors or any indication in the console.

Proposal

Options:

  • Ensure that script is always awaited even if login() was invoked before it loaded
  • Emit onError with a reason to indicate that the script is not loaded, then users would have a way to handle it in their applications

ArmorDarks avatar Jul 07 '25 15:07 ArmorDarks