{"record":{"id":"658e77d89b7ab5b2","repo":"appwrite/appwrite","slug":"user-recovery-codes-already-exists-658e77","errorCode":"user_recovery_codes_already_exists","errorMessage":"The current user already generated recovery codes and they can only be read once for security reasons.","messagePattern":"The current user already generated recovery codes and they can only be read once for security reasons\\.","errorType":"exception","errorClass":"Appwrite\\Extend\\Exception","httpStatus":409,"severity":"error","filePath":"src/Appwrite/Platform/Modules/Users/Http/Users/MFA/RecoveryCodes/Create.php","lineNumber":92,"sourceCode":"            ->param('userId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'User ID.', false, ['dbForProject'])\n            ->inject('response')\n            ->inject('dbForProject')\n            ->inject('queueForEvents')\n            ->callback($this->action(...));\n    }\n\n    public function action(string $userId, Response $response, Database $dbForProject, Event $queueForEvents): void\n    {\n        $user = $dbForProject->getDocument('users', $userId);\n\n        if ($user->isEmpty()) {\n            throw new Exception(Exception::USER_NOT_FOUND);\n        }\n\n        $mfaRecoveryCodes = $user->getAttribute('mfaRecoveryCodes', []);\n\n        if (!empty($mfaRecoveryCodes)) {\n            throw new Exception(Exception::USER_RECOVERY_CODES_ALREADY_EXISTS);\n        }\n\n        $mfaRecoveryCodes = Type::generateBackupCodes();\n        $user->setAttribute('mfaRecoveryCodes', $mfaRecoveryCodes);\n        $dbForProject->updateDocument('users', $user->getId(), new Document(['mfaRecoveryCodes' => $mfaRecoveryCodes]));\n\n        $queueForEvents->setParam('userId', $user->getId());\n\n        $document = new Document([\n            'recoveryCodes' => $mfaRecoveryCodes\n        ]);\n\n        $response->dynamic($document, Response::MODEL_MFA_RECOVERY_CODES);\n    }\n}\n","sourceCodeStart":74,"sourceCodeEnd":108,"githubUrl":"https://github.com/appwrite/appwrite/blob/a1d520eea492ebd1da1ef2dc8db5b2b34e277dce/src/Appwrite/Platform/Modules/Users/Http/Users/MFA/RecoveryCodes/Create.php#L74-L108","documentation":"Error \"The current user already generated recovery codes and they can only be read once for security reasons.\" thrown in appwrite/appwrite.","triggerScenarios":"Thrown at src/Appwrite/Platform/Modules/Users/Http/Users/MFA/RecoveryCodes/Create.php:92 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Regenerate recovery codes via the update recovery codes endpoint.","Recovery codes can only be viewed once; store them securely when generated."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a1d520eea492ebd1da1ef2dc8db5b2b34e277dce","analyzedAt":"2026-08-18T21:34:56.994Z","contentChangedAt":"2026-08-18T21:34:56.994Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}