javascript - 我的注册详细信息未保存到我的 firebase 数据库
问题描述
我正在开发这个注册应用程序,这是我在 firebase 上的第一次尝试。
我的电子邮件地址保存在 firebase 的身份验证部分,但是在我尝试将我的应用程序连接到数据库之后,以便我可以存储更多信息,当我单击注册时出现此错误:
Error: Reference.child failed: First argument was an invalid path = "undefined". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"
at validatePathString (firebase.js:1)
at t.child (firebase.js:1)
at userServices.js:30
at angular.js:14634
at m.$eval (angular.js:15878)
at m.$digest (angular.js:15689)
at angular.js:15917
at e (angular.js:5490)
at angular.js:5762
这是我的代码:
angular.module("registrationApp")
.factory("signupService", ["$rootScope", "$firebaseAuth", signupService]);
function signupService($rootScope, $firebaseAuth) {
var ref = firebase.database().ref();
var auth = $firebaseAuth();
return {
signup: function (user) {
auth.$createUserWithEmailAndPassword(
user.email,
user.password
).then(function (regUser) {
var userInfo = ref.child("Users")
.child(regUser.uid).set({
date: firebase.database.ServerValue.TIMESTAMP,
regUser: regUser.uid,
firstname: user.firstName,
email: user.email
})//userInfo
$rootScope.message = "Hi " + user.firstName + " " + "Thanks for Registering";
}).catch(function (error) {
$rootScope.message = error.message;
})
}
}
}`
解决方案
也许为时已晚,但我遇到了同样的问题,我的解决方案是将regUser.uid更改为regUser.user.uid。所以更新后的代码是:
var userInfo= ref.child('Users')
.child(regUser.user.uid).set({
date: firebase.database.ServerValue.TIMESTAMP,
regUser: regUser.user.uid,
firstname: user.firstname,
lastname: user.lastname,
email: user.email
})//userInfo
推荐阅读
- c - 为什么我的程序一次将其输入反转一行不起作用?
- excel - 使用 VBA 对数据透视表中的列进行排序时,如何在对象 PivotLines() 中插入变量?
- python - 尝试将对象转换为数字时出现问题
- c++ - 格式指定类型'char *',但参数的类型为'std::string *'(又名'basic_string
*') - html - 从以前的网页而不是重定向的网页 VBA 填充的 HTML 元素集合
- javascript - 节点js写入文件
- android - 如何在 Gradle 中删除任务名称中的斜杠
- java - 第二个 Jframe 不会显示
- wordpress - MAMP localhost 归档导致一无所获
- javascript - Socket.io 不会在我的 React 应用程序中的浏览器后退按钮上触发断开连接