Error: Cannot prompt to authenticate until the request has finished loading in React Native with Firebase and Expo Auth Session

I’m encountering an issue in my React Native application when trying to implement Google authentication using Firebase and Expo Auth Session. When I attempt to log in with Google, I receive the following error message:

Copy code Error: Cannot prompt to authenticate until the request has finished loading. Problem Description:

I have two main components in my application, App and LoginScreen, both of which utilize the promptAsyncGoogle function to initiate the Google authentication process.

In the App component, I’m initializing the promptAsyncGoogle function using the Google.useAuthRequest hook. This function is used to initiate Google authentication when the app starts.

In the LoginScreen component, I’m using the same promptAsyncGoogle function to initiate Google authentication when the user clicks the “Logga in med Google” button.

Issue Details:

The error occurs when I press the “Logga in med Google” button in the LoginScreen component. However, if I press the “Logga in med Google” button in the CreateAccount component first (which also uses promptAsyncGoogle), it starts working, and I can log in with Google successfully.

Here is the relevant code from my App component:

// Code from App.js  
// ...  
useEffect(() => {   
const { request, response, promptAsyncGoogle } = Google.useAuthRequest({     
useProxy: true,     
expoClientId: '',     
androidClientId: '',   
});    
// ...    
useEffect(() => {     
if (response?.type === "success") {       
// Handle successful authentication     
} else if (response?.type === "dismiss" || response?.type === "error") {      
// Handle dismissal or error     
}        
}, [response]);    // ...  }, []); 

Question:

What could be causing the “Cannot prompt to authenticate until the request has finished loading” error in the LoginScreen component?

Why does the Google authentication work in the LoginScreen component only after using it in the CreateAccount component first?

How can I ensure that the promptAsyncGoogle function in the LoginScreen component works correctly from the beginning, without requiring prior usage in another component?

Any insights, suggestions, or solutions would be greatly appreciated. Thank you!

Please provide the following:

  1. SDK Version: 48.0.18
  2. Platforms(Android/iOS/web/all): Android

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