首页 文章

将用户uid链接到firebase数据库

提问于
浏览
2

我目前正在使用react-native创建一个应用程序,并希望将firebase身份验证生成的userid链接到我的firebase数据库中的用户信息 .

{
  users:useruid:{
                  //Storing other user information
               }
}

我正在从auth中检索uid并为这样的用户创建一个新的子代:

firebase.auth().onAuthStateChanged((user) => {

  console.log(user)

  if(user){

    user.getToken().then((userid) => {
      //Set the initial state
      firebase.database().ref('/users/').child(userid).set({
        'uid': userid,
        'businessName': business,
        'street address': street,
        'city': city,
        'state': state,
        'zipcode': zipcode,
        'productGroup': 0,
        'pom': 0,
        'som': 0,
        'inventory': 0,
        'reporting_and_analytics': 0,
        'accounting': 0
      })

      dispatch({type: types.REGISTER_USER_SUCCESS})

    }).catch(function(error){
      console.log(error.message)
      dispatch({type: types.REGISTER_BUSINESS_FAILURE, error});
    });
  }
  else{
    console.log("ERROR: Registration error")
  }
});

 }

我收到错误:关于生成的uid的路径无效 . 任何帮助 . 我检查了firebase上的文档以及与此相关的类似问题,但仍然得到相同的错误 .

Error

1 回答

  • 0

    路径:

    firebase.database().ref('/users/').child(userid)
    

    由于 child() 的工作方式,这与 //users//userid 基本相同,这显然是一条不正确的路径 .

    而是在 users 之前和之后丢失 / . 尝试:

    firebase.database().ref('users').child(userid)
    

    child() 方法将形成正确的路径 .

相关问题