使用 Firebase 身份验证使用电子邮件和密码登录后,页面将重定向到用户信息中心,在页面重定向后,如何使用该信息中心中的用户信任。
firebase.auth().signInWithEmailAndPassword(this.email, this.password)
.then(cred => {
console.log(cred.user);
window.location='dashboard.html'
}).catch(err => {
this.feedback=err.message;
})
使用给定的命令将数据存储在云火存储中:-
firebase.auth().createUserWithEmailAndPassword(this.email, this.password)
.then(cred => {
return db.collection('students').doc(cred.user.uid).set({
name: this.name,
email: this.email
});
}).then(() => {
this.feedback='User registered, please login.';
window.location='login.html' ;
})
.catch(err => {
this.feedback=err.message;
});
我想在数据库中使用用户 UID 索引的存储详细信息 并将其显示在用户仪表板上
firebase.auth().onAuthStateChanged(user => {
if (user) {
console.log(user.email);
window.location= 'dashboard.html'
console.log(user.email);
this.name = user.displayName ;
this.email =user.email;
}
})
若要让用户进入新页面,请使用如下所示的onAuthStateChange
侦听器:
firebase.auth().onAuthStateChanged(function(user) { if (user) { // User is signed in. } else { // No user is signed in. } });
在else
块中,您通常会重定向回登录页面。由于 Firebase 身份验证会自动刷新其有效期较短的 ID 令牌,因此在信息中心页面中使用上述代码也意味着用户可以安全地将此信息中心页面的网址添加为书签,并在以后返回。