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

@ -16,7 +16,7 @@
"supportsTablet": true,
"bundleIdentifier": "com.cally.app",
"googleServicesFile": "./ios/GoogleService-Info.plist",
"buildNumber": "63",
"buildNumber": "64",
"usesAppleSignIn": true
},
"android": {

View File

@ -2,6 +2,7 @@ import React, { useState } from "react";
import { Dialog, Button, Text, View } from "react-native-ui-lib";
import { StyleSheet } from "react-native";
import { Feather } from "@expo/vector-icons";
import {useDeleteUser} from "@/hooks/firebase/useDeleteUser";
interface ConfirmationDialogProps {
visible: boolean;
@ -17,6 +18,7 @@ const DeleteProfileDialogs: React.FC<ConfirmationDialogProps> = ({
onConfirm,
}) => {
const [confirmationDialog, setConfirmationDialog] = useState<boolean>(false);
return (
<>
<Dialog

View File

@ -20,6 +20,7 @@ import { useUpdateUserData } from "@/hooks/firebase/useUpdateUserData";
import { useChangeProfilePicture } from "@/hooks/firebase/useChangeProfilePicture";
import { colorMap } from "@/constants/colorMap";
import DeleteProfileDialogs from "../user_components/DeleteProfileDialogs";
import {useDeleteUser} from "@/hooks/firebase/useDeleteUser";
const MyProfile = () => {
const { user, profileData } = useAuthContext();
@ -45,6 +46,7 @@ const MyProfile = () => {
const { mutateAsync: updateUserData } = useUpdateUserData();
const { mutateAsync: changeProfilePicture } = useChangeProfilePicture();
const { mutateAsync: deleteAsync } = useDeleteUser()
const isFirstRender = useRef(true);
const handleUpdateUserData = async () => {
@ -229,7 +231,7 @@ const MyProfile = () => {
}}
visible={showDeleteDialog}
onDismiss={handleHideDeleteDialog}
onConfirm={() => {console.log('delete account here')}}
onConfirm={() => deleteAsync({})}
/>
</ScrollView>
);

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);
}
}
},
});
};

View File

@ -47,7 +47,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>63</string>
<string>64</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
@ -138,6 +138,7 @@
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
</array>
<key>UILaunchStoryboardName</key>
<string>SplashScreen</string>