I wanna fetch the data from firestore and show the data inside web page when user enter the email. Like press submit, then user data of the entered email will show. But the code below is not working. Can someone help me.
function shareAccess(){
var email = document.getElementById('email').value;
auth.signInWithEmailAndPassword(email, password)
.then(function() {
var user_data = {
email : email,
}
db.collection("users").get(user_data).then((querySnapshot) => {
querySnapshot.forEach((doc) => {
alert(`${doc.id} => ${doc.data()}`);
});
});
})
}
function shareAccess(){
var email = document.getElementById('email').value;
auth.signInWithEmailAndPassword(email, password)
.then(function() {
var user_data = {
email : email,
}
db.collection("users").get(email).then((querySnapshot) => {
querySnapshot.forEach((doc) => {
alert(`${doc.id} => ${doc.data()}`);
});
});
})
}
As mentioned in the Documentation :
The Firebase Admin SDK supports looking up user information with an email:
getAuth() .getUserByEmail(email) .then((userRecord) => { // See the UserRecord reference doc for the contents of userRecord. console.log(`Successfully fetched user data: ${userRecord.toJSON()}`); }) .catch((error) => { console.log('Error fetching user data:', error); });
For more information, you can refer to the Answer where a similar issue has been explained and documentation explained about two ways to retrieve data stored in Cloud Firestore.
- Call a method to get the data.
- Set a listener to receive data-change events.