-1

I'm trying to get current signed user's image and name from the firebase realtime database in which his data was stored when he signup. I want to put these two items in the drawer header. enter image description hereYou can see the attached screenshots.

Here is the current user enter image description here

here is the data of the current user. I want to get that data on the basis of current user signed in

enter image description here

3 Answers 3

4

you can get the currentUser.uid if you are loggedin with firebase.

try my code,

firebase
      .database()
      .ref('Users/' + firebase.auth().currentUser.uid)
      .once('value')
      .then(snapshot => {
        console.log(snapshot.val()) <--will print the user data
      });

hope this works for you.

Sign up to request clarification or add additional context in comments.

Comments

1

Try making an async function so you can retrieve data from any user with just the UID like this:

export async function getUserByUID(UID) {
  return await firebase.database().ref(`Users/${UID}`).once('value');
}

Later you can simply pass the UID and get any users' data:

const getMyData = async () => {
  let UID = firebase.auth().currentUser.uid;
  let userData = await getUserDataByUID(UID);
  // this will be null if there's no user data
  // all users' data will be in userData for example:
  console.log(userData.image) // will log the image url you saved.
}

BTW don't forget your firebase database rules! The last thing you want is other seeing those passwords!!

Comments

0

check the following code

 firebase.database().ref(`Users/${firebase.auth().currentUser.uid}`).once('value', function (snapshot) {
        console.log(snapshot.val())
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.