Authorize not resolving when locking device

Hey everyone! I’m seeing an issue where our app is setting a loading state as true when opening the popup to open a browser through await getAuth0Instance().webAuth.authorize and waiting for it to resolve to set the state back to false. There’s an edge case where, if a user locks the device while the popup is open, it does not resolve at all and leaves the loading state hanging.

Is there a way to handle this scenario and getting a response from this function?

Hi @alexandro.mancera

I am sorry about the delayed reply to your inquiry!

From what I understand, the issue you are describing seems to be a common pain point when using webAuth since the action of locking the device would interrupt the communication channels between the system browser and your app. The authorize method which is expected to return a Promise, locking the device would cause the OS itself to basically interrupt or “forget” about it, leaving it in a pending state indefinitely.

As far as my knowledge goes, you should be able to use AppState in order to listen for when the app returns into an active state.

The logic behind would look something like this:

//Performing the login
const credentials = await auth0.webAuth.authorize({ scope: 'openid profile email' });

useEffect(() => {
    const subscription = AppState.addEventListener('change', (nextAppState) => {
      if (nextAppState === 'active' && isAuthenticating.current) {
        // App is active - authentication still in process.
        
        // Allowthe SDK a moment to process a potential success redirect
        // If it was a success, the 'await' above will finish and clear the flag.
        // If it was a 'lock/unlock' zombie, this timer will hit and clear the UI.
        setTimeout(() => {
          if (isAuthenticating.current) {
            console.log('Safety valve: Resetting stuck loading state.');
            setIsLoading(false);
            isAuthenticating.current = false;
          }
        }, 1000); 
      }
    });

Let me know if the information above was useful regarding the matter or if you have any other questions/issue!

Kind Regards,
Nik

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.