firebase/snippets-web

How do I read all the users , namely , output the email addresses of these users from the firebase database??

iWyse opened this issue · 5 comments

iWyse commented

Pls help

iWyse commented

function getUsersEmail() {
const dbRef = ref(getDatabase());
// const token = credential.accessToken;
get(child(dbRef, 'users/' THERE???? )).then((snapshot) => {
if (snapshot.exists()) {
console.table(snapshot.val());
} else {
console.log("No data available");
}
}).catch((error) => {
console.error(error);
});
}
getUsersEmail()

iWyse commented

I was able to output the database to the console, but how do I output the email addresses?

Hey @iWyse
We need more details to help you. How are you storing the email addresses into the database? Do you have a sample database structure that you can share?

iWyse commented

Solved the problem, thanks

function getUsersEmail() {
const dbRef = ref(getDatabase());
get(child(dbRef, users/)).then((snapshot) => {
snapshot.forEach((child) => {
child.val().email;
});
});
}
getUsersEmail();

I'm glad you solved it!