From 8bcd7c1376725a26fbfe2b374f20d3ac5e71f1c3 Mon Sep 17 00:00:00 2001 From: Paul Schmiedmayer Date: Thu, 30 May 2024 21:07:48 -0700 Subject: [PATCH] Improve Invitation Code Setup (#11) # Improve Invitation Code Setup ## :gear: Release Notes - Improves the invitation code setup using auth system instead of manually passing in the user id. - Update dependencies CC: @MatthewTurk247 ### Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md). --- .../xcshareddata/swiftpm/Package.resolved | 28 +++++++++---------- ENGAGEHF/Onboarding/InvitationCodeView.swift | 7 ++--- functions/index.js | 13 +++++---- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/ENGAGEHF.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ENGAGEHF.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index a46434b2..2cab3190 100644 --- a/ENGAGEHF.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ENGAGEHF.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -60,8 +60,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/firebase/firebase-ios-sdk.git", "state" : { - "revision" : "9d17b500cd98d9a7009751ad62f802e152e97021", - "version" : "10.26.0" + "revision" : "8bcaf973b1d84e119b7c7c119abad72ed460979f", + "version" : "10.27.0" } }, { @@ -69,8 +69,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/google/GoogleAppMeasurement.git", "state" : { - "revision" : "16244d177c4e989f87b25e9db1012b382cfedc55", - "version" : "10.25.0" + "revision" : "70df02431e216bed98dd461e0c4665889245ba70", + "version" : "10.27.0" } }, { @@ -159,8 +159,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/StanfordBDHG/ResearchKit", "state" : { - "revision" : "3f70adf898b5985ba15e25d5074d86a9c657d305", - "version" : "2.2.30" + "revision" : "69c4977f2ecd293b4e92d11f93a818b0b6517f0c", + "version" : "3.0.2" } }, { @@ -168,8 +168,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/StanfordBDHG/ResearchKitOnFHIR", "state" : { - "revision" : "cdb24dd5607d5a63aaf3a3597c98122189cb548e", - "version" : "1.3.0" + "revision" : "dcd5f95522ed02a873b03c9638dbf397b99c74e0", + "version" : "1.4.0" } }, { @@ -204,8 +204,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/StanfordSpezi/SpeziBluetooth.git", "state" : { - "revision" : "8e94fc71720ef3fcf7f5d9dba9eef603c5151d7a", - "version" : "1.3.0" + "revision" : "68966242caa49834a352953225b8b1d234481d77", + "version" : "1.4.0" } }, { @@ -276,8 +276,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/StanfordSpezi/SpeziQuestionnaire.git", "state" : { - "revision" : "f9d9b6d99bb1e00bda2974b440dca8367733d591", - "version" : "1.1.0" + "revision" : "76732ebcb0b521fa94d41c38a5fe35e6e1a87173", + "version" : "1.2.1" } }, { @@ -303,8 +303,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-argument-parser", "state" : { - "revision" : "46989693916f56d1186bd59ac15124caef896560", - "version" : "1.3.1" + "revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b", + "version" : "1.4.0" } }, { diff --git a/ENGAGEHF/Onboarding/InvitationCodeView.swift b/ENGAGEHF/Onboarding/InvitationCodeView.swift index a789c21a..43037d4e 100644 --- a/ENGAGEHF/Onboarding/InvitationCodeView.swift +++ b/ENGAGEHF/Onboarding/InvitationCodeView.swift @@ -104,7 +104,7 @@ struct InvitationCodeView: View { private func verifyOnboardingCode() async { do { if FeatureFlags.disableFirebase { - guard invitationCode == "VASCTRAC" else { + guard invitationCode == "ENGAGEHFTEST1" else { throw InvitationCodeError.invitationCodeInvalid } @@ -112,14 +112,13 @@ struct InvitationCodeView: View { } else { try Auth.auth().signOut() - async let authResult = Auth.auth().signInAnonymously() + try await Auth.auth().signInAnonymously() let checkInvitationCode = Functions.functions().httpsCallable("checkInvitationCode") do { _ = try await checkInvitationCode.call( [ - "invitationCode": invitationCode, - "userId": authResult.user.uid + "invitationCode": invitationCode ] ) } catch { diff --git a/functions/index.js b/functions/index.js index 1bda8722..a90029cd 100644 --- a/functions/index.js +++ b/functions/index.js @@ -18,15 +18,16 @@ const {beforeUserCreated} = require("firebase-functions/v2/identity"); admin.initializeApp(); exports.checkInvitationCode = onCall(async (request) => { - const {invitationCode, userId} = request.data; - - if (!userId) { + if (!request.auth.uid) { throw new https.HttpsError( - "unauthenticated", - "User is not properly authenticated.", + "unauthenticated", + "User is not properly authenticated.", ); } + const userId = request.auth.uid; + const {invitationCode} = request.data; + const firestore = admin.firestore(); logger.debug(`User (${userId}) -> ENGAGE-HF, InvitationCode ${invitationCode}`); @@ -35,7 +36,7 @@ exports.checkInvitationCode = onCall(async (request) => { const invitationCodeRef = firestore.doc(`invitationCodes/${invitationCode}`); const invitationCodeDoc = await invitationCodeRef.get(); - if (!invitationCodeDoc.exists || (invitationCodeDoc.data().used)) { + if (!invitationCodeDoc.exists || invitationCodeDoc.data().used) { throw new https.HttpsError("not-found", "Invitation code not found or already used."); }