Skip to content

Commit

Permalink
docs(docs): check if the code has been redeemed
Browse files Browse the repository at this point in the history
  • Loading branch information
vplasencia committed Dec 5, 2024
1 parent fba79cb commit e7ebb69
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions apps/docs/docs/tutorials/api-sdk/onchain-invites.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
sidebar_position: 2
title: On-chain invites
title: On-chain group invites
---

import Tabs from "@theme/Tabs"
Expand Down Expand Up @@ -122,9 +122,15 @@ const group = await semaphore.getGroup(groupId, {
})

const invite = await apiSdk.getInvite(inviteCode)
const apiKey = "your-api-key"

await semaphore.addMember(group.id, memberId)
await apiSdk.redeemInvite(inviteCode, invite.group.id)
if(invite.isRedeemed) {
throw new Error(`Invite code '${inviteCode}' has already been redeemed`)
} else {
await semaphore.addMember(group.id, memberId)

await apiSdk.redeemInvite(inviteCode, invite.group.id, apiKey)
}
```

## Full example
Expand Down Expand Up @@ -164,9 +170,14 @@ const associatedGroup = apiSdk.createGroup(groupCreationDetails, apiKey)
// generate invite code with the associated group id
const invite = await apiSdk.createInvite(associatedGroup.id, apiKey)

// add member to on-chain group
await semaphore.addMember(onchainGroupId, memberId)
// check if the invite code has been redeemed
if(invite.isRedeemed) {
throw new Error(`Invite code '${invite.code}' has already been redeemed`)
} else {
// add member to on-chain group
await semaphore.addMember(onchainGroupId, memberId)

// redeem the invite code after successfully adding the member to the on-chain group
await apiSdk.redeemInvite(invite.code, associatedGroup.id)
// redeem the invite code after successfully adding the member to the on-chain group
await apiSdk.redeemInvite(invite.code, associatedGroup.id, apiKey)
}
```

0 comments on commit e7ebb69

Please sign in to comment.