mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5216] [Bug]: 2FA Becomes Disabled After Page Refresh #3657
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#3657
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @aLIEz-xue on GitHub (Jun 12, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5216
Describe the bug
After successfully enabling Two-Factor Authentication (2FA), refreshing the page causes the 2FA toggle button to display as disabled. In addition, 2FA is no longer effective and users can log in without OTP verification.
How to reproduce the problem
Expected behavior
No response
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.3.0
Xray-core version
No response
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 24.04.4 LTS
Which parts of the panel are affected?
No response
Browser (only if it is a UI bug)
No response
Is the panel behind a reverse proxy or CDN?
None
Before submitting
@github-actions[bot] commented on GitHub (Jun 12, 2026):
The reported behavior is caused by two distinct bugs. The steps in this issue trigger the first one; the second is a related latent issue worth noting.
Bug 1 — 2FA toggle does not auto-save (root cause of this report)
Confirmed in
frontend/src/pages/settings/SecurityTab.tsxandfrontend/src/api/queries/useAllSettings.ts.When the 2FA toggle is clicked,
toggleTwoFactor()generates a TOTP secret locally, opens the confirmation modal, and — after the user scans the QR code and enters a correct code — calls:updateSettingupdates only the in-memory React draft. The change is not sent to the backend until the user explicitly clicks the Save button at the top of the Settings page (the same button used to persist port, base path, Telegram settings, etc.). A page refresh before that click discards the unsaved draft, re-fetches server state (POST /panel/api/setting/all), and restorestwoFactorEnable: false— which is also why logging in without OTP continues to work, because the backend setting was never changed.The success toast that appears after the modal is confirmed ("Two-factor authentication has been enabled") fires before the network save, making it appear that the operation is complete.
Workaround (immediate): after confirming the TOTP modal, scroll to the top of the Settings page and click Save before navigating away or refreshing.
Bug 2 — Changing credentials via the web UI silently disables 2FA
Confirmed in
internal/web/service/panel/user.go,UpdateUser(), lines 122–130:Any call to the
/panel/api/setting/updateUserendpoint (Settings → Security → Admin credentials form) unconditionally clearstwoFactorEnableandtwoFactorTokenin the database if 2FA is currently enabled. This did not trigger in the steps above because the credential change (step 3) occurred before 2FA was enabled (step 5). However, a user who enables and saves 2FA and then later changes their username or password will have 2FA silently erased on the next credential update. A closely related variant of this bug (in thex-ui.shCLI reset path) was fixed in #4758.To confirm which bug applies to your situation: after going through steps 1–5 exactly as described, check whether you clicked the Save button in the header before refreshing. If you did not, Bug 1 is the cause. If you did click Save, please share the panel's response (success toast or error) at that point, as that would indicate a different code path.
This reply was generated automatically; a maintainer may follow up.