javascript firebase.auth().currentUser = null



我创建了一个简单的登录名.js方法通过firebase.auth((使用方法signinwithemailandpassword(email,password(。 正确登录后,通过方法window.open("主页.html"(,我打开一个新页面。 在这个主页中,如果我使用window.alert(firebase.auth((.currentUser.uid(,我有错误,因为currenUser为空。 我想使用观察者

firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
var uid = user.uid;
} else {
// User is signed out.
// ...
}
});

但是这个观察者检查用户是否存在,不要给我一个检索UID用户或存储更正它的方法。

登录.js

const txtemail = document.getElementById('input_email');
const txtpassword = document.getElementById('input_password');
const btnLogin = document.getElementById('buttonLogin');
btnLogin.addEventListener('click', e => {
const email = txtemail.value;
const password = txtpassword.value;
if(email == ""){
window.alert("inserisci email!");
} else if (password == ""){
window.alert("inserisci Password");
} else {
const auth = firebase.auth();
auth.signInWithEmailAndPassword(email,password)
}
});

firebase.auth().onAuthStateChanged(function(user) {
if (user) {
firebase.database().ref("TeamLavoro").orderByChild('Email').equalTo(user.email).on("value", function(snapshot) {
if(snapshot.val() != null){
window.open("homepageteam.html", "_self");
} else {
window.open("homepage.html", "_self");
}
})
}else{
window.alert("Nessun Utente Trovato");
}
});

主页团队.js

firebase.auth().onAuthStateChanged(function (user) {
if(user){
window.alert(user.uid);
}
else{
window.alert("No USER")
}
});

一直"没有用户"。 我尝试过使用 .than 和 .catch,但相等。

最新更新