Firebase security rules do not allow when creating a user

I use the Firebase method $authWithPasswordto log in the user. I use the method $createUserto create a registration for my users and its success. I am updating the entry on my / users / path to save the username, uid and some other details. Here is the code

var myDataRef = new Firebase(baseURL + 'datalog/');
var refObj = $firebaseAuth(myDataRef);

refObj.$createUser({
    email: $scope.emailId,
    password: $scope.password
}).then(function(userData) {
    var UserUniqueUrl = new Firebase(baseURL + 'users/' + userData.uid + '/');
    UserUniqueUrl.set({
        'email': $scope.emailId,
        'username': $scope.username,
        'uid': userData.uid,
        'theme': 'default'
    }, function(error) {
        if (error) {
            console.log(error);
        } else {
            console.log('Successfully updated in user table');
        }
    });
}).catch(function(error) {
    if (error.code == 'EMAIL_TAKEN') {
        $scope.regStatusError = 'Email already registered!';
    } else {
        $scope.regStatusError = 'Unable to register! Try again later.';
    }
});

And here are my safety rules

{
    "rules": {
        "users": {
            ".read": "auth != null",
            ".write": "auth != null"
        }
    }
}

, , , , , - ".read": "auth != null" ".write": "auth != null". ".read": true ".write": true, , , uid email, . , ?

enter image description here . .

+4
1

, -

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }
  }
}

-1

Source: https://habr.com/ru/post/1617205/


All Articles