How do I in the best possible way remove a user and his/her profile (the profile has it's own node with the $uid as the key) in the best way in Firebase?
Should I just do a $remove() on the profile and then a $userRemove(), or is there a better way? If I have my rules setup properly I can't access the profile for a deletion after I deleted the user I guess, since only the user has write access to the profile.
"profiles": {
"$uid": {
// grants write access to the owner of this profile whose uid must exactly match the key ($uid)
".write": "auth !== null && auth.uid === $uid",
// grants read access to any user who is logged in with an email and password
".read": "auth !== null && auth.provider === 'password'"
}
}
This is how I figure it could be done, but what happens if one of the calls goes through and not the other, then it's an inconsistent user/profile left.
var firebaseObj = new Firebase(FBURL),
Auth = $firebaseAuth(firebaseObj);
var profileObj = $firebase(firebaseObj.child('profiles').child(user.uid)).$asObject();
profileObj.$remove().then(function(data) {
return Auth.$removeUser(user);
}).then(function(data) {
console.log('successfully removed user and profile');
});
Note: I have not tested the code above, just wanted to get other peoples thoughts about how to do this and provide a rough example of how I could do it.