Reputation: 86
I am trying to create login signup screens in React Native and want to fetch the details of user registered using signup/login. So far the details are getting stored in them but the user id in database and authentication is different in firebase in order to fetch them. How to fetch the user details from firebase if user id will be different in both the tables.
userLogin = (email, pass) => {
firebase.auth().signInWithEmailAndPassword(email, pass)
.then(() => {
navigation.navigate("HomeScreen")
})
.catch(err => {
Alert.alert(err.message)
})
}
Upvotes: 0
Views: 808
Reputation: 80914
When you login using the following the code:
firebase.auth().signInWithEmailAndPassword(email, password)
.then((res) => {
console.log(res.user.uid);
})
.catch((error) => {
var errorCode = error.code;
var errorMessage = error.message;
});
Here you can get the uid
from firebase authentication, which you can then use in firebase realtime database:
var database = firebase.database();
database.ref('users/' + userId).set({
username: name,
email: email,
profile_picture : imageUrl
});
Upvotes: 3