Repository navigation
feat(auth): read how many MFA recovery codes the signed-in user has left - #610
Merged
Merged
Conversation
Tr00d
force-pushed
the
feat/auth.mfa_recovery_codes.get_status
branch
from
October 30, 2026 13:32
cb36efc to
05e4bb1
Compare
Tr00d
marked this pull request as ready for review
October 30, 2026 13:37
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.
Summary
A signed-in user can read how many of their MFA recovery codes remain unused, or learn that they have none.
Capability:
auth.mfa_recovery_codes.get_status(MFA Recovery Codes Get Status). There is no capability spec for it; the contract is the auth OpenAPIGET /factors/recovery-codes.Public API
Behavior
Operation:
GET /factors/recovery-codeswith the session's access token asAuthorization: Bearer, plus the API key header. Works at AAL1 and AAL2, and whether or not the auth server enables recovery-code enroll or verify.Checks before the wire: an offline client throws
GotrueException(ReasonOffline). No session, or a session without an access token, throwsGotrueException(ReasonNoSessionFound). Neither sends a request.Output:
{ id, type, total, remaining }maps toRecoveryCodesStatus { FactorId, Total, Remaining }.typeis alwaysrecovery_code, so it is not surfaced.mfa_factor_not_found(the user never generated codes) returnsnull.GotrueException.Failures: any other rejection throws
GotrueExceptionwith the server'sErrorCode:no_authorizationfor an anonymous user;bad_jwtfor an expired token.Reasonfollows the existingerror_codeand status mapping. NoFailureHint.Reasonmember is added.Cancellation: the token reaches the HTTP call.
State: nothing stored, cleared or emitted. The operation runs under a new
gotrue.get_recovery_codes_statusdomain span that parents the HTTP span.Deviations from supabase-js
auth.experimental.recoveryCodesis set. Here the XML docs say the feature is experimental on the auth server.null. auth-js returns themfa_factor_not_founderror. Not having codes is a status the caller renders, not a failure._useSessionrefreshes an expired session first. This SDK uses the current access token, likeGetUserIdentitiesAsync, so an expired token is rejected withbad_jwt.Tests
RecoveryCodesStatusTestsnull. An anonymous user is rejected withno_authorization.RecoveryCodesStatusContractTestsnullonmfa_factor_not_found; throws on another 404 and on a 200 without a body;bad_jwt; Offline and NoSessionFound before the wire; cancellation; no context capture.ObservabilityContractTestsNo approval test, because a GET has no request body.
Changed-line coverage: 100% (40 lines). Mutation: 14/14 on changed lines (10 killed, 4 timeout), 0 survivors.
Notes
GOTRUE_MFA_RECOVERY_CODES_ENROLL_ENABLEDdefaults to false, and the Supabase CLI (2.120 and 2.122) exposes noconfig.tomlsetting for it. So the stack cannot create recovery codes, and the enrolled status is pinned at the contract tier. Add the E2E once the CLI exposes the recovery-codes enroll setting.no_authorizationmaps toReason.AdminTokenRequiredthrough the existing table, which is misleading for this case. It is unchanged here;ErrorCodecarries the precise code.