Skip to content

Commit

Permalink
Merge pull request #4 from TLX-Protocol/add-partner-codes
Browse files Browse the repository at this point in the history
Add Support for Partner Codes
  • Loading branch information
chase-manning authored Jan 30, 2024
2 parents 7ee7778 + bec72f9 commit 36fc60d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions functions/src/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { generateAndSaveInviteCodes, useCode, userExists, usernameExists } from
import { getUserAddress, validateParams } from "./utils";

const requiredKeys = ["twitterCode", "discordCode", "signature", "inviteCode"];
const partnerCodes = ["kirbycrypto"];

async function getTwitterUsername(code: string, secrets: Secrets): Promise<string> {
try {
Expand Down Expand Up @@ -49,12 +50,15 @@ export default async function registrationHandler(request: Request, secrets: Sec
}

// Validating invite code
const codeSnapshot = await db.ref("invites").child(params.inviteCode).get();
if (!codeSnapshot.exists()) {
throw new APIError("Invalid invite code");
}
if (codeSnapshot.val().used) {
throw new APIError("Code already used");
const isPartner = partnerCodes.includes(params.inviteCode);
if (!isPartner) {
const codeSnapshot = await db.ref("invites").child(params.inviteCode).get();
if (!codeSnapshot.exists()) {
throw new APIError("Invalid invite code");
}
if (codeSnapshot.val().used) {
throw new APIError("Code already used");
}
}

// Validating Twitter
Expand Down

0 comments on commit 36fc60d

Please sign in to comment.