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!