mirror of
https://github.com/urosran/cally.git
synced 2025-07-16 01:56:16 +00:00
profile deletion added
This commit is contained in:
32
hooks/firebase/useDeleteUser.ts
Normal file
32
hooks/firebase/useDeleteUser.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user