fix(auth): record usedByUser on invite redemption (stacked on #28)#35
Draft
Sarah Simionescu (sarahsimionescu) wants to merge 1 commit into
Draft
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Follow-up fix for #28. In #28's
user.create.beforehook, the invite code is claimed (setsusedAt) before the new user's id exists, sousedByUserwas left null and the admin invite list at/dashboard/admin/invitescouldn't show who redeemed a code.This adds a
user.create.afterhook that backfillsusedByUseronce the user is created. Single-use enforcement is unchanged — still keyed off the atomicusedAtclaim in thebeforehook.Why it's safe / scoped
ALLOW_OPEN_SIGNUPis true (the default), so open-signup and the default Vercel template are unaffected.afterhook, no schema change, no change to thebefore-hook claim logic.Verified locally (real app, isolated Postgres + Redis)
usedByUsernow equals the created user's id (bound_correctly = t).400 INVALID_OR_EXPIRED_INVITE_CODE(single-use intact).ALLOW_OPEN_SIGNUPunset) → signup with no code still works; the after hook no-ops.🤖 Generated with Claude Code