![](/img/trans.png)
[英]How should a user be redirected to another page after successful login in Vue 3
[英]How to use firebase authentication user data after the page is redirected to another page (dashboard)?
使用Firebase身份验证使用电子邮件和密码登录后,页面被重定向到用户仪表板,页面重定向后,我如何在该仪表板中使用用户凭据。
firebase.auth().signInWithEmailAndPassword(this.email, this.password)
.then(cred => {
console.log(cred.user);
window.location='dashboard.html'
}).catch(err => {
this.feedback=err.message;
})
使用给定的命令将数据存储在Cloud Firestore中:
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令牌,因此在仪表板页面中具有以上代码也意味着用户可以安全地将该仪表板页面的URL添加为书签,并在以后返回。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.