'getAuth().onAuthStateChanged not called, async not resolving in capacitor?
This may be a firebase issue or a capacitor issue with promises - I'm building an iOS app with capacitor and NextJS.
I'm finding async functions (at least to firebase) aren't completing even when they're successful, for example a call to 'createUserWithEmailAndPassword' from firebase succeeds (the account is created on firebase) however it doesn't resolve,
onClick={() => { console.log("begin sign up"); setLoading(true) try { createUserWithEmailAndPassword(getAuth(), email, password).then(data => {
                }).catch(e => {
                    setError(JSON.stringify(e))
                }).finally(() => setLoading(false))
            }
            catch (e) {
                console.log(JSON.stringify(e));
                setLoading(false);
            }
        }}
This function works fine in a standard nextjs environment so the logic has been validated, making me think it might have to do with async functions in capicitor.
I also seperately have a hook into the callback: getAuth().onAuthStateChanged and getAuth().onIdTokenChanged which are never called.
Update: I used proxyman to inspect network traffic - the sign in request is suceeding with a valid payload returned however on the capacitor side it's not resolving (i.e. calling 'then' or setting a user on the firebase auth).
Solution 1:[1]
You seem to have the following problem: https://github.com/robingenz/capacitor-firebase-authentication/issues/78
This was the solution (Source: harryherskowitz.com):
function whichAuth() {
  let auth
  if (Capacitor.isNativePlatform()) {
    auth = initializeAuth(app, {
      persistence: indexedDBLocalPersistence
    })
  } else {
    auth = getAuth()
  }
  return auth
}
export const auth = whichAuth()
You must set indexedDBLocalPersistence as persistence when you initialize auth.
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 | RGe | 
