From 252492d3fdfc248f1ce1d6461acaa5c2db4598c3 Mon Sep 17 00:00:00 2001 From: tsh22 Date: Wed, 2 Mar 2022 18:49:25 +0800 Subject: [PATCH 1/2] Implement terminate account function --- App.js | 28 ++++++++++++- .../settings-screens/MainSettingsScreen.js | 10 ++--- .../TerminateAccountScreen.js | 22 ++++++---- .../TerminateConfirmationScreen.js | 40 +++++-------------- 4 files changed, 56 insertions(+), 44 deletions(-) diff --git a/App.js b/App.js index bd6480e..4af0461 100644 --- a/App.js +++ b/App.js @@ -63,6 +63,32 @@ export default function App() { }, []); const authContext = { + terminateAccount: (data) => { + const usersRef = firebase.firestore().collection("users"); + // Remove user data + usersRef + .doc(data.uid) + .delete() + .then(() => { + console.log(`Document ${data.uid} successfully deleted!`); + + // Remove auth for user + data.user + .delete() + .then(() => { + setUser(null); + setValidated(false); + console.log(`User ${data.uid} account terminated!`); + }) + .catch((error) => { + console.log(error); + console.log("Error terminating account"); + }); + }) + .catch((error) => { + console.error("Error removing document: ", error); + }); + }, signUpSuccess: () => { if (!isValidated) { console.log("sign up success"); @@ -228,7 +254,7 @@ export default function App() { - {console.log(isValidated)} + {console.log(`Authentication check isValidated? : ${isValidated}`)} {user && isValidated ? ( Log out - v2.2.2 + v2.2.3 ); @@ -101,8 +101,8 @@ const tabs = [ }, // {id: 2, // title: "Feedback to us!"} - // { - // id: "4", - // title: "Terminate my account", - // }, + { + id: "2", + title: "Terminate my account", + }, ]; diff --git a/screens/settings-screens/TerminateAccountScreen.js b/screens/settings-screens/TerminateAccountScreen.js index fc0bc8b..5ba1d18 100644 --- a/screens/settings-screens/TerminateAccountScreen.js +++ b/screens/settings-screens/TerminateAccountScreen.js @@ -6,20 +6,23 @@ import { TouchableOpacity, TouchableWithoutFeedback, Keyboard, + Image, } from "react-native"; import { Input } from "react-native-elements"; import colors from "../../assets/colors"; import { globalStyles } from "../../assets/globalStyles"; -import { Entypo } from "@expo/vector-icons"; +import firebase from "../../database/firebaseDB"; export default function TerminateAccountScreen({ navigation }) { const [isMatching, setMatching] = useState(false); const [showError, setShow] = useState(false); + const user = firebase.auth().currentUser; + function onPress() { if (isMatching) { setShow(false); - navigation.navigate("Account terminated"); + navigation.navigate("Account terminated", { user: user }); } else { setShow(true); } @@ -36,12 +39,11 @@ export default function TerminateAccountScreen({ navigation }) { return ( - + Are you sure you want to terminate your account? @@ -105,4 +107,10 @@ const styles = StyleSheet.create({ terminateContainer: { marginVertical: 20, }, + sadSmile: { + alignSelf: "center", + marginBottom: 20, + height: 60, + width: 60, + }, }); diff --git a/screens/settings-screens/TerminateConfirmationScreen.js b/screens/settings-screens/TerminateConfirmationScreen.js index 85e1de5..d1475e1 100644 --- a/screens/settings-screens/TerminateConfirmationScreen.js +++ b/screens/settings-screens/TerminateConfirmationScreen.js @@ -4,43 +4,21 @@ import { globalStyles } from "../../assets/globalStyles"; import firebase from "../../database/firebaseDB"; import { AuthContext } from "../../assets/AuthContext"; -export default function TerminateConfirmationScreen({ navigation }) { - function terminateAccount() { - return null; - // useEffect(() => { - // const usersRef = firebase.firestore().collection("users"); - // firebase.auth().onAuthStateChanged((user) => { - // if (user) { - // // Remove user data - // usersRef - // .doc(user.uid) - // .delete() - // .then(() => { - // console.log("Document successfully deleted!"); - // }) - // .catch((error) => { - // console.error("Error removing document: ", error); - // }); +export default function TerminateConfirmationScreen({ navigation, route }) { + const { user } = route.params; + const { terminateAccount } = useContext(AuthContext); - // // Remove auth for user - // user - // .delete() - // .then(() => { - // console.log("Account terminated"); - // }) - // .catch((error) => console.log("Error terminating account")); - // } else { - // console.log("No user"); - // } - // }); - // }, []); + const uid = user.uid; + + function terminate() { + return terminateAccount({ user, uid }); } return ( Account successfully terminated. - - Go to sign in page + + Go to welcome screen ); From fbaf7cfdb503a07a15eac072b8241c804b122130 Mon Sep 17 00:00:00 2001 From: tsh22 Date: Wed, 2 Mar 2022 18:49:44 +0800 Subject: [PATCH 2/2] Update version number --- app.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.json b/app.json index 83c0c14..94cc769 100644 --- a/app.json +++ b/app.json @@ -2,7 +2,7 @@ "expo": { "name": "GOZeroWaste", "slug": "GOZeroWaste", - "version": "2.1.0", + "version": "2.2.3", "orientation": "portrait", "icon": "./assets/icons/icon.png", "splash": { @@ -29,7 +29,7 @@ "backgroundColor": "#FFFFFF" }, "package": "com.tsh22.gozerowaste", - "versionCode": 2 + "versionCode": 6 }, "web": { "favicon": "./assets/icons/favicon.png"