Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

847
Views
The correct way to delete a user with react-native-firebase from Auth and Firestore at once?

I'm trying to delete a user from Auth and Firestore on button click in one go using react-native-firebase. My issue at the moment is that it is not deleting the document 'user' from Firestore. BUT, it does look like I am deleting the user from Auth.

Also when I press the button that calls the deleteUserFunc I receive the error:

"null is not an object (evaluating '(0, _auth.default)().currentUser.uid')"

(UID has a valid id on page load)

const [_, setUser] = useContext(UserContext);
const uid = auth().currentUser.uid;   

const deleteUserFunc = async () => {
        await deleteAccount();
    }

    async function deleteAccount() {
        auth().currentUser.delete().then(() => {
            db.collection('users')
                .doc(user.uid)
                .delete()
        }).catch((error) => {
            console.log(error, "error")
        }).finally(() => setUser((state) => ({ ...state, isLoggedIn: false })))
    }

How can I delete from the Firestore for this user, as well as improve the code that I have written.

Any help is appreciated - thank you for your time!

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

My guess is that you set your user variable to point to auth.currentUser, which becomes null when you delete the current user. So you'll need to either reverse the operations (first delete the document, then the user), or you can capture the UID in a local variable before deleting the user.

The latter would look like:

async function deleteAccount() {
    const uid = auth().currentUser.uid; // ๐Ÿ‘ˆ
    auth().currentUser.delete().then(() => {
        db.collection('users')
            .doc(uid) // ๐Ÿ‘ˆ
            .delete()
    }).catch((error) => {
        console.log(error, "error")
    }).finally(() => setUser((state) => ({ ...state, isLoggedIn: false })))
}
about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!