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 ? ( - + 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 );