-
Notifications
You must be signed in to change notification settings - Fork 9
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
Track if backup codes have been verified #257
Conversation
Without this, generating codes for the first time, then clicking `Back`, then visiting the Backup Codes screen would generate another set of codes. It should instead render the `Manage` component, since the first setup saved the codes to the database.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a better solution that doesn't appear to impact the user experience 👍 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Thanks for the fix!
@@ -61,6 +61,7 @@ function Main( { userId } ) { | |||
} = user; | |||
const [ globalNotice, setGlobalNotice ] = useState( '' ); | |||
const [ error, setError ] = useState( '' ); | |||
const [ backupCodesVerified, setBackupCodesVerified ] = useState( true ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just add some notes about my testing process for the logic here for future reference.
Initially, I thought of setting this value to false
during testing.
And setting this part to true
only when the Back
button on the backup-codes screen is pressed.
However, there are two issues with this approach:
- Currently, within
ScreenLink
, we can't determine which screen theBack
button is pressed from. - Even if we could determine that, since the value is set to
true
only when theBack
button on the backup-codes screen is pressed, this condition with! backupCodesVerified
would betrue
again when the user exits the account screen (whenMain
is unmounted) and returns to the account screen, leading to another unexpected re-generation of backup-codes.
So, the current logic is that every time the ScreenLink
component is pressed, it will execute setBackupCodesVerified( true );
. I believe this is an acceptable compromise, especially since this workaround was put in place primarily due to the side-effects of two-factor/#507
.
One of the commits from #245 was reverted in 03ab804. This achieves the same goal as that commit, but in a way that doesn't have the side-effects that it did.
It takes a similar conceptual approach to #221, where it keeps track of whether or not the codes have been verified. That can't be done in
BackupCodes
, though, because the state would get lost when clickingBack
. It also can't do it in local storage, since that wouldn't persist across browsers.This approach keeps the state in
Main
so that it won't get lost, but it ultimately relies on the database as the canonical source of truth. The user record is refreshed after saving the codes so that the system knows the user has them, but it also has the state of whether or not they've verified them. The combination of those two lets us achieve the original goal but without the side effects.I also added some defensive code to the Password component. That's not necessary for the main fix here, it's just related because the need for it was exposed by the previous bug.
Testing
Back
. The Backup Codes status will show that it's activeAlso test that flow but with clicking
Finished
, and do some general tests to make sure there aren't any side-effects.