mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 00:24:53 +00:00
profile deletion added
This commit is contained in:
2
app.json
2
app.json
@ -16,7 +16,7 @@
|
|||||||
"supportsTablet": true,
|
"supportsTablet": true,
|
||||||
"bundleIdentifier": "com.cally.app",
|
"bundleIdentifier": "com.cally.app",
|
||||||
"googleServicesFile": "./ios/GoogleService-Info.plist",
|
"googleServicesFile": "./ios/GoogleService-Info.plist",
|
||||||
"buildNumber": "63",
|
"buildNumber": "64",
|
||||||
"usesAppleSignIn": true
|
"usesAppleSignIn": true
|
||||||
},
|
},
|
||||||
"android": {
|
"android": {
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import React, { useState } from "react";
|
|||||||
import { Dialog, Button, Text, View } from "react-native-ui-lib";
|
import { Dialog, Button, Text, View } from "react-native-ui-lib";
|
||||||
import { StyleSheet } from "react-native";
|
import { StyleSheet } from "react-native";
|
||||||
import { Feather } from "@expo/vector-icons";
|
import { Feather } from "@expo/vector-icons";
|
||||||
|
import {useDeleteUser} from "@/hooks/firebase/useDeleteUser";
|
||||||
|
|
||||||
interface ConfirmationDialogProps {
|
interface ConfirmationDialogProps {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
@ -17,6 +18,7 @@ const DeleteProfileDialogs: React.FC<ConfirmationDialogProps> = ({
|
|||||||
onConfirm,
|
onConfirm,
|
||||||
}) => {
|
}) => {
|
||||||
const [confirmationDialog, setConfirmationDialog] = useState<boolean>(false);
|
const [confirmationDialog, setConfirmationDialog] = useState<boolean>(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Dialog
|
<Dialog
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import { useUpdateUserData } from "@/hooks/firebase/useUpdateUserData";
|
|||||||
import { useChangeProfilePicture } from "@/hooks/firebase/useChangeProfilePicture";
|
import { useChangeProfilePicture } from "@/hooks/firebase/useChangeProfilePicture";
|
||||||
import { colorMap } from "@/constants/colorMap";
|
import { colorMap } from "@/constants/colorMap";
|
||||||
import DeleteProfileDialogs from "../user_components/DeleteProfileDialogs";
|
import DeleteProfileDialogs from "../user_components/DeleteProfileDialogs";
|
||||||
|
import {useDeleteUser} from "@/hooks/firebase/useDeleteUser";
|
||||||
|
|
||||||
const MyProfile = () => {
|
const MyProfile = () => {
|
||||||
const { user, profileData } = useAuthContext();
|
const { user, profileData } = useAuthContext();
|
||||||
@ -45,6 +46,7 @@ const MyProfile = () => {
|
|||||||
|
|
||||||
const { mutateAsync: updateUserData } = useUpdateUserData();
|
const { mutateAsync: updateUserData } = useUpdateUserData();
|
||||||
const { mutateAsync: changeProfilePicture } = useChangeProfilePicture();
|
const { mutateAsync: changeProfilePicture } = useChangeProfilePicture();
|
||||||
|
const { mutateAsync: deleteAsync } = useDeleteUser()
|
||||||
const isFirstRender = useRef(true);
|
const isFirstRender = useRef(true);
|
||||||
|
|
||||||
const handleUpdateUserData = async () => {
|
const handleUpdateUserData = async () => {
|
||||||
@ -229,7 +231,7 @@ const MyProfile = () => {
|
|||||||
}}
|
}}
|
||||||
visible={showDeleteDialog}
|
visible={showDeleteDialog}
|
||||||
onDismiss={handleHideDeleteDialog}
|
onDismiss={handleHideDeleteDialog}
|
||||||
onConfirm={() => {console.log('delete account here')}}
|
onConfirm={() => deleteAsync({})}
|
||||||
/>
|
/>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
);
|
);
|
||||||
|
|||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -47,7 +47,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>63</string>
|
<string>64</string>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSAppTransportSecurity</key>
|
<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>
|
||||||
<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>
|
</array>
|
||||||
<key>UILaunchStoryboardName</key>
|
<key>UILaunchStoryboardName</key>
|
||||||
<string>SplashScreen</string>
|
<string>SplashScreen</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user