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

394 waitlist #395

Merged
merged 15 commits into from
May 13, 2024
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@nessprim:registry=https://npm.pkg.github.com/:_authToken=${PLANBY_AUTH_TOKEN}
@nessprim:registry=https://npm.pkg.github.com/
8 changes: 8 additions & 0 deletions config/firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ service cloud.firestore {
match /rsvpCounter-dev/{counterId} {
allow read, write: if isAuthenticated() && isAdmin();
}
match /waitlist/{docId} {
allow read: if isAuthenticated();
allow write: if isAuthenticated() && isAdmin();
}
match /spots/{docId} {
allow read: if isAuthenticated();
allow write: if isAuthenticated() && isAdmin();
}

// Tickets Collection Rules
match /tickets/{ticketId} {
Expand Down
1 change: 0 additions & 1 deletion firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
Expand Down
111 changes: 8 additions & 103 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,109 +385,6 @@ export const logEvent = functions.https.onCall((data, context) => {
}
});

export const verifyRSVP = functions.https.onCall(async (_, context) => {
if (!context.auth) {
throw new functions.https.HttpsError(
"permission-denied",
"Not authenticated"
);
}

functions.logger.info("Verify RSVP called.", { uid: context.auth.uid });

// only verify once
const user = await admin.auth().getUser(context.auth.uid);
if (user.customClaims?.rsvpVerified) {
return {
status: 200,
verified: true,
message: "RSVP already verified.",
};
} else if (user.customClaims?.isTestAccount) {
const counterDocRef = admin
.firestore()
.collection("rsvpCounter-dev")
.doc("counter");
const counterDoc = await counterDocRef.get();

if (counterDoc.exists) {
const count = counterDoc.data()?.count || 0;

if (count >= 5) {
functions.logger.info("RSVP limit reached.", {
uid: context.auth.uid,
});
return {
status: 400,
verified: false,
message: "RSVP limit reached.",
};
} else {
await counterDocRef.set({ count: count + 1 }, { merge: true });
}
} else {
await counterDocRef.set({ count: 1 });
}
await admin.auth().setCustomUserClaims(user.uid, {
...user.customClaims,
rsvpVerified: true,
});

return {
status: 200,
verified: true,
};
} else {
const counterDocRef = admin
.firestore()
.collection("rsvpCounter")
.doc("counter");
const counterDoc = await counterDocRef.get();

if (counterDoc.exists) {
const count = counterDoc.data()?.count || 0;

if (count >= 700) {
functions.logger.info("RSVP limit reached.", {
uid: context.auth.uid,
});
return {
status: 400,
verified: false,
message: "RSVP limit reached.",
};
} else {
await counterDocRef.set({ count: count + 1 }, { merge: true });
}
} else {
await counterDocRef.set({ count: 1 });
}

try {
functions.logger.info("Verifying RSVP. User: " + context.auth.uid);
// add to custom claims
await admin.auth().setCustomUserClaims(user.uid, {
...user.customClaims,
rsvpVerified: true,
});
} catch (e) {
functions.logger.error("Error verifying RSVP.", {
uid: context.auth.uid,
error: (e as Error).message,
});
throw new functions.https.HttpsError(
"internal",
"Service down. 1101"
);
}

return {
status: 200,
verified: true,
};
}
});

async function internalGetTicketData(id: string, extended = false) {
functions.logger.info("Checking for ticket data...");
const ticketDoc = await admin
Expand Down Expand Up @@ -686,3 +583,11 @@ export {
export { createTicket } from "./apple";

export { createPassClass, createPassObject } from "./google";

export {
verifyRSVP,
withdrawRSVP,
joinWaitlist,
// expiredSpotCleanup,
// moveToSpots,
} from "./rsvp";
544 changes: 544 additions & 0 deletions functions/src/rsvp.ts

Large diffs are not rendered by default.

Loading