Skip to content

fix(auth): record usedByUser on invite redemption (stacked on #28)#35

Draft
Sarah Simionescu (sarahsimionescu) wants to merge 1 commit into
feat/trustclaw-invite-only-signupfrom
fix/invite-usedbyuser
Draft

fix(auth): record usedByUser on invite redemption (stacked on #28)#35
Sarah Simionescu (sarahsimionescu) wants to merge 1 commit into
feat/trustclaw-invite-only-signupfrom
fix/invite-usedbyuser

Conversation

@sarahsimionescu

@sarahsimionescu Sarah Simionescu (sarahsimionescu) commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Draft — stacked on top of #28. Base is a mirror of #28's head (feat/trustclaw-invite-only-signup), so the diff below is only the fix. After #28 merges into main, retarget this PR's base to main, then mark it ready.

What

Follow-up fix for #28. In #28's user.create.before hook, the invite code is claimed (sets usedAt) before the new user's id exists, so usedByUser was left null and the admin invite list at /dashboard/admin/invites couldn't show who redeemed a code.

This adds a user.create.after hook that backfills usedByUser once the user is created. Single-use enforcement is unchanged — still keyed off the atomic usedAt claim in the before hook.

Why it's safe / scoped

  • No-ops entirely when ALLOW_OPEN_SIGNUP is true (the default), so open-signup and the default Vercel template are unaffected.
  • Purely additive: one after hook, no schema change, no change to the before-hook claim logic.

Verified locally (real app, isolated Postgres + Redis)

  • ✅ Invite-only signup with a valid code → succeeds, and usedByUser now equals the created user's id (bound_correctly = t).
  • ✅ Reusing a spent code → 400 INVALID_OR_EXPIRED_INVITE_CODE (single-use intact).
  • ✅ Default mode (ALLOW_OPEN_SIGNUP unset) → signup with no code still works; the after hook no-ops.

🤖 Generated with Claude Code

The user.create.before hook claims the invite code (sets usedAt) before
the new user's id exists, so usedByUser was left null and the admin invite
list couldn't show who redeemed a code. Add an after hook to backfill
usedByUser once the user is created. Single-use enforcement is unchanged
(still keyed off usedAt in the atomic before-hook claim).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sarahsimionescu Sarah Simionescu (sarahsimionescu) changed the base branch from main to feat/trustclaw-invite-only-signup June 3, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant