Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust 2fa configuration ui to new api #1244

Merged
merged 14 commits into from
Feb 27, 2023

Conversation

HendrikThePendric
Copy link
Contributor

@HendrikThePendric HendrikThePendric commented Feb 20, 2023

Fixes DHIS2-14555

I found the previous UI version to configure 2FA super confusing, and it didn't seem to actually match the process users were supposed to follow. In particular there were a few point that stood out:

  • To enable 2FA the user needs to scan a QR code in order to add an entry to the Authenticator App. Showing this QR code to users who have already completed 2FA configuration, and now want to disable 2FA is super confusing.
  • Since the Authenticator App is required to enable authentication, it is safe to assume a user already has access to the Authenticator App. So showing installation instructions when the user wants to disable showing these instructions is confusing too.
  • As I found out the hard way, if a user wants to re-enable 2FA, he cannot use the old entry in the Authenticator App but must create a new one. I've added a notification about that.

So I've attempted to make things a bit clearer and whilst doing that I noticed I was restructuring things so much that I might as well bring this section of the app into 2023 and rewrite the lot. So I've upgraded all dependencies and implemented the 2FA section using our new toolbox.

I also added a new item to the sidebar, since this was already on a separate route anyway. I don't see why we wouldn't have it as a separate section.

In any case, a lot for @cooper-joe to review.

And I requested you @tomzemp because this work is loosely related to what you're doing in the login app.

2fa_config_demo.mov

On a general note, mostly for @cooper-joe I think:
As you can see in the screencast, the QR code is not showing once the account has 2FA enabled. This is partly due to a technical limitation: it's only possible to successfully fetch the QR Code image for users that currently have 2FA disabled. Almost all of the time this also makes sense from a practical perspective, but there are some edge cases where it could be useful to allow the user to set things up again. Personally I can actually only think of one use case, which would be when a user has bought a new phone and then logs in with his/her old phone and wants to set up the new phone for 2FA. But even for this use case there are some easy work arounds:

  • Rely on the authenticator app to sync the login across devices (not 100% sure if this is possible)
  • Export the entry from the authenticator app on the old device and import it into the new one
  • Disable 2FA, and then enable it again using the new device

As such, probably the above is not really an issue. I can think of a lot of scenarios where users would effectively get locked out of their accounts, but those problems are more to do with shortcomings of the authenticator app in general. The only cases where it could help to show a QR for users that have 2FA configured already are cases where something goed wrong with the 2FA device (i.e. phone is replaced, authenticator app login record is accidentally deleted) during an active user session. I think these scenarios are too obscure to cater for.

@dhis2-bot
Copy link
Contributor

dhis2-bot commented Feb 20, 2023

🚀 Deployed on https://pr-1244--dhis2-user-profile.netlify.app

@HendrikThePendric HendrikThePendric changed the title fix: adjust qr image source to new 2fa endpoint fix: adjust 2fa configuration ui to new api Feb 22, 2023
Copy link
Contributor

@kabaros kabaros left a comment

Choose a reason for hiding this comment

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

lgtm (code-wise) .. just minor comments

src/account/twoFactor/useTwoFaToggleMutation.js Outdated Show resolved Hide resolved
Comment on lines 54 to 55
userProfileStore.state.twoFaEnabled = nextIsTwoFaEnabled
userProfileStore.setState(userProfileStore.state)
Copy link
Contributor

Choose a reason for hiding this comment

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

are the two needed? the mutation of mutation of userProfileStore directly, and the setState

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not exactly sure, it could be possible to do the following:

userProfileStore.setState({
    ...userProfileStore.state,
    twoFaEnabled: attemptingToEnableTwoFa,
})

But this seems to be the idiomatic way to do it with the old Store in d2-ui: first mutate then call setState with the mutated object as a parameter....

src/account/twoFactor/useTwoFaToggleMutation.js Outdated Show resolved Hide resolved
Copy link
Member

@tomzemp tomzemp left a comment

Choose a reason for hiding this comment

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

I approve from a code perspective, but defer to the UX review. Not really a UX comment, but it would be nice if we consistently called this the same thing throughout (sometimes it's "Two factor authentication", "2-factor authentication", "2 Factor Authentication" etc.,)

src/account/twoFactor/TwoFactorStatus.js Outdated Show resolved Hide resolved
src/account/twoFactor/TwoFactorEnableInstructions.js Outdated Show resolved Hide resolved
src/account/twoFactor/TwoFactorEnableInstructions.js Outdated Show resolved Hide resolved
src/account/twoFactor/TwoFactorEnableInstructions.js Outdated Show resolved Hide resolved
lastActionWasTwoFaDisableSuccess,
setLastActionWasTwoFaDisableSuccess,
] = useState(false)
const { show: showAlert } = useAlert(getAlertMessage, getAlertOptions)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is a big issue (and maybe it's just a UX choice, in which case I would be quite 🙊), but it seems that the use of this showAlert function for all of these different alerts leads to them being replaced by one another rather than stacked on top of one another. So, like if I successfully enable and then disable my 2FA in succession, I only end up with the one success message about disabling...and the text just changes in the existing alert, so it's hard to see as a new alert.

Realistically, I don't think people would be making changes in such rapid succession that it really matters, but I just point it out (if this wasn't already the intent)

Copy link
Contributor Author

@HendrikThePendric HendrikThePendric Feb 23, 2023

Choose a reason for hiding this comment

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

This wasn't a consious decision, but now that I've thought about it a bit more, I think it could possibly make sense to keep it this way for simplicity's sake... I am thinking in particular about the scenario where a user could first get an error and then fixes things and gets a success message. The problem here is that the error is a "sticky" alert, it only hides when the user clicks the close icon. So when the success message comes in, the error message would still show below it, resulting in a very confusing situation. So then I'd end up calling hide() on the error alert before showing a success alert, and then I've pretty much ended up with a more complex implementation of what is effectively identical functionality as we have now.

* fix: twofactor design changes

* chore: fix i18n

---------

Co-authored-by: HendrikThePendric <[email protected]>
@HendrikThePendric HendrikThePendric merged commit 84a04e1 into master Feb 27, 2023
@HendrikThePendric HendrikThePendric deleted the DHIS2-14555-update-2fa-image-source branch February 27, 2023 15:13
dhis2-bot added a commit that referenced this pull request Feb 27, 2023
## [30.3.30](v30.3.29...v30.3.30) (2023-02-27)

### Bug Fixes

* adjust 2fa configuration ui to new api ([#1244](#1244)) ([84a04e1](84a04e1)), closes [#1245](#1245)
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 30.3.30 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants