diff --git a/functions/index.js b/functions/index.js index b9dff0e..07b70f8 100644 --- a/functions/index.js +++ b/functions/index.js @@ -207,10 +207,18 @@ exports.getPreferences = functions.https.onCall((data, context) => { }) }) -// secure function to set a user's filter prefernces in the database +// secure function to set a user's filter preferences in the database exports.postPreferences = functions.https.onCall((data, context) => { if (!context.auth) return "Error request is not verified" return admin.firestore().collection('preferences').doc(context.auth.uid).set({data}).then(() => { return "Successfully saved preferences" }) +}) + +// secure function to delete a user's filter preferences from the database +exports.deletePreferences = functions.https.onCall((data, context) => { + if (!context.auth) return "Error request is not verified" + return admin.firestore().collection('preferences').doc(context.auth.uid).delete().then(() => { + return "Successfully deleted preferences" + }) }) \ No newline at end of file diff --git a/src/pages/AccountPage.vue b/src/pages/AccountPage.vue index 3f7654a..366ce1c 100644 --- a/src/pages/AccountPage.vue +++ b/src/pages/AccountPage.vue @@ -18,6 +18,9 @@
Missing credentials to complete this action
@@ -155,6 +158,23 @@ export default { this.FirebaseError = error.message this.displayFirebaseError = true }) + }, + + deleteUserPreferences() { + const functions = getFunctions(app) + let host = window.location.hostname + if (host === '127.0.0.1' || host === 'localhost') { + connectFunctionsEmulator(functions, host, 5001); + } + const deletePreferencesData = httpsCallable(functions, 'deletePreferences') + deletePreferencesData().then(() => { + this.FirebaseSuccessMsg = "Successfully deleted filter preferences" + this.displayFirebaseSuccessMsg = true + }) + .catch((error) => { + this.FirebaseError = error.message + this.displayFirebaseError = true + }) } } } diff --git a/src/pages/MapPage.vue b/src/pages/MapPage.vue index 3ceaaf4..87cbcb0 100644 --- a/src/pages/MapPage.vue +++ b/src/pages/MapPage.vue @@ -163,7 +163,6 @@ export default { this.showNotYetRunning = response.data.data["showNotYetRunning"] // update the map with the user's preferences - console.log("got preferences") this.decideShowStations() this.decideShowTrains() }