首页 > 解决方案 > 防止谷歌凭据保存在android中

问题描述

我正在使用Firebase Google Authentication服务。身份验证工作正常,但问题是当我使用 google auth 登录时,凭据会被保存。因此,每次注销后,我都无法选择登录电子邮件。它直接让我登录到应用程序。因此,当我想使用另一个 Gmail 帐户登录时,这对我来说是个问题。

实现凭证页面的代码。

google_sign_in_btn.setOnClickListener {
            signIn()
        }
  ...


private fun signIn() {
    val signInIntent = mGoogleSignInClient.signInIntent
    startActivityForResult(signInIntent, 234)
}


override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (requestCode == 234)
        {
            val task = GoogleSignIn.getSignedInAccountFromIntent(data)
            try
            {
                val account = task.getResult(ApiException::class.java)
                if (account != null) {
                    firebaseAuthWithGoogle(account)
                }
            }
            catch (e:ApiException) {
            }
        }
    }

标签: androidfirebasekotlinfirebase-authenticationgoogle-authentication

解决方案


您面临的问题是您没有从 Google 提供商中注销用户。仅从 Firebase 退出是不够的。如果您希望每次都弹出该弹出窗口,以便选择要使用的电子邮件帐户,请从 Google 和 Firebase 中退出:

googleSignInClient.signOut().addOnCompleteListener { /* ... /* }
FirebaseAuth.getInstance().signOut()

推荐阅读