Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to speed up the Firebase authentication process

I have an Android app with Firebase-backed storage. For authentication, I'm using a Google sign-in, followed by Firebase's signInWithCredential().

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 ---
like image 378
EboMike Avatar asked Oct 22 '17 20:10

EboMike


People also ask

Is Firebase Auth slow?

Because it IS slow and for this reason you should avoid using it. Build your own authentication, like I did and you'll discover how significantly faster it is.

How long is Firebase authentication?

Firebase Authentication is based on two tokens: a refresh token that never expires, and an ID token that expires an hour after it's minted and is auto-refreshed by the SDKs.

Does Firebase automatically refresh token?

Every time a user signs in, the user credentials are sent to the Firebase Authentication backend and exchanged for a Firebase ID token (a JWT) and refresh token. Firebase ID tokens are short lived and last for an hour; the refresh token can be used to retrieve new ID tokens.

How much OTP is free in Firebase?

Limitations of OTP in firebase: The free plan of firebase has Ten Thousand Verification per month, but if you exceed this limit, you need to pay for that.


1 Answers

Authentication time depends on Network speed and Firebase Servers.

There is no need to login the user every time they launch your application because

FirebaseAuth.getInstance().getCurrentUser()

will not be null unless you explicitly sign out the user with

FirebaseAuth.getInstance().signOut()

In case you want to update the Auth instance for newer changes you can call reload on profile which will be faster than re-login.

Why you might need to reload the profile?

Let's say the user was logged in and you blocked that account from Firebase Dashboard. In this case, user will still be logged in. You can reload the profile instead of re-login to revoke user access.

like image 92
coder3101 Avatar answered Oct 24 '22 14:10

coder3101