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

Function findRedeemableCode

apps/host-selfhost/src/auth/invites.ts:125–138  ·  view source on GitHub ↗
(
  client: Client,
  code: string,
)

Source from the content-addressed store, hash-verified

123
124// A code is redeemable when it exists, is unused, and is unexpired.
125export const findRedeemableCode = async (
126 client: Client,
127 code: string,
128): Promise<InviteCodeRow | null> => {
129 const result = await client.execute({
130 sql: "SELECT * FROM invite_code WHERE code = ? AND used_at IS NULL",
131 args: [code.trim().toUpperCase()],
132 });
133 const raw = result.rows[0];
134 if (!raw) return null;
135 const row = toRow(raw);
136 if (row.expiresAt && Date.parse(row.expiresAt) < Date.now()) return null;
137 return row;
138};
139
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.

Callers 2

makeAuthOptionsFunction · 0.90
handlers.tsFile · 0.90

Calls 2

toRowFunction · 0.85
executeMethod · 0.65

Tested by

no test coverage detected