Firebase USer注册 - 屏幕不会消失

时间:2017-11-29 04:22:36

标签: android firebase-authentication firebaseui

我尝试在我的应用中实施Firebase身份验证,当现有用户安装最新版本时,无论他们登录多少次,身份验证屏幕都不会消失。

真的很奇怪 - 在我搬到新电脑前工作得很好。

它似乎不适用于新帐户,但之前设置的现有帐户无法登录新版本的应用。

mAuthStateListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                //user is signed in
                onSignedInInialise(user.getDisplayName());

            } else {
                //user is signed out
                onSignedOutCleanup();
                startActivityForResult(
                        AuthUI.getInstance()
                                .createSignInIntentBuilder()
                                .setIsSmartLockEnabled(false)
                                .setProviders(Arrays.asList(
                                        new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
                                        new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build()))
                                .build(),
                        RC_SIGN_IN);
            }

        }
    };



@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        if (resultCode == RESULT_OK) {
            FirebaseUser user = mFirebaseAuth.getCurrentUser();
            String uid = user.getUid();
            String userName = user.getDisplayName();
            String userEmail = user.getEmail();
            Uri userProfilePic = user.getPhotoUrl();
            createUserInFirebaseHelper(uid, userName, userEmail);
            Toast.makeText(MainActivity.this, "Hello " + userName + "!", Toast.LENGTH_SHORT).show();

        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(MainActivity.this, "Sign in cancelled", Toast.LENGTH_SHORT).show();
            finish();
        }
    } else if (requestCode == GPS_PERMISSION) {

        String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        if (provider != null) {
            getLocation();
        } else {
            Toast.makeText(this, "You must enable Gps to get your location", Toast.LENGTH_SHORT).show();
        }
    }
}


@Override
protected void onResume() {
    super.onResume();
    mFirebaseAuth.addAuthStateListener(mAuthStateListener);
}



    @Override
protected void onPause() {
    super.onPause();
    if (mAuthStateListener != null) {
        mFirebaseAuth.removeAuthStateListener(mAuthStateListener);
    }
    detachDatabaseReadListener();
}

1 个答案:

答案 0 :(得分:0)

您是否已将新计算机的SHA-1添加到应用的Firebase控制台?