I'm building a single activity Android app in an attempt to follow Google's recommendations. I'm using FirebaseAuth UI for authentication which apparently uses 'Smart Lock for Passwords' to save the credentials into your google account. My sign out function looks like this:
private fun signOutUser(){
AuthUI.getInstance()
.signOut(this)
.addOnCompleteListener {
Timber.i("Sign out completed")
}
sharedViewModel.setUser(null)
}
However, once the sign out finishes, the UI immediately starts the user sign-in process, which with Smart Lock for Passwords means that a dialog pops up. This stops users from being able to pick another account. In the github account for FirebaseAuth UI, Google mentions this issue saying:
"Smart Lock for Passwords must be instructed to disable automatic sign-in, in order to prevent an automatic sign-in loop that prevents the user from switching accounts."
Their suggested code is:
public void onClick(View v) {
if (v.getId() == R.id.sign_out) {
AuthUI.getInstance()
.signOut(this)
.addOnCompleteListener(new OnCompleteListener<Void>() {
public void onComplete(@NonNull Task<Void> task) {
// user is now signed out
startActivity(new Intent(MyActivity.this, SignInActivity.class));
finish();
}
});
}
}
But since I have only one activity I cannot do a startActivity.
So my question is how can I prevent Smart Lock for Passwords from attempting to re-login after a user signs out?
Here is the rest of my auth code if it's relevant:
override fun onStart() {
super.onStart()
// Enable Auth listener
startAuthListener()
// If user is not logged in, start the login process
if(!sharedViewModel.isUserAuthenticated()){
startLoginProcess()
}
}
private fun initializeAuthListener() {
mAuthStateListener = FirebaseAuth.AuthStateListener { firebaseAuth ->
if (null != firebaseAuth.currentUser) {
// User is authenticated
// user = firebaseAuth.currentUser
sharedViewModel.setUser(firebaseAuth.currentUser)
//refresh all data by calling getAllCollections, getAllPois
sharedViewModel.refreshLocalCacheData()
} else {
// User is not signed in so kick off FirebaseUI login
startLoginProcess()
}
}
}
private fun startAuthListener(){
authService.addAuthStateListener(mAuthStateListener)
}
private fun startLoginProcess(){
val providers = Arrays.asList(
AuthUI.IdpConfig.EmailBuilder().build(),
AuthUI.IdpConfig.GoogleBuilder().build())
// Create and launch sign-in intent
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.build(),
RC_SIGN_IN)
}