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: clean up two factor #26901

Merged
merged 9 commits into from
Dec 17, 2024
Merged

fix: clean up two factor #26901

merged 9 commits into from
Dec 17, 2024

Conversation

zlwaterfield
Copy link
Contributor

@zlwaterfield zlwaterfield commented Dec 13, 2024

Changes

There's currently a race condition introduced here https://github.com/PostHog/posthog/pull/26813/files that may double trigger the set up call and make it so the QR code being rendered doesn't match the token stored in the session.

This PR also cleans up the set up code so the modal is only rendered once and not in 3 locations.

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

It doesn't have an impact.

How did you test this code?

Manually.

I'd love for the review to pull this locally and test all 3 cases to make sure it's all working

  1. Set up 2FA from profile
  2. Set up 2FA from members list (click on 2FA not enabled tag)
  3. Turn on the 2FA enforcement on the organization, reload and set it up via the forced modal.

Copy link
Contributor

github-actions bot commented Dec 13, 2024

Size Change: 0 B

Total Size: 1.11 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 1.11 MB

compressed-size-action

@surbhi-posthog
Copy link
Contributor

I see failing tests, so I'm just going to re-run them to see if they pass

Copy link
Member

@raquelmsmith raquelmsmith left a comment

Choose a reason for hiding this comment

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

I was wondering if a race condition would happen here..

Approving because my one comment is non-blocking but it might be better to change it up a bit.

actions.loadStatus()

if (values.user && values.user.organization?.enforce_2fa && !values.user.is_2fa_enabled) {
actions.openTwoFactorSetupModal(true)
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this is confusing because the modal could be already open (if it's forced open), yet we're saying here to open the modal. but instead of it opening the modal, what's actually happening is this side-effect where startSetup is called.

I think it technically works but it's confusing and took me a bit to understand the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On load, this will check the user's status and open the modal if the user doesn't have 2fa but is required to have it. This will only be called when the application is first loaded because it's rendered in global modals. The modal can't already be opened because this will be called before the UI renders a button to open it manually. This is the only place that force opens the modal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Curious - what is confusing about it? Do you have thoughts on a different way it could be done?

@surbhi-posthog
Copy link
Contributor

Tested locally for the three cases and everything looks good. I'm just trying to figure out what's going on with these failing tests so I'm re-basing and rerunning them since they seem unrelated to these changes.

@surbhi-posthog
Copy link
Contributor

Test recording
Uploading Screen Recording 2024-12-16 at 2.17.02 PM.mov…

Copy link
Contributor

@surbhi-posthog surbhi-posthog left a comment

Choose a reason for hiding this comment

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

Tested locally and it worked well

@zlwaterfield
Copy link
Contributor Author

It will pass locally but still need get the requests stubbed or else CI won't pass.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@zlwaterfield zlwaterfield merged commit 27b3d2e into master Dec 17, 2024
96 checks passed
@zlwaterfield zlwaterfield deleted the zach/two-factor-fixes branch December 17, 2024 03:41
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.

4 participants