gpt4 book ai didi

android - Firebase 电子邮件验证未更新状态

转载 作者:搜寻专家 更新时间:2023-11-01 08:22:59 25 4
gpt4 key购买 nike

我在我的应用程序中使用 Firebase 身份验证,用户可以使用电子邮件和密码进行注册,他必须验证电子邮件。

用户收到验证邮件,但当他验证邮件并返回应用程序时,isEmailVerified() 始终为 false。所以我的应用程序仍然不允许用户使用所有功能,尽管他已经验证了他的电子邮件。

但是如果他们注销并再次登录,isEmailVerified() 会立即返回 true。但是注销用户并重新登录不是很好吗。

public class Profile extends AppCompatActivity {

FirebaseDatabase database;
DatabaseReference myRef;
TextView name;
Button logout;
FirebaseAuth auth;
String userStatus;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);

auth = FirebaseAuth.getInstance();
database = FirebaseDatabase.getInstance();
myRef = database.getReference("name");

name=findViewById(R.id.id_name);
logout=findViewById(R.id.id_logout);

logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

auth.signOut();

startActivity(new Intent(Profile.this, Login.class));
}
});

userStatus= String.valueOf(auth.getCurrentUser().isEmailVerified());

if (userStatus =="true")

{

myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {

String value = dataSnapshot.getValue(String.class);
name.setText("Hello my name is: "+value);
Log.d("ashu", "Value is: " + value);
}

@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.d("ashu", "Failed to read value.", error.toException());
}
});
}

else {
Toast.makeText(Profile.this,"Verify your email ", Toast.LENGTH_SHORT).show();
name.setText("Verify your email");

}}}

最佳答案

这是我经过一些逻辑后的回答

userStatus = String.valueOf(auth.getCurrentUser().isEmailVerified());

// user has not verified the email
Toast.makeText(Profile.this,"Verify your email ", Toast.LENGTH_SHORT).show();
name.setText("Verify your email");

auth.getCurrentUser().reload().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {

if (userStatus =="true")

{
//if they have verified the email
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// retrieving the value of current user

String value = dataSnapshot.getValue(String.class);
name.setText("Hello my name is: "+value);
}

@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.d("ashu", "Failed to read value.", error.toException());
}
});



}

else {

name.setText("Verify your mail");
}

}
});

}

关于android - Firebase 电子邮件验证未更新状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48530554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com