MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / consumeInviteCode

Function consumeInviteCode

apps/host-selfhost/src/auth/invites.ts:142–153  ·  view source on GitHub ↗
(
  client: Client,
  code: string,
  by: { usedBy: string; usedByEmail: string },
)

Source from the content-addressed store, hash-verified

140// Mark a code consumed. The `used_at IS NULL` guard makes this the single-use
141// gate even under a race: rowsAffected === 0 means someone redeemed it first.
142export const consumeInviteCode = async (
143 client: Client,
144 code: string,
145 by: { usedBy: string; usedByEmail: string },
146): Promise<boolean> => {
147 const result = await client.execute({
148 sql: `UPDATE invite_code SET used_by = ?, used_by_email = ?, used_at = ?
149 WHERE code = ? AND used_at IS NULL`,
150 args: [by.usedBy, by.usedByEmail, new Date().toISOString(), code.trim().toUpperCase()],
151 });
152 return result.rowsAffected > 0;
153};

Callers 1

makeAuthOptionsFunction · 0.90

Calls 1

executeMethod · 0.65

Tested by

no test coverage detected