0

I would like to delete users authenticated by yours KEY, knowing that I am a administrator, firts I created an authservice and after an userService to associate with registered user

enter image description here

Now in Database I have the associate user enter image description here

Now in my code I have Firts, I created method auth to create user in auth.service.ts

    createUser(user: any, path: string) {
    return this.afu.auth.createUserWithEmailAndPassword(user.email, user.password)
                                .then(() => {
                                  return this.service.save(user, path);
                                })
                                .catch((e) => console.log(e));
  }

this method create user authenticated and create in Database a user, calling the method save

    save(user: any, path: string) {
    const createdAt = new Date();
    return new Promise((resolve, reject) => {
      this.db.list(this.PATH + path)
            // .push(user)
              // console.log(createdAt)
            .push({ name: user.name, email: user.email, role: user.role_id, status: user.status, created_at: createdAt  })
            .then(() => resolve())
    })
  }

So, I have to delete this two registers by KEY in my method

    remove(key: string, path: string) {
    return this.db.list(this.PATH + path).remove(key);
  }

Remebering, I'm administrator

2
  • Could you give more details on the remove() function? You call it on list()? Commented May 5, 2018 at 7:56
  • So, this function remove() delete only the data of Database but don't delete of Authentication, I would like to delete both Commented May 5, 2018 at 14:06

1 Answer 1

3

From your comment I understand you want to "delete the user from Authentication". Use the delete() method of User, see https://firebase.google.com/docs/reference/js/firebase.User

You get the current user with the currentUser() method of the Auth service interface, see https://firebase.google.com/docs/reference/js/firebase.auth.Auth#currentUser

In "pure" JavaScript you can do the following and user with mail [email protected] will be deleted from the Authentication list.

firebase.auth().signInWithEmailAndPassword("[email protected]", "abcd")
    .then(function (info) {
       var user = firebase.auth().currentUser;
       user.delete();
    });
Sign up to request clarification or add additional context in comments.

1 Comment

I done my friend thank you very much perfect, now its work to me, I did so remove(user: any, path: string) { return this.db.list(this.PATH + path).remove(user.key) .then(() => { firebase.auth().signInWithEmailAndPassword(user.email, user.password) .then(function (info) { var user = firebase.auth().currentUser; user.delete(); }); }); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.