Reactjs 如何在firebase实时数据库和身份验证上生成相同的用户id

Reactjs 如何在firebase实时数据库和身份验证上生成相同的用户id,reactjs,firebase,react-native,firebase-realtime-database,firebase-authentication,Reactjs,Firebase,React Native,Firebase Realtime Database,Firebase Authentication,我正在尝试在React Native中创建登录注册屏幕,并希望获取使用signup/login注册的用户的详细信息。到目前为止,详细信息都存储在其中,但数据库和身份验证中的用户id在firebase中是不同的,以便获取它们。如果两个表中的用户id不同,如何从firebase获取用户详细信息 userLogin = (email, pass) => { firebase.auth().signInWithEmailAndPassword(email, pass)

我正在尝试在React Native中创建登录注册屏幕,并希望获取使用signup/login注册的用户的详细信息。到目前为止,详细信息都存储在其中,但数据库和身份验证中的用户id在firebase中是不同的,以便获取它们。如果两个表中的用户id不同,如何从firebase获取用户详细信息

userLogin = (email, pass) => {
        firebase.auth().signInWithEmailAndPassword(email, pass)
        .then(() => {
            navigation.navigate("HomeScreen")
        })
        .catch(err => {
            Alert.alert(err.message)
        })
    }

使用以下代码登录时:

firebase.auth().signInWithEmailAndPassword(email, password)
  .then((res) => {
    console.log(res.user.uid);
  })
  .catch((error) => {
    var errorCode = error.code;
    var errorMessage = error.message;
  });
在这里,您可以从firebase身份验证中获取
uid
,然后可以在firebase实时数据库中使用:

var database = firebase.database();
 database.ref('users/' + userId).set({
    username: name,
    email: email,
    profile_picture : imageUrl
  });

使用以下代码登录时:

firebase.auth().signInWithEmailAndPassword(email, password)
  .then((res) => {
    console.log(res.user.uid);
  })
  .catch((error) => {
    var errorCode = error.code;
    var errorMessage = error.message;
  });
在这里,您可以从firebase身份验证中获取
uid
,然后可以在firebase实时数据库中使用:

var database = firebase.database();
 database.ref('users/' + userId).set({
    username: name,
    email: email,
    profile_picture : imageUrl
  });

我是一个新来的本地人,你建议的那个没用,或者可能是我做错了。你能再发一条吗,我已经用我的登录代码更新了我的问题。什么不起作用,你做了
console.log(res.user.uid)吗?哦,对不起,我使用了userId。不过,当我使用res.user.uid时,它确实起了作用,谢谢。我对React Native还不熟悉,您建议的那个没起作用,或者可能是我做错了。你能再发一条吗,我已经用我的登录代码更新了我的问题。什么不起作用,你做了
console.log(res.user.uid)吗?哦,对不起,我使用了userId。不过,当我使用res.user.uid时,它确实起了作用,谢谢。