gpt4 book ai didi

javascript - Firebase 身份验证返回空语句

转载 作者:行者123 更新时间:2023-12-05 07:46:38 25 4
gpt4 key购买 nike

当 firebase-authentication 在成功创建用户注册期间返回 null 语句时,我如何设法在条件下执行语句..

firebase.auth().createUserWithEmailAndPassword(email, pass).catch(function(error) {

var errorCode = error.code;
var errorMessage = error.message;

if(errorCode == "auth/email-already-in-use"){ //condition working
alert(errorMessage);
}
else if(errorCode == null){ //this condition not working
alert("Registration Successfully");
}
else{ //condition working
alert("Weak Password");
}

});

最佳答案

如果你开始新的事件,你必须检查谁是当前用户,如果用户可用,你可以像这样开始第二个事件

 auth = FirebaseAuth.getInstance(); // Get Firebase auth instance

if (auth.getCurrentUser() != null) {
startActivity(new Intent(Login_Activity.this, SecondActivity.class));
finish();
}

如果有任何用户不可用,您必须根据需要将用户重定向到登录事件或用户创建事件

authListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user == null) {

// user auth state is changed - user is null
// launch login activity

startActivity(new Intent(secondActivity.this, Login_Activity.class));
finish();
}
}
};

关于javascript - Firebase 身份验证返回空语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40521080/

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