Google Firebase在Android应用中注销并忘记用户 [英] Google Firebase sign out and forget user in Android app

查看:312
本文介绍了Google Firebase在Android应用中注销并忘记用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我调用 mFirebaseAuth.signOut(); mFirebaseUser.delete(); my FirebaseAuth.AuthStateListener()正常工作并返回 null 作为 FirebaseUser 实例在 onAuthStateChanged 中,我刷新UI并显示使用Google登录按钮。

但是当我想再次登录时,我看不到用户弹出窗口(我的设备上有两个用户,附加了图片)。应用程序仅在首次登录时显示此弹出窗口,之后它将使用同一用户。如果我在设置屏幕上清除应用程序的数据,我将能够再次看到这个弹出窗口。



我的问题是如何在每次退出后显示弹出窗口。





更新:
我按下Sign In按钮时运行这段代码:

  GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN )
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this / * FragmentActivity * /,this / * OnConnectionFailedListener * /)
.addApi(Auth.GOOGLE_SIGN_IN_API,gso)
.build();

意图signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent,FirebaseActivity.REQUEST_SIGN_IN);

onActivityResult() GoogleSignInResult 所以我调用 startActivityForResult()

解决方案

Firebase Auth快速入门示例代码,Google提供商的注销包括这些步骤。您是否在退出时调用 Auth.GoogleSignInApi.signOut()

  private void signOut(){
// Firebase注销
mAuth.signOut();

// Google退出
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback< Status>(){
@Override
public void onResult(@NonNull Status status){
updateUI(null);
}
});
}


I have faced with the next problem:

when I call mFirebaseAuth.signOut(); or mFirebaseUser.delete(); my FirebaseAuth.AuthStateListener() works correct and returns null as FirebaseUser instance in onAuthStateChanged, i refresh UI and show "Sign in with Google" button.

But when I want to log in again, I don't see the pop-up with users (i have 2 users on my device, attached the image). The app shows this pop-up only in first sign in, after that it uses the same user. If i clear app's data on the settings screen I will be able to see this pop-up again.

My question is how to show this pop-up after every sign out.

UPDATE: I run this code when press Sign In button:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();

Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
            startActivityForResult(signInIntent, FirebaseActivity.REQUEST_SIGN_IN);

in onActivityResult() i gen an instance of GoogleSignInResult so everything i need happens after i call startActivityForResult()

解决方案

In the Firebase Auth Quickstart sample code, the sign-out for Google provider includes these steps. Are you calling Auth.GoogleSignInApi.signOut() when you sign-out?

private void signOut() {
    // Firebase sign out
    mAuth.signOut();

    // Google sign out
    Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
            new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    updateUI(null);
                }
            });
}

这篇关于Google Firebase在Android应用中注销并忘记用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆