简体   繁体   English

页面重定向到另一个页面(仪表板)后如何使用Firebase身份验证用户数据?

[英]How to use firebase authentication user data after the page is redirected to another page (dashboard)?

after sign in with email and password using firebase authentication , the page is redirected to user dashboard , how can i use the user credntials in that dashboard after the page is redirected. 使用Firebase身份验证使用电子邮件和密码登录后,页面被重定向到用户仪表板,页面重定向后,我如何在该仪表板中使用用户凭据。

firebase.auth().signInWithEmailAndPassword(this.email, this.password)
                      .then(cred => {
                          console.log(cred.user);

                          window.location='dashboard.html'
                         }).catch(err => {
                        this.feedback=err.message;
                      })

the data is stored in cloud firestore using the given command :- 使用给定的命令将数据存储在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;
                        });

i want to use the store details on the index of user uid in the database and display it on the user dashboard 我想使用数据库中用户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;
                      }

                  })

To get the user on the new page, use an onAuthStateChange listener as shown here : 要获得新的页面上的用户,使用onAuthStateChange听众如图所示在这里

 firebase.auth().onAuthStateChanged(function(user) { if (user) { // User is signed in. } else { // No user is signed in. } }); 

In the else block, you'd typically redirect back to the login page. else块中,通常将您重定向回登录页面。 Since Firebase Authentication automatically refreshes its short-lived ID tokens, having the above code in the dashboard page also means that the user can safely bookmark this dashboard page's URL and return to it later. 由于Firebase身份验证会自动刷新其短暂的ID令牌,因此在仪表板页面中具有以上代码也意味着用户可以安全地将该仪表板页面的URL添加为书签,并在以后返回。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Vue 3成功登录后如何将用户重定向到另一个页面 - How should a user be redirected to another page after successful login in Vue 3 认证后,firebase不会将用户重定向到另一个页面 - after authentication firebase is not re-directing the user to another page Firebase 身份验证,如何检测页面重定向结果(或重定向到特定 url)? - Firebase Authentication, how to detect page is redirected result (or redirect to specific url)? FireBase 用户认证重定向到另一个页面 - FireBase user authentication redirect to another page 成功插入数据后如何关闭此模式? 并且页面不应该被重定向到另一个页面 - How can i close this modal after the data is successfully inserted? and the page should not be redirected to another page 页面重定向到另一个页面后输入凭据 - enter credentials after the page is redirected to another page firebase 登录后登录页面未重定向到用户仪表板 - Log-in page not redirecting to user dashboard after firebase log-in 检查用户是否从另一个页面重定向 - Check if user is redirected from another page 提交表单后从另一个页面(如确认页面)重定向后,如何将值保留在表单中 - How to keep the values in a form after getting redirected from another page(like a confirmation page) after submitting the form Javascript Firebase 身份验证和 Firestore:保存用户数据前的页面重定向 - Javascript Firebase Authentication and Firestore: Page Redirects Before Saving User Data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM