[英]Problem in getting User Profile Information from Firebase
I am facing a problem in getting the User Profile Information from Firebase.我在从 Firebase 获取用户配置文件信息时遇到问题。
Actually, I created a function which will get the user information from Firebase.实际上,我创建了一个从 Firebase 获取用户信息的函数。 The codes for the same is shown below-
相同的代码如下所示 -
function showProfileInformation(){
var user = firebase.auth().currentUser;
if (user != null) {
user.providerData.forEach(function (profile) {
var storeTheEmail= profile.email;
console.log(storeTheEmail);
});
}
}
When I call this function from body tag of the HTML as-当我从 HTML 的body 标签调用这个函数时,
<body onload="showProfileInformation()">
Then, the function is called but It is not retrieving the User Information然后,该函数被调用,但它没有检索用户信息
But when I call this Function through a button, as-但是当我通过一个按钮调用这个函数时,作为-
<button onclick="showProfileInformation()">Click Me</button>
Then it works properly.然后它可以正常工作。
What might be the problem?可能是什么问题?
You can solve it by delaying the execution of your function-您可以通过延迟执行您的功能来解决它-
<body id="bodyTag" onload="changeTheStatusWithDelay()">
<script>
// IT IS THE FUNCTION WHICH WILL BE CALLED FROM BODY TAG
function changeTheStatusWithDelay(){
// IT WILL DELAY YOUR EXECUTION OF THE FUNCTION
setTimeout(changeItNow, 2000);
}
//NOW YOU CAN PASTE ALL OF YOUR CODE HERE
function changeItNow(){
var database = firebase.database();
var user = firebase.auth().currentUser;
if (user != null) {
user.providerData.forEach(function (profile) {
var storeTheEmail= profile.email;
console.log(storeTheEmail);
});
}
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.