在FirebaseUser中的用户之间切换 - FirebaseAuth

时间:2017-04-08 11:28:13

标签: android firebase firebase-realtime-database firebase-authentication

我一直在使用Android上的管理控制面板。在哪个管理员可以添加和禁用用户。 假设admin uid是I4YnygVk2eaCLEJbCiCLiWlo13as

mAuth.createUserWithEmailAndPassword(emailid, password)
.addOnCompleteListener(UserManagement.this, new OnCompleteListener<AuthResult>() {
    @Override
    public void onComplete(@NonNull Task<AuthResult> task) {
        Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful()+"uid"+mAuth.getCurrentUser().getUid());
        //here the Uid is changed to the new registered user i.e RlhiQxMibWYA1NaqlN9JdFZ8ocK2.

        AuthCredential credential = EmailAuthProvider
            .getCredential("a@a.com", "123456");

            firebaseUser.reauthenticate(credential)
                .addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                        public void onComplete(@NonNull Task<Void> task) {

        //here what i need is getUid() should print the admin's uid(I4YnygVk2eaCLEJbCiCLiWlo13as), and not the newly created uid.
                            Log.d(TAG, "User re-authenticated."+firebaseUser.getUid())                                    database.getReference("users/"+mAuth.getCurrentUser().getUid()).child("active").setValue(true);
                        }
                    });

    }        
});

1 个答案:

答案 0 :(得分:0)

当您的用户创建成功时,请调用此方法

FirebaseAuth.getInstance().signOut();

这会注销新创建的用户,然后您可以使用管理员凭据登录。