Skip to content

Commit

Permalink
feat(client): add invite code validity check
Browse files Browse the repository at this point in the history
  • Loading branch information
waddaboo committed Nov 4, 2024
1 parent 38457e3 commit 8e9dd3d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions apps/client/src/api/bandadaAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ export async function addMemberByInviteCode(
}
}

export async function checkInvite(
inviteCode: string,
groupId: string
): Promise<boolean> {
try {
return await request(
`${API_URL}/invites/check/${inviteCode}/group/${groupId}`
)
} catch (error: any) {
console.error(error)

if (error.response) {
alert(error.response.statusText)
} else {
alert("Some error occurred!")
}

return false
}
}

export async function redeemInvite(
inviteCode: string,
groupId: string
Expand Down
11 changes: 11 additions & 0 deletions apps/client/src/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ export default function HomePage(): JSX.Element {
return
}

const isValid = await bandadaAPI.checkInvite(
inviteCode,
invite.group.id
)

if (!isValid) {
setLoading(false)
alert("Invalid invite code")
return
}

const signer = library.getSigner(account)

const message = `Sign this message to generate your Semaphore identity.`
Expand Down

0 comments on commit 8e9dd3d

Please sign in to comment.