Repository navigation
Conversation
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.
Closes #600 (L-API-4, L-API-5, L-API-6).
Every email and phone code for an account lived in one pair of columns on
users. Starting a flow for an address replaced the code the owner was waiting on. A recovery resume wrote its code over the owner's open request. And a verification and an account claim, each working from a copy of the user loaded earlier in the request, could act on values the other had just changed.What changes
one_time_codestable holds each code hashed, keyed by user, channel and the attempt that asked for it: the ephemeral token's attempt, or the access session. A resend replaces only that attempt's code. A code verifies only on its own attempt, and only while the account still holds the address it was sent to. A caller with no attempt or session scope is refused rather than given a shared slot.FOR UPDATEin the same transaction before the verification is applied (withLockedUser). Magic link and OAuth claims take the same lock. Claiming an unverified account drops the codes other attempts requested before the address was proven.startRecoveryalways opens its ownawaiting_coderequest. A resume records the request it resumes (resumesRequestId) and no longer writes onto the owner's.verifyRecoveryreads onlyawaiting_coderequests.Migration
20261204120000-add-one-time-codesadds the table andaccount_recovery_requests."resumesRequestId". It was run up, down and up against a scratch database. The old code columns onusersstay in place and are no longer read, so an instance on the previous release keeps working during a rolling deploy. Two cases cross releases:Contract (minor changeset, breaking)
No route, schema or status code changes. A code now verifies only on the attempt that requested it. The server adapters keep a single ephemeral cookie per browser, so a second sign-in there already replaced the first code, and the adapters see no change. A direct client that starts a new attempt must send a new code on it.
Residual
Tests
tests/postgres/oneTimeCodes.spec.ts):