Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
nriedman committed Apr 15, 2024
1 parent a08aa7e commit 4a31f4d
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ exports.checkInvitationCode = onCall(async (request) => {
const invitationCodeDoc = await invitationCodeRef.get();

if (!invitationCodeDoc.exists || (invitationCodeDoc.data().used)) {
logger.warn(`Invitation code not found or already used: ${invitationCode}`);
throw new https.HttpsError("not-found", "Invitation code not found or already used.");
}

const userStudyRef = firestore.doc(`users/${userId}`);
const userStudyDoc = await userStudyRef.get();

if (userStudyDoc.exists) {
logger.warn(`User (${userId}) is already enrolled in the study.`);
throw new https.HttpsError("already-exists", "User is already enrolled in the study.");
}

Expand Down

0 comments on commit 4a31f4d

Please sign in to comment.