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

Only show the reauth modal if a primary 2FA provider is enabled #161

Merged
merged 6 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions settings/src/components/account-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function AccountStatus() {
verified your backup codes for two-factor authentication.`;

return (
<>
<div className={ 'wporg-2fa__account-status' }>
<SettingStatusCard
screen="password"
status="enabled"
Expand Down Expand Up @@ -72,7 +72,7 @@ export default function AccountStatus() {
bodyText={ backupBodyText }
disabled={ ! backupCodesEnabled }
/>
</>
</div>
);
}

Expand Down
24 changes: 13 additions & 11 deletions settings/src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ function Main( { userId } ) {
return <Spinner />;
}

const { '2fa_available_providers': availableProviders, '2fa_revalidation': revalidation } =
record;
// Check that there are providers, and that there isn't only backup codes.
const hasPrimaryProvider =
!! availableProviders.length &&
! (
availableProviders.length === 1 && availableProviders[ 0 ] === 'Two_Factor_Backup_Codes'
);

let screenContent = (
<Card>
<CardHeader className="wporg-2fa__navigation" size="xSmall">
Expand All @@ -156,22 +165,15 @@ function Main( { userId } ) {
);

if ( 'account-status' === screen ) {
screenContent = (
<div className={ 'wporg-2fa__account-status' }>
<AccountStatus />
</div>
);
screenContent = <AccountStatus />;
} else if (
twoFactorRequiredScreens.includes( screen ) &&
userRecord.record[ '2fa_available_providers' ] &&
userRecord.record[ '2fa_revalidation' ] &&
userRecord.record[ '2fa_revalidation' ].expires_at <= new Date().getTime() / 1000
hasPrimaryProvider &&
revalidation?.expires_at <= new Date().getTime() / 1000
) {
screenContent = (
<>
<div className={ 'wporg-2fa__account-status' }>
<AccountStatus />
</div>
<AccountStatus />
<RevalidateModal />
</>
);
Expand Down