Skip to content

Commit

Permalink
Block access to backup codes on render if totp is not enabled
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Adam Wood <[email protected]>
  • Loading branch information
adamwoodnz authored and renintw committed Jun 8, 2023
1 parent 9c430b0 commit 8011dd2
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions settings/src/components/backup-codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,18 @@ import { refreshRecord } from '../utilities';

/**
* Setup and manage backup codes.
*
* @param props
* @param props.setScreen
*/
export default function BackupCodes( { setScreen } ) {
export default function BackupCodes() {
const {
user: { totpEnabled, backupCodesEnabled },
user: { backupCodesEnabled, totpEnabled },
navigateToScreen,
} = useContext( GlobalContext );
const [ regenerating, setRegenerating ] = useState( false );

// If TOTP hasn't been enabled, the user should not have access to BackupCodes component.
// This is primarily added to prevent users from accessing through the URL.
if ( ! totpEnabled ) {
const currentUrl = new URL( document.location.href );
currentUrl.searchParams.set( 'screen', 'account-status' );
window.history.pushState( {}, '', currentUrl );
setScreen( 'account-status' );
navigateToScreen( 'account-status' );
return;
}

Expand Down

0 comments on commit 8011dd2

Please sign in to comment.