'Firebase auth gets stuck on iOS login without error

I've set up the most basic implementation of firebase auth login with email and password.

firebase.auth().signInWithEmailAndPassword(email, password).then(() => {

    console.log('Logged in')
    window.location.href = "./home.html"

}).catch(function (error) {

    console.log(error)

});

For some reason, on iOS, the login process sometimes gets stuck waiting for the promise of signInWithEmailAndPassword() to resolve. I don't get any error message.

The only way to re-enable the login mechanism is to clear the browser cache.

Is this a known problem? I've been experiencing this problem for my last two apps over the last year.

Edit: After further trial and error I found out that the problem usually happens after being logged in, letting the iPhone go to sleep, waking it back up, and then logging out. Then the same problem also happens for the signOut() function.



Solution 1:[1]

Turns out the problem had to do with the domain not being whitelisted in my project settings. The reason why I didn't pay attention to the console alert about oAuth was that it did work most of the times, even with it showing. So I thought it didn't have any effect on it.

The answer was suggested in this thread

Solution 2:[2]

I was having the same issue, but it was even more consistent when I moved to version 9 of the firebase sdk and my app was running in an Ionic-Capacitor native app on iOS. The solution was to add "localhost" to Firebase > Authentication > Sign-in method > Authorize domains (NOTE: if you use localhost make sure you have sufficient security db rules to prevent someone from adding bad data and you may not want to use this in production).

Then I needed to use intializeAuth() when running in hybrid (native app) mode. My app is also a pwa and getAuth(app) makes assumptions that its loading in a browser environment which causes this problem.

const firebaseApp = initializeApp(FirebaseConfig);
this.firebaseAuth = isPlatform('hybrid') ? 
    initializeAuth(firebaseApp, {persistence: indexedDBLocalPersistence}) :
    this.firebaseAuth = getAuth(firebaseApp);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Max
Solution 2