Home:ALL Converter>How to get data from firebase by using uid

How to get data from firebase by using uid

Ask Time:2019-01-25T13:33:23         Author:Ali Alsaggaf

Json Formatter

In my app I want the user name to be displayed after user logins for that i have used the Uid but I am not recieving data from firebase

Using RN>57.8

this is my code:

componentDidMount(){

firebase.database()
   .ref('users/'+this.state.uid)
    .on('value',(snapshot)=>{
    const name1 = snapshot.val().name;
    alert(name1)
})
}

and

componentDidMount(){

firebase.database()
   .ref(`users/${this.state.uid}`)
    .on('value',(snapshot)=>{
    const name1 = snapshot.val().name;
    alert(name1)
})
}

I want to show alert message with the name of the user but it is not working whereas if i write the path directly as shown below i am able to get the alert

Example:

.ref('users/ALM5456N3NNN35HFR56L')

Author:Ali Alsaggaf,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/54359463/how-to-get-data-from-firebase-by-using-uid
yy