Auth0 on React Native iOS App

I have an iOS app which I have integrated with Auth0. When I cancel login on Auth0 login page, the app stops working. Is there any step I am missing in the integration which will again bring back login page even on cancellation?

Hi @owais,

Welcome to the Auth0 Community!

I’m having trouble understanding the scenario. Could you please provide some more info, an example (screencast), or detailed steps to reproduce the issue?

Hello Dan
See the attached screenshot. When I hit cancel button, app throws an error typically for 24 hours. Not able to understand the behaviour. If I close and reopen the app, login should again happen. It keeps on throwing an error message.


Thanks for the added info. What button are you pressing that causes this? Can you share that please?

When we press cancel on Auth0 Sign in prompt, it goes in error mode. See the second screenshot above.

I see, thank for clarifying.

Do you have a line of code throwing that alert? It looks like a custom error message from your application.

How are you handling the canceled login in your app? Code snippets are helpful.

Hello Dan,
We are not handling this in code. Do you have a sample code or point me to documentation?

Could you please post a code snippet of the line that is throwing this error?

const login = async () => {
        try {
          const credentials = await auth0.webAuth.authorize({
            scope: 'openid email profile',
          });
      
          await SInfo.setItem('idToken', credentials.idToken, {});
          const user_data = await getUserData(credentials.idToken);
          setLoggedIn(true);
          setUserData(user_data);
        } catch (error) {
          console.log(error);
          // Check if the error is due to user cancellation
          if (error.code === 'auth0.webAuth.authorize.cancelled') {
            // Handle cancellation (e.g., show a message to the user)
            console.log('User cancelled the login process');
          } else {
            // Handle other errors
            alert('Error logging in - loginfunc');
            console.log('Login Function:' + error);
            // Redirect to the app's main screen
            // props.navigation.navigate('SplashScreen');
            // Clear session and delete token in case of an error
            await auth0.webAuth.clearSession({});
            await SInfo.deleteItem('idToken', {});
          }
        }
      };

Hello Dan,
I made some update to the function. Still doesn’t work:

const login = async () => {
    try {
        alert('Initiating logging in');
        // logout();
        const credentials = await auth0.webAuth.authorize({
            scope: 'openid email profile',
        });

        // Check if credentials exist
        if (!credentials) {
            // User cancelled the authentication process
            console.warn('User cancelled authentication');
            return; // Optionally, you can handle this case as needed
        }

        alert('Fetching logging in');
        await SInfo.setItem('idToken', credentials.idToken, {});
        const user_data = await getUserData(credentials.idToken);
        setLoggedIn(true);
        setUserData(user_data);
        alert('Completed logging in');
    } catch (error) {
      alert('Error logging in');  
      console.error('Authentication error:', error);
        // Handle the error appropriately (e.g., show an error message)
    }
};

I have introduced alerts to notify where it is failing. It is not proceeding beyond
alert(‘Fetching logging in’);

Also when I build the app in Xcode and run it in iPhone, as soon as I open the app it starts error logging in message. Something is messed up in this function.

Thanks for sharing.

What does the error message say?

I am not able to find any error in Xcode console. Anywhere specific you want me look for to identify the error?

From what I can tell, this alert is the one being displayed:

alert('Error logging in');

And in the same catch closure, there is an error object.

I changed my code to this page Auth0 React Native SDK Quickstarts: Login.

And I am getting following error on logout:
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<SFAuthenticationViewController: 0x10700dc00>) error in react native iOS app

Did you ever print the original error? This new one looks like a conflict in how the UI elements are being loaded, but it doesn’t appear to be coming from Auth0.