Skip to content

Commit

Permalink
Fix Invitation Code Setup
Browse files Browse the repository at this point in the history
  • Loading branch information
PSchmiedmayer committed May 30, 2024
1 parent 9e3715d commit 55c8904
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk.git",
"state" : {
"revision" : "9d17b500cd98d9a7009751ad62f802e152e97021",
"version" : "10.26.0"
"revision" : "8bcaf973b1d84e119b7c7c119abad72ed460979f",
"version" : "10.27.0"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "16244d177c4e989f87b25e9db1012b382cfedc55",
"version" : "10.25.0"
"revision" : "70df02431e216bed98dd461e0c4665889245ba70",
"version" : "10.27.0"
}
},
{
Expand Down Expand Up @@ -159,17 +159,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordBDHG/ResearchKit",
"state" : {
"revision" : "3f70adf898b5985ba15e25d5074d86a9c657d305",
"version" : "2.2.30"
"revision" : "cf7ad893f0778b2d9b8af2d7e769ed84bbd45cbc",
"version" : "3.0.1"
}
},
{
"identity" : "researchkitonfhir",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordBDHG/ResearchKitOnFHIR",
"state" : {
"revision" : "cdb24dd5607d5a63aaf3a3597c98122189cb548e",
"version" : "1.3.0"
"revision" : "dcd5f95522ed02a873b03c9638dbf397b99c74e0",
"version" : "1.4.0"
}
},
{
Expand Down Expand Up @@ -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"
}
},
{
Expand Down Expand Up @@ -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"
}
},
{
Expand All @@ -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"
}
},
{
Expand Down
7 changes: 3 additions & 4 deletions ENGAGEHF/Onboarding/InvitationCodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,21 @@ struct InvitationCodeView: View {
private func verifyOnboardingCode() async {
do {
if FeatureFlags.disableFirebase {
guard invitationCode == "VASCTRAC" else {
guard invitationCode == "ENGAGEHFTEST1" else {

Check warning on line 107 in ENGAGEHF/Onboarding/InvitationCodeView.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Onboarding/InvitationCodeView.swift#L107

Added line #L107 was not covered by tests
throw InvitationCodeError.invitationCodeInvalid
}

try? await Task.sleep(for: .seconds(0.25))
} 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 {
Expand Down
13 changes: 7 additions & 6 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand All @@ -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.");
}

Expand Down

0 comments on commit 55c8904

Please sign in to comment.