Edit - a key thing that I didn't realise at when writing is that this happens when you use Google as an authentication provider
I've set up my Android app so that I can log in and out using Firebase Authentication.
But when I log in, I'm not presented with any options that would let me log in as a different use - it just auto-logs me into the same account I logged into last time.
How can I switch the user account I use to log in?
Code from my main Activity:
// Authentication stuff
private lateinit var auth: FirebaseAuth
private val btnSignIn: Button by lazy { findViewById(R.id.btnSignIn) }
val signInLauncher = registerForActivityResult(FirebaseAuthUIActivityResultContract()) { res ->
if (res.resultCode == RESULT_OK) {
refreshSigninInfo()
} else {
showToast("Sign in failed - do you have internet connection?")
}
}
private fun refreshSigninInfo() { // Called in onCreate()
auth = FirebaseAuth.getInstance()
auth.currentUser?.let {
btnSignIn.text = "Signed in as ${it.email}\nTap to sign out"
btnSignIn.setOnClickListener {
auth.signOut()
refreshSigninInfo()
}
} ?: run {
btnSignIn.text = "Tap to sign in"
btnSignIn.setOnClickListener {
val signInIntent = AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(arrayListOf(AuthUI.IdpConfig.EmailBuilder().build(), AuthUI.IdpConfig.GoogleBuilder().build()))
.build()
signInLauncher.launch(signInIntent)
// HERE, upon launch, this this should give the user
// the option of selecting a different sign-in account
// but instead, if the user has previously signed in,
// it just directly signs the user in without the option
// to change account
}
}
}