Repository navigation
Keep account emails unique and look up logins by email claim - #199
Open
NetworkTheoryAppliedResearchInstitute wants to merge 2 commits into
Open
NetworkTheoryAppliedResearchInstitute wants to merge 2 commits into
NetworkTheoryAppliedResearchInstitute wants to merge 2 commits into
Conversation
Registration and POST /users now write a UserEmails claim, keyed by the trimmed, lower-cased email, together with the user in one DynamoDB transaction. The claim's attribute_not_exists condition makes a second account for the same email fail with 409, including concurrent requests, and the user put is conditional on a new id so no existing account is replaced. Login reads the claim and fetches that user by id instead of taking the first row of one unpaginated scan. Add scripts/claim-user-emails.js to claim the emails of existing accounts. It only adds claims; an email shared by several accounts stays unclaimed and is reported by id, so login does not choose between them. Document the table, permissions and rollout order in backend/README.md and note the private table in CONFORMANCE.md. Expose transactWrite through the DynamoDB wrapper. Tests cover duplicate registration across case and spacing, a race in which both requests reach the write before either commits, simulated condition failures, refusing to replace an existing id, consistent reads at login, login beyond the first scan page, existing duplicates, the backfill's pagination and re-runs, and the SDK's cancellation reasons. Signed-off-by: Jodson Graves <info@ntari.org> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The backfill left an email shared by several existing accounts with no claim, so a later registration could take it. It now writes a claim that names no account (needsReview: true): registration is refused, and login finds no owner until an operator replaces the claim with the owner's userId. Login treats such a claim as no account. Rows imported from a federation peer (sourceNodeId) are never claimed. The README now describes both, and notes that rows imported before peers were marked carry no such field. Tests: a shared email gets the held claim, a new registration for it is refused, login finds no owner, and a re-run leaves the hold in place; a peer-imported row is never claimed. Both fail against the previous model. Full suite: node:test 67/67, Jest 54/54. Signed-off-by: Jodson Graves <info@ntari.org> Co-Authored-By: Claude Opus 5.5 <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.
Registration (
/api/auth/register,POST /users) now writes aUserEmailsclaim (trimmed, lower-cased email to user id) and the user in one DynamoDB transaction. Both writes are conditional: a taken email returns 409 and an existing id is never overwritten. Login reads the claim, then the user by id, instead of the first row of a single scan.Operator steps before deploy
UserEmails(hash keyemail; command inbackend/README.md) and grantGetItem/PutItemon it.node scripts/claim-user-emails.js, deploy, then run it again.Accounts that already share an email stay unclaimed and are listed by id; they cannot log in until an operator chooses the owner.
Tests: duplicate registration across case and spacing, a held-write race, simulated condition failure, no overwrite by id, login beyond the first scan page, existing duplicates, backfill pagination.
Overlaps #197 (
authRoutes.js,userRoutes.js; same 409 wording) and #194 (userRoutes.js).🤖 Generated with Claude Code