繁体   English   中英

Firebase 身份验证 - 在控制台中创建用户但进度条不会停止旋转并且任务未完成?

[英]Firebase authentication - users being created in console but progress bar won't stop spinning and the task is not completed?

所以我正在处理移动应用程序的注册表,当用户填写注册表并提交时,进度条会出现并无限旋转,令人惊讶的是没有打印任何消息。 尽管如此,用户确实出现在 Firebase 控制台中,这让我感到不可思议。

代码:

    progressBar.setVisibility(View.VISIBLE);
            mAuth.createUserWithEmailAndPassword(email, password)
                    .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if(task.isSuccessful()) {
                                User user = new User(fullName, rating, email);
    
                                System.out.println(user.fullName);
    
                                FirebaseDatabase.getInstance().getReference("Users")
                                        .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
                                        .setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
                                    @Override
                                    public void onComplete(@NonNull Task<Void> task) {
                                        if(task.isSuccessful()) {
                                            Toast.makeText(RegisterUser.this, "User has been registered succesfully!", Toast.LENGTH_LONG).show();
System.out.println("Success!");
                                            progressBar.setVisibility(View.GONE);
                                        }else {
                                            Toast.makeText(RegisterUser.this, "Failed to register! 
 Try again!", Toast.LENGTH_LONG).show();
System.out.println("Failure!");
                                            progressBar.setVisibility(View.GONE);
                                        }
                                    }
                                });
                            }
                        }
                    });

谢谢!

    FirebaseDatabase.getInstance().getReference("Users")
                                            .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
                                            .setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
                                        @Override
                                        public void onComplete(@NonNull Task<Void> task) {
                                            if(task.isSuccessful()) {
                                                Toast.makeText(RegisterUser.this, "User has been registered succesfully!", Toast.LENGTH_LONG).show();
    System.out.println("Success!");
                                                progressBar.setVisibility(View.GONE);
                                            }else {
                                                Toast.makeText(RegisterUser.this, "Failed to register! 
     Try again!", Toast.LENGTH_LONG).show();
    System.out.println("Failure!");
                                                progressBar.setVisibility(View.GONE);
                                            }
                                        }
                                    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
 progressBar.setVisibility(View.GONE)
        }
    });

添加此失败侦听器。 所以你可以得到失败的消息或做你想做的事。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM