Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

848
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda