Skip to content

Fix TOTP verify button after resetting authenticator app - #979

Open
lakrisgubben wants to merge 2 commits into
WordPress:masterfrom
lakrisgubben:fix-978
Open

Fix TOTP verify button after resetting authenticator app#979
lakrisgubben wants to merge 2 commits into
WordPress:masterfrom
lakrisgubben:fix-978

Conversation

@lakrisgubben

@lakrisgubben lakrisgubben commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

What?

Clicking "Reset authenticator app" replaces the contents of #two-factor-totp-options via AJAX, but the click handlers for .totp-submit and .button.reset-totp-key were bound directly to elements present at page load. The new "Verify" button never got those handlers, so clicking it fell back to a native form submit instead of the AJAX request, triggering the browser's unsaved changes prompt.

Fixes #978

Why?

Making sure users can easily switch authenticator app.

How?

Delegate both handlers off the persistent #two-factor-totp-options container so they keep working after its contents are replaced.

Use of AI Tools

AI assistance: Yes
Tool: Claude code
Model: Sonnet 5
Used for: Initial finding of what code triggered the bug, wording on issue.

Testing Instructions

  1. Go to your user profile screen with TOTP already enabled.
  2. Click "Reset authenticator app" (this AJAX-resets the key and re-renders a fresh QR code + form via wp.apiRequest).
  3. Enter a valid code from your authenticator app in the new "Authentication Code" field.
  4. Click "Verify" immediately (no page reload in between).

Before this PR it wouldn't work, with this PR it works.

Changelog Entry

Fixed – Clicking TOTP verify button after resetting authenticator app

Open WordPress Playground Preview

Clicking "Reset authenticator app" replaces the contents of #two-factor-totp-options via AJAX, but the click handlers for .totp-submit and .button.reset-totp-key were bound directly to elements present at page load. The new "Verify" button never got those handlers, so clicking it fell back to a native form submit instead of the AJAX request, triggering the browser's unsaved changes prompt.

Delegate both handlers off the persistent #two-factor-totp-options container so they keep working after its contents are replaced.

Fixes WordPress#978
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: lakrisgubben <lakrisgubben@git.wordpress.org>
Co-authored-by: masteradhoc <masteradhoc@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change directly addresses the reported issue by delegating the event handlers to a persistent container without introducing behavioral regressions in the reviewed code.

Pull request overview

This PR fixes the TOTP “Verify” button behavior on the user profile screen after “Reset authenticator app” replaces the TOTP options markup via AJAX. It updates the admin JS to use delegated event handlers so the click logic continues to work for dynamically replaced buttons.

Changes:

  • Switched the TOTP “Verify” click handler to delegated binding on #two-factor-totp-options.
  • Switched the “Reset authenticator app” click handler to delegated binding on #two-factor-totp-options.
File summaries
File Description
providers/js/totp-admin.js Uses delegated click handlers so “Verify” and “Reset authenticator app” continue to work after the options area is re-rendered via AJAX.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@masteradhoc masteradhoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR @lakrisgubben!
I've just validated the fix locally and on WP Playground and it fixes the noted issue perfectly.

@masteradhoc

Copy link
Copy Markdown
Collaborator

@georgestephanis this small bugfix fine for you as well? then it would be ready to merge

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.

"Verify" button stops working after clicking "Reset authenticator app" without a page reload

3 participants