Skip to content

Conversation

@dhairyashiil
Copy link

Proposed changes (including videos)

This pull request addresses the issue where the UI does not immediately reflect changes in the 2FA status (both TOTP and email) after enabling or disabling them. The state is updated correctly in the backend, but the frontend UI fails to re-render, requiring a page reload to display the updated status. The fix ensures that the UI reflects the new 2FA status immediately after the change is made without requiring a page reload.

2FA TOTP Video:

2fa.totp.mp4

2FA Email Video:

2fa.email.mp4

Issue(s)

Closes #35184

Steps to test or reproduce

  1. Go to the 2FA settings page (Profile -> Security).
  2. Enable or disable 2FA for either TOTP or email.
  3. Observe that the UI now updates immediately to reflect the new status without requiring a page reload.
  4. Verify that the UI correctly reflects the changes after each action, ensuring the status is in sync with the backend.

Further comments

To resolve the issue, I added a state update and re-render logic to the UI component after enabling or disabling 2FA. This ensures that the UI synchronizes with the backend immediately. No page reload is needed after the action is performed.

@dhairyashiil dhairyashiil requested a review from a team as a code owner February 11, 2025 20:04
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Feb 11, 2025

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Feb 11, 2025

🦋 Changeset detected

Latest commit: f799be9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 35 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/freeswitch Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/license Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/models Patch
@rocket.chat/network-broker Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/instance-status Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@casalsgh casalsgh requested a review from tiagoevanp February 12, 2025 18:50
'@rocket.chat/meteor': patch
---

Written code to update UI to immediately reflect 2FA status change after enabling/disabling TOTP/email
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Written code to update UI to immediately reflect 2FA status change after enabling/disabling TOTP/email
Fixes 2FA status change not reflected in UI when enabling/disabling TOTP/emailcode

Copy link
Author

Choose a reason for hiding this comment

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

Thank you, Sir. And yes, from next time, I will write the changeset summary in the manner you mentioned.

const user = useUser();

const isEnabled = user?.services?.email2fa?.enabled;
const [isEnabled, setIsEnabled] = useState(user?.services?.email2fa?.enabled);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, can you change the isEnabled and setIsEnabled for something like isEmail2faEnabled/setIsEmail2faEnabled for a better const description name? Thanks!

Copy link
Author

Choose a reason for hiding this comment

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

Yes, Sir. I have renamed it to isEmail2faEnabled/setIsEmail2faEnabled. Thank you, and from now on, I will keep this in mind while defining and naming variables.


const handleEnable = useCallback(async () => {
await enable2faAction();
setIsEnabled(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

How about to use the same technique used into TOTP file for "is enabling" state control? This will avoid any double click into the action button if a connection drop/delay happens... ;)

Copy link
Author

Choose a reason for hiding this comment

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

Yes, Sir. Thank you for the suggestion. I’ve added a registeringEmail2fa state to track the action process, preventing multiple clicks if there's a delay or connection issue. I’ve also included error handling, and right now, I'm only dispatching the error as a toast message, assuming we get an error message if enabling/disabling email 2FA fails.

If you prefer a different approach, please let me know, and I’ll make the changes accordingly

@tiagoevanp
Copy link
Contributor

Thanks for the contribution! Small but important catches.

@yash-rajpal
Copy link
Member

yash-rajpal commented Feb 12, 2025

This solution fixes the issue at hand but isn't a proper fix.

This issue arises because the user's info isn't synced between the client and server. After enabling/disabling the 2FA options, the server is updated but the client still has old info. A better fix for this would be to fix this root problem, syncing the data between client and server.

Please check my implementation on PR #35188 and feel free to ask any questions that you might have.

Thanks for the contribution. 🚀

@dhairyashiil
Copy link
Author

This solution fixes the issue at hand but isn't a proper fix.

This issue arises because the user's info isn't synced between the client and server. After enabling/disabling the 2FA options, the server is updated but the client still has old info. A better fix for this would be to fix this root problem, syncing the data between client and server.

Please check my implementation on PR #35188 and feel free to ask any questions that you might have.

Thanks for the contribution. 🚀

Yes, Sir, I will check your PR, and I will definitely ask you questions if I don't understand something. Thank you for this. 🙏

@yash-rajpal
Copy link
Member

Fixed by #35188

Thanks for the contribution. 🚀

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.

Bug: UI not reflecting 2FA totp and email status change

3 participants