From 8011dd27e928521b83f757cea839d806e35c80b1 Mon Sep 17 00:00:00 2001 From: Adam Wood Date: Thu, 1 Jun 2023 15:16:30 +1200 Subject: [PATCH] Block access to backup codes on render if totp is not enabled --------- Co-authored-by: Adam Wood --- settings/src/components/backup-codes.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/settings/src/components/backup-codes.js b/settings/src/components/backup-codes.js index c8a0c97b..55642ffa 100644 --- a/settings/src/components/backup-codes.js +++ b/settings/src/components/backup-codes.js @@ -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; }