[Vuejs]-How to delete user with Vue.js Firebase UID

3đź‘Ť

In your code, user is a DocumentSnapshot type object. If you want to delete the document, you can use user.ref.delete(). It returns a promise, so you will need to await it.

Deleting a document will not also delete a user account in Firebase Authentication. If you want to delete the user account, you will have to use the Firebase Authentication API for that. firebase.auth().currentUser.delete().

1đź‘Ť

try this

<button class="..." @click="deleteProfile(currentUser.uid)">Delete</button>

and

methods: {
async deleteProfile(dataId) {
      fireDb.collection("yourCollection").doc(dataId).delete()
      .then(() => {
        alert('Deleted')
      })
    }
}
👤Ham-

0đź‘Ť

Building off Doug Stevenson’s answer, this is the function that ultimately worked.

    async deleteProfile (user) {
      await db.collection("users").doc(user).delete()
      await firebase.auth().currentUser.delete()
    }

await db.collection("users").doc(user).delete() accepts “user” as an argument from the click event in the DOM, in order to target the doc of the specified user in the database (I don’t know why I didn’t think of that sooner!) await firebase.auth().currentUser.delete() removes currentUser from firebase authorization.

Leave a comment