I have an Android app with Firebase-backed storage. For authentication, I’m using a Google sign-in, followed by Firebase’s
This is sometimes reasonably fast, some other times very slow (2 seconds for the Google sign-in, 6 seconds for Firebase, sometimes longer). This is not acceptable from a UX point of view, especially since this happens every single time the user starts the app.
Is there anything I can do to speed things up?
In a nutshell, with all async handling removed:
result = Auth.GoogleSignInApi.silentSignIn(googleApiClient).get(); // --- That can take over two seconds --- GoogleSignInAccount acct = result.getSignInAccount(); AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); authTask = auth.signInWithCredential(credential); // --- This can take over six seconds ---
Authentication time completely depends upon Network speed and Firebase Back end response time.
Also Why do you relogin the user every time app launches.
FirebaseAuth.getInstance().getCurrentUser() will not be null unless you explicitly sign out the user with FirebaseAuth.getInstance().signOut()
What I mean is that. You should not re login the user every time user opens/launches your app instead use saved Auth instance.
In case you want to update the Auth instance for newer changes let’s say user was logged in and then due to some reasons you block that account. In that case user will still be logged in and use your services. To avoid this you can call reload the profile which will be faster than re login.