Skip to content

fix(users): report the recovery code factor when listing user MFA factors - #13531

Merged
HarshMN2345 merged 3 commits into
mainfrom
fix/users-mfa-recovery-code-factor
Sep 8, 2026
Merged

HarshMN2345 merged 3 commits into
mainfrom
fix/users-mfa-recovery-code-factor

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Closes #10927

What does this PR do?

Makes Users MFA factors report whether recovery codes exist, using the same calculation as Account. Previously the omitted recoveryCode key defaulted to false even after codes were generated.

Also returns the documented 201 status when creating user recovery codes, matching the Account route and the existing SDK response definition.

Test Plan

testListMFAFactorsRecoveryCode checks both Users and Account before and after generating recovery codes and asserts the creation status.

…tors

GET /v1/users/:userId/mfa/factors omitted the recoveryCode key entirely, so
the response model fell back to false even for users who had generated
recovery codes. GET /v1/account/mfa/factors computes it from the user's
mfaRecoveryCodes attribute, so the two endpoints disagreed for the same user.

Compute the factor the same way on the users route.
@greptile-apps

greptile-apps Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR aligns the Users MFA APIs with their Account counterparts:

  • Reports recoveryCode as enabled when the user has generated recovery codes.
  • Returns the documented HTTP 201 status when user recovery codes are created.
  • Adds end-to-end coverage for factor reporting before and after recovery-code generation.

Confidence Score: 5/5

The PR appears safe to merge; the MFA factor calculation and creation status are consistent with the corresponding Account behavior and are covered end to end.

No actionable correctness, security, or repository-rule violations remain in the current PR diff.

Important Files Changed

Filename Overview
src/Appwrite/Platform/Modules/Users/Http/Users/MFA/Factors/XList.php Derives the recovery-code factor from the user’s stored recovery-code array and includes it in the MFA factor response.
src/Appwrite/Platform/Modules/Users/Http/Users/MFA/RecoveryCodes/Create.php Changes successful recovery-code creation responses to the documented HTTP 201 status.
tests/e2e/Services/Users/UsersBase.php Verifies Users and Account factor responses before and after recovery-code creation, including the creation status.

Reviews (3): Last reviewed commit: "Merge branch 'main' into fix/users-mfa-r..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/users-mfa-recovery-code-factor (after).

Metric Before After Change
🚀 Requests/sec 195.03 191.87 ⚪ -1.6%
⏱️ Latency P50 89.17 ms 89.23 ms ⚪ +0.1%
⏱️ Latency P95 210.24 ms 215.97 ms ⚪ +2.7%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 89.23 215.97 12,426 191.87 +5.73
Account 182.71 331.92 654 10.8 -0.88
TablesDB 85.17 156.6 6,758 107.84 +4.12
Storage 84.82 180.58 3,270 53.67 -0.39
Functions 139.54 269.84 1,744 29.26 -0.75

Top API waits (after)

API request Max wait (ms)
account.name.update 526.18
functions.variables.update 459.02
account.prefs.update 414.81
storage.buckets.create 414.49
functions.delete 412.95

The SDK method declares STATUS_CODE_CREATED for both of its responses, but the
action never set it, so the route answered 200. The account equivalent sets it,
so the two surfaces disagreed here as well.
@HarshMN2345
HarshMN2345 merged commit de2773c into main Sep 8, 2026
6 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Sep 10, 2026
2 of 4 tasks
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.

users.listMfaFactors() returns incorrect recoveryCode value (inconsistent with account.listMfaFactors())

2 participants