Creos Creos - 11 months ago 126
Android Question

Is FirebaseAuth # signInWithCredential result internally cached (for some period) or it performs a network trip & reauthetnicates on each invocation?

The previous version of Firebase (before google-fication) had an API

which would return non-null if there was a currently logged in user allowing us to short-circuit authentication. That was spelled out in the docs and clients were encouraged to use it for performance.

Is the new
API intended to not perform a full re-authentication if the user has recently authenticated, or clients of the library need to keep track of that themselves and only invoke when necessary? I couldn't find any details in the official docs or in the guides.

Basically, what is the contract of the method? Is it designed for use where I can invoke it multiple times and it returns immediately the successful authenticated state after a first full authentication (up to some expiry period), or does it perform a full-blown network-based authentication every single time?


If you want to know if a user is signed in, call FirebaseAuth.getCurrentUser(). It is the equivalent of Firebase.getAuth() in the 2.x SDK.

Calling FirebaseAuth.signInWithCredential() will try to sign in with the credentials you specify.

If you want to know when a user gets signed in/signed out or something changes about their state, use FirebaseAuth.addAuthStateListener().