Skip to content

Commit

Permalink
Require explicit action to create backup codes
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwoodnz committed Aug 14, 2024
1 parent fe04b98 commit 325ff31
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions settings/src/components/backup-codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import DownloadButton from './download-button';
*/
export default function BackupCodes() {
const {
user: { backupCodesEnabled, hasPrimaryProvider, backupCodesRemaining },
backupCodesVerified,
user: { hasPrimaryProvider },
} = useContext( GlobalContext );
const [ regenerating, setRegenerating ] = useState( false );

Expand All @@ -41,12 +40,7 @@ export default function BackupCodes() {
);
}

if (
! backupCodesEnabled ||
backupCodesRemaining === 0 ||
regenerating ||
! backupCodesVerified
) {
if ( regenerating ) {
return <Setup setRegenerating={ setRegenerating } />;
}

Expand Down Expand Up @@ -116,11 +110,7 @@ function Setup( { setRegenerating } ) {
return (
<>
<div className="wporg-2fa__screen-intro">
<p>
Backup codes let you access your account if your primary two-factor
authentication method is unavailable, like if your phone is lost or stolen. Each
code can only be used once.
</p>
<IntroText />

<p>Please print the codes and keep them in a safe place.</p>
</div>
Expand Down Expand Up @@ -201,6 +191,13 @@ function CodeList( { codes } ) {
);
}

const IntroText = () => (
<p>
Backup codes let you access your account if your primary two-factor authentication method is
unavailable, like if your phone is lost or stolen. Each code can only be used once.
</p>
);

/**
* Render the screen where users can manage Backup Codes.
*
Expand All @@ -209,25 +206,21 @@ function CodeList( { codes } ) {
*/
function Manage( { setRegenerating } ) {
const {
user: { backupCodesRemaining },
user: { backupCodesEnabled, backupCodesRemaining },
} = useContext( GlobalContext );

return (
<>
<div className="wporg-2fa__screen-intro">
<p>
Backup codes let you access your account if your primary two-factor
authentication method is unavailable, like if your phone is lost or stolen. Each
code can only be used once.
</p>
<IntroText />

{ backupCodesRemaining > 5 && (
{ backupCodesEnabled && backupCodesRemaining > 5 && (
<p>
You have <strong>{ backupCodesRemaining }</strong> backup codes remaining.
</p>
) }

{ backupCodesRemaining <= 5 && (
{ backupCodesEnabled && backupCodesRemaining <= 5 && (
<Notice status="warning" isDismissible={ false }>
<Icon icon={ warning } />
You only have <strong>{ backupCodesRemaining }</strong> backup codes
Expand All @@ -239,7 +232,7 @@ function Manage( { setRegenerating } ) {
</div>

<Button isSecondary onClick={ () => setRegenerating( true ) }>
Generate new backup codes
{ backupCodesEnabled ? 'Regenerate backup codes' : 'Generate backup codes' }
</Button>
</>
);
Expand Down

0 comments on commit 325ff31

Please sign in to comment.