Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase onAuthStateChanged callback takes 20+ seconds sometimes

We've been using Firebase on our applications after moving away from our own NodeJS backend running express and during this transition we've noticed one major drawback. The amount of time it takes for the initial auth state to be received by the client.

When my application is opened I immediately register the onAuthStateChanged callback to start listening for changes in authentication state, that way I can route the user to either their personal hub or the authentication screen.

The problem is that while sometimes this only takes a few milliseconds, at other times (Independant of internet connection) it takes anywhere from 20+ seconds, causing an extremely poor user experience.

We're using the Firebase WEB API on a UIWebView component.

I've tested this on 3G, 4G, LTE and Wifi and it's completely random. Sometimes it loads like lightning. Sometimes it's so slow that I question the reliability of the service.

Some may argue that this is due to the user data we have to download, but the 20-30 seconds that we're waiting is before we even attempt to pull data from the server. This is just to get the initial authorization state. We're only using email providers.

Does anyone know what we could do to improve this? On average the onAuthStateChanged callback is defined 562ms after the applications execution. After this sometimes it can take 20-200ms (Average latency) and sometimes it takes 20000ms+

like image 389
Hobbyist Avatar asked Aug 30 '16 09:08

Hobbyist


1 Answers

I was able to fix this issue by adding my domain to the 'OAuth redirect domains' section in the Firebase Console > Authentication > Sign-in Method.

I had added my Firebase-provided domain but forgot to add my custom domain after I set that up.

like image 151
Kaiden Avatar answered Oct 14 '22 15:10

Kaiden