I am facing a problem in getting the User Profile Information from Firebase.
Actually, I created a function which will get the user information from 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-
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.