Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Invitation Code Setup #11

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" : "69c4977f2ecd293b4e92d11f93a818b0b6517f0c",
"version" : "3.0.2"
}
},
{
"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 @@
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
Loading