【发布时间】: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 的文档以及与此相关的类似问题,但仍然遇到相同的错误。
【问题讨论】:
-
使用
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