【发布时间】:2017-02-18 23:55:57
【问题描述】:
这是任务。创建用户时,我想在主数据库中添加它们的一个实例,以便它们可以拥有与它们相关联的东西(列表和食谱)。我尝试做.set() 和.update(),虽然两者都在我的数据库中添加了一个用户实例,但每次新用户注册时它都会被覆盖。我将如何不覆盖该信息?我将根据我找到的信息继续搜索和更新我的帖子。这是我拥有的身份验证代码。
app.controller("SampleCtrl", ["$scope", "Auth",
function($scope, Auth) {
$scope.auth = Auth;
$scope.createUser = function() {
$scope.message = null;
$scope.error = null;
// Create a new user
Auth.$createUserWithEmailAndPassword($scope.email, $scope.password, $scope.name)
.then(function(firebaseUser) {
$scope.message = "User created with uid: " + firebaseUser.uid;
const uid = firebaseUser.uid;
const dbref = firebase.database().ref().child('users');
dbref.update({
id: uid,
name: $scope.name
});
console.log(dbref.uid);
}).catch(function(error) {
$scope.error = error;
});
};
$scope.deleteUser = function() {
$scope.message = null;
$scope.error = null;
$scope.auth.$onAuthStateChanged(function(firebaseUser) {
$scope.firebaseUser = firebaseUser;
});
// Delete the currently signed-in user
Auth.$deleteUser().then(function() {
$scope.message = "User deleted";
}).catch(function(error) {
$scope.error = error;
});
};
}
]);
提前致谢!
******编辑**********
好的,所以我得到了要添加的信息,但不是我预期的方式。我希望结构是这样的 用户 - - - ID - - - -信息 其中 id 是键,info 是保存新对象的值。 我得到的是这个...... a random serialized ID and then my user id and information object
现在的问题是,我如何摆脱那个随机序列化的密钥?
【问题讨论】:
标签: angularjs firebase firebase-realtime-database firebase-authentication