From 89dcd43afe0103673427c005c4274bb0509253cc Mon Sep 17 00:00:00 2001 From: Conor McNamara Date: Wed, 15 Mar 2023 12:04:58 +0000 Subject: [PATCH 1/4] Add and store user preferences --- functions/index.js | 25 ++++++---- src/components/Navbar.vue | 2 + src/pages/MapPage.vue | 100 +++++++++++++++++++++++++++----------- src/store/store.js | 5 ++ 4 files changed, 94 insertions(+), 38 deletions(-) diff --git a/functions/index.js b/functions/index.js index 01496b0..3226245 100644 --- a/functions/index.js +++ b/functions/index.js @@ -199,13 +199,18 @@ exports.postLiveTrainData = functions.https.onRequest((request, response) => { }) }) -exports.securefunction = functions.https.onCall((data, context) => { - if (typeof context.auth === undefined) { - // user not logged in - return "User is not logged in" - } - else { - // user logged in - return "User is logged in" - } -}) +// secure function to fetch a user's filter preferences from the database +exports.getPreferences = functions.https.onCall((data, context) => { + if (!context.auth) return "Error request is not verified" + return admin.firestore().collection('preferences').doc(context.auth.uid).get().then((preferences) => { + return preferences.data() + }) +}) + +// secure function to set a user's filter prefernces 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" + }) +}) \ No newline at end of file diff --git a/src/components/Navbar.vue b/src/components/Navbar.vue index a710f33..51b0c33 100644 --- a/src/components/Navbar.vue +++ b/src/components/Navbar.vue @@ -34,6 +34,7 @@