【问题标题】:Linking user uid to firebase database将用户 uid 链接到 firebase 数据库
【发布时间】:2017-10-06 17:37:54
【问题描述】:

我目前正在 react-native 中制作应用程序,并希望将 firebase 身份验证生成的用户 ID 链接到我的 firebase 数据库中的用户信息。

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

我正在从身份验证中检索 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

【问题讨论】:

  • 使用uid代替令牌,如firebase.database().ref('/users/').child(user.uid)
  • @cherniv 我收到与 user.uid 相同的错误。同样在documentation user.getToken() 上推荐而不是user.uid。
  • @Cherniv user.uid 有效。经过几次重试,它成功了。 user.getToken() 生成一个令牌,其中包含一些不能在 firebase 路径上使用的字符。 firebase Invalid Characters
  • 我正在努力解决同样的问题。我意识到你的帖子已经有几年了 - 所以也许事情已经改变了,但我无法让这种方法发挥作用。你还在用这种方式吗?

标签: node.js firebase react-native firebase-realtime-database firebase-authentication


【解决方案1】:

路径:

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

本质上与//users//userid 相同,因为child() 的工作方式显然是不正确的路径。

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

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

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

【讨论】:

  • 谢谢布拉德利。但是,在写入firebase并使用以下命令指定完整路径时,在节点名称之前和之后使用'/'没有遇到任何问题:firebase.database.ref([您正在尝试的节点的完整路径的名称访问])。但是在使用 child() 方法并包含斜杠时存在问题。
猜你喜欢
  • 2016-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 1970-01-01
  • 2021-02-09
  • 2017-07-30
相关资源
最近更新 更多