Diaconu Eduard Diaconu Eduard - 1 year ago 122
AngularJS Question

Remove users from Firebase

I start learn more about Firebase and i try to create a simple database.

I follow all steps from website and i successfully added members in database.

But...now, it's necessary to learn how can remove an user.

Here is my code to add and remove users:

<!DOCTYPE html>

<button onclick="saveData()">Save Data</button>
<button onclick="printData()">Print Data</button>
<button onclick="printData2()">Print Data2</button>
<button onclick="remove()">Remove</button>
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
var ref = new Firebase("https://projecttest-9aee9.firebaseio.com/web/saving-data/fireblog");
var usersRef = ref.child("users");
function saveData(){
alanisawesome: {
date_of_birth: "June 23, 1912",
full_name: "Alan Turing"
gracehop: {
date_of_birth: "December 9, 1906",
full_name: "Grace Hopper"
function printData(){

usersRef.on("value", function(snapshot) {
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
function printData2(){

ref.child("users/gracehop/date_of_birth").on("value", function(snapshot) {
console.log(snapshot.val());//"December 9, 1906"
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);

function remove(){
alanisawesome: {
date_of_birth: "June 23, 1912",
full_name: "Grace Hopper"


Where is the problem with remove users function?

Thank you for help!

Answer Source

First removeUser is not defined anywhere. Second, I don't think you're using the correct ref in remove(), you should use usersRef.

Try using the user.remove() method.

From the User API reference:

Deletes and signs out the user.

Important: this is a security sensitive operation that requires the user to have recently signed in. If this requirement isn't met, ask the user to authenticate again and then call firebase.User#reauthenticate.

If you want to delete the database node corresponding to a user, you could do something like this:

  .then(function() {
    console.log("Remove succeeded.")
  .catch(function(error) {
    console.log("Remove failed: " + error.message)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download