profile deletion added

This commit is contained in:
Milan Paunovic
2024-11-01 05:19:11 +01:00
parent 6e7a3475d1
commit 9ca96b2286
5 changed files with 40 additions and 3 deletions

View File

@ -0,0 +1,32 @@
import {useAuthContext} from "@/contexts/AuthContext";
import {useMutation} from "react-query";
import firestore from "@react-native-firebase/firestore";
import auth, {FirebaseAuthTypes} from "@react-native-firebase/auth";
export const useDeleteUser = () => {
const {user: currentUser} = useAuthContext();
return useMutation({
mutationKey: ["deleteUser"],
mutationFn: async ({customUser}: { customUser?: FirebaseAuthTypes.User }) => {
const user = currentUser ?? customUser;
if (user) {
try {
await firestore()
.collection("Profiles")
.doc(user.uid)
.delete();
await auth().currentUser?.delete();
await auth().signOut();
console.log("User deleted and signed out successfully");
} catch (e) {
console.error("Error deleting user:", e);
}
}
},
});
};