mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 15:17:17 +00:00
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import {useAuthContext} from "@/contexts/AuthContext";
|
|
import {useMutation} from "@tanstack/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);
|
|
}
|
|
}
|
|
},
|
|
});
|
|
}; |