Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Firebase身份验证获取用户id?_Firebase_React Native_Firebase Authentication - Fatal编程技术网

如何从Firebase身份验证获取用户id?

如何从Firebase身份验证获取用户id?,firebase,react-native,firebase-authentication,Firebase,React Native,Firebase Authentication,如何获取用户ID?在创建用户ID之后,我正在创建该用户 通过使用createUserWithEmailAndPassword函数 firebase.auth().createUserWithEmailAndPassword(email,password) .then(resp => handleUserCreated(resp.uid, name...)) 在handleUserCreated函数中,我试图将该用户插入到数据库中,问题是它给我的ID=未定义 const handleUse

如何获取用户ID?在创建用户ID之后,我正在创建该用户 通过使用createUserWithEmailAndPassword函数

firebase.auth().createUserWithEmailAndPassword(email,password)
.then(resp => handleUserCreated(resp.uid, name...))
在handleUserCreated函数中,我试图将该用户插入到数据库中,问题是它给我的ID=未定义

const handleUserCreated  = (userId, name ...) =>
firebase.database().ref(`profles/${userId}`)
数据库中的我的规则

  {
      "rules": {
        ".read": "auth != null",
        ".write": "auth != null"
      }
    }

你能帮我解决这个未定义ID的问题吗?

试试下面的解决方案,效果很好

createUser() {

   const { email, password } = this.state;

   firebase.auth().createUserWithEmailAndPassword(email, password)
   .then(data => {  
      console.log("User ID :- ", data.user.uid);
   })
   .catch(error => {
      console.log(error);
   });

}

然后(resp=>{console.log(resp);handleUserCreated(resp.user.uid,name…})try firebase.auth().onAuthStateChanged(function(user){})谢谢#MuruGan解决了我的问题,很好用了,谢谢,但是对于应用程序逻辑,我们需要提取auth对象之外的user.uid,以便在我们的应用程序逻辑中使用,我找不到解决方案。我将感谢您的帮助。谢谢