I have been researching extensively and am struggling to get any data to show up in the firebase database. I am aiming for this specific structure:
"my-app-name": {
"users": {
"uid-of-user": {
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="403428252d003428252d6e232f2d">[email protected]</a>",
"todoitems": {
}
}
}
}
Initially, I am unsure about how to implement this structure. In the visual editor, under "my-app-name"
, I have inputted "users" = ""
. I am uncertain if this is the correct way to start establishing users
as an empty object. Perhaps I should not be using the visual editor at all? Below is my createNewUser
controller responsible for storing new users in the database:
function LoginController($scope, Auth, $state, $location, $firebaseObject, $firebase) {
$scope.createNewUser = createNewUser;
$scope.signupComplete = "";
function createNewUser() {
var ref = new Firebase("https://sizzling-torch-655.firebaseio.com/");
//CREATE USER
Auth.$createUser({
email: $scope.email,
password: $scope.password
}).then(function(userData) {
//THIS SHOULD BE PERSISTING IT TO THE DATABASE
var user = $firebaseObject(ref.child('users').child(userData.uid));
user.$loaded().then(function() {
var newUser = {
emailAddress: $scope.email,
};
user.$ref.$set(newUser);
})
// $location.path("/home");
}).catch(function(error) {
$scope.responseMessage = error;
});
};
};
I want to emphasize that the 'users' object has not been created in the firebase database yet. Any assistance would be greatly appreciated. Thank you.
Additional Information
Auth.$creatUser
is defined as:
app.factory("Auth", ["$firebaseAuth", function($firebaseAuth) {
return $firebaseAuth(ref);
}]);
Although I successfully created users and can see them in the Login/Users tab of the Firebase dashboard, I am unable to store them in the database.
The userData.uid
refers to the unique identifier returned from the then
block of the $createUser
function.
UPDATE 2 Here are my security rules. Could these be preventing me from writing user data to the database? This app will be a todo list application, where users should only be able to access their own data.
{
"rules": {
// public read access
".read": true,
"users": {
"$uid": {
".write": "$uid === auth.uid"
}
}
}
}