react-oauth
react-oauth copied to clipboard
`useGoogleLogin` silently does nothing if invoked too soon
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
onErrorwith a reason to indicate that the script is not loaded, then users would have a way to handle it in their applications