if 语句检查数据库信息,在不应该工作时工作



我正在尝试对日志活动进行错误检查,如果检测到以下问题,它将触发意图:

1(如果用户尚未注册(他使用的电子邮件未通过Firebase身份验证(,这对我来说效果很好

2( 如果用户已注册,但未向我提供任何信息进入Firebase数据库

我的问题是,由于某种原因,我用来检查数据库中信息的代码对用户有效,即使他们在附加到其 UID 的数据库中有信息。

这意味着告诉他们提供信息的意图将在他们已经提供信息时触发。

if(task.isSuccessful()){
    // Checks if user has submitted information in the Essential Information activity
    //Takes the Unique ID(if it is present if not it will tell him to sign up or invalid email) asks the firebase database if he has given information to the database
    reference.child("Users").child(UserUID).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            // User exists
            if (dataSnapshot.exists()) {
                //Displays Toast telling user that their information is saved in the database
                Toast.makeText(LogInActivity.this, "You have data in our database ", Toast.LENGTH_SHORT).show();
            }
            //User doesn't have information in the database
            else {
                // Displays Toast telling user he/she needs to sign in into the firebase database
                // User goes to UserInformationActivity to give his/her information
                Toast.makeText(LogInActivity.this, "You need to give Essential Information", Toast.LENGTH_SHORT).show();
                // 3 second delay
                final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        // Goes to UserInformationActivity
                        Intent GoToUserInformation = new Intent(LogInActivity.this, UserInformationActivity.class);
                        LogInActivity.this.startActivity(GoToUserInformation);
                    }
                }, 3000);
            }

        }
        // if the checking got cancelled, likability of that happening is small
        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}

您不想检查用户是否已登录吗?

直接来自火力基地...

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
    // User is signed in
    // check a snapshot to see if there is information....if not, error out.
} else {
    // No user is signed in
}

相关内容

最新更新