Enable deletion of user preferences

This commit is contained in:
Conor McNamara
2023-03-16 11:15:40 +00:00
parent 063b858777
commit 66c6dae003
3 changed files with 29 additions and 2 deletions

View File

@ -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"
})
})

View File

@ -18,6 +18,9 @@
<h3>Delete account</h3>
<input @click="deleteUserAccount" type="submit" name="" value="Delete Account">
<h3>Delete filter preferences data</h3>
<button @click="deleteUserPreferences">Delete preferences</button>
</div>
<p v-if="missingCredentials">Missing credentials to complete this action</p>
@ -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
})
}
}
}

View File

@ -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()
}