Here is the task. When a user is created, I would like to add an instance of them in the main database so they can then have things associated with them (lists and recipes). I tried doing .set()
and .update()
and while both added an instance of the user in my DB, it would get overwritten each time a new user registered. How would I go about not having that information overwritten? I will keep searching and update my post based on the information I have found. Here is the auth code I have.
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;
});
};
}
]);
Thanks in advance!
******EDIT**********
Okay, so I got information to be added, but not in the way I expected. I want the structure to be like this users ----- id -------info Where id is the key and info is the value that holds a new object. What I am getting is this... a random serialized ID and then my user id and information object
The question is now, how do I get rid of that random serialized key?