使用firebase和js注册和重定向到主页时出现问题



当我注册时,我的代码会将我重定向到主页,但数据不会存储在实时数据库中。

function SignUp(){
var name = document.getElementById("fname").value;
var email = document.getElementById("email").value;
var phone = document.getElementById("phone").value;
var password = document.getElementById("password").value;
var password2 = document.getElementById("password2").value;
if(password == password2) {
auth.createUserWithEmailAndPassword(email, password).then((res) => { 
database.ref('User/'+auth.currentUser.uid).set({
name: name,
phone:phone,
password: password2,
});
}).catch((error) => {
console.log(error);
alert(error.message);
});
}
else{
alert("password didnt match");
document.querySelector('.form_container').reset();
}
window.location.href = "index.html";    
}

这将重定向到我的主页。但这些数据并没有被存储到实时数据库中。提前谢谢。

const auth = firebase.auth();
var database = firebase.database();
function SignUp(){
var name = document.getElementById("fname").value;
var email = document.getElementById("email").value;
var phone = document.getElementById("phone").value;
var password = document.getElementById("password").value;
var password2 = document.getElementById("password2").value;
if(password == password2) {
auth.createUserWithEmailAndPassword(email, password).then((res) => {
database.ref('User/'+auth.currentUser.uid).set({
email:email,
name: name,
phone:phone,
password: password2,
});
document.getElementById('success').style.display='block';
}).catch((error) => {
console.log(error);
alert(error.message);
});
}
else{
alert("password didnt match");
document.querySelector('.form_container').reset();
}
}
function success(){
window.location.href = "../index.html";
}

在注册表格中

<div class="success_container" id="success">
<div class="animate success">
<p>successfully signed up</p>
<button type="button" onclick="success()">back to site</button>
</div>
</div>

添加此代码,即可完成您的工作。感谢

相关内容

  • 没有找到相关文章

最新更新