diff --git a/src/Expensify.tsx b/src/Expensify.tsx index e446f1e725a9..5696fdffeaca 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -12,9 +12,12 @@ import GrowlNotification from './components/GrowlNotification'; import RequireTwoFactorAuthenticationModal from './components/RequireTwoFactorAuthenticationModal'; import AppleAuthWrapper from './components/SignInButtons/AppleAuthWrapper'; import SplashScreenHider from './components/SplashScreenHider'; +import TestToolsModal from './components/TestToolsModal'; import UpdateAppModal from './components/UpdateAppModal'; import * as CONFIG from './CONFIG'; import CONST from './CONST'; +import useDebugShortcut from './hooks/useDebugShortcut'; +import useIsAuthenticated from './hooks/useIsAuthenticated'; import useLocalize from './hooks/useLocalize'; import {updateLastRoute} from './libs/actions/App'; import * as EmojiPickerAction from './libs/actions/EmojiPickerAction'; @@ -96,6 +99,8 @@ function Expensify() { const [focusModeNotification] = useOnyx(ONYXKEYS.FOCUS_MODE_NOTIFICATION, {initWithStoredValues: false}); const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH); + useDebugShortcut(); + useEffect(() => { if (!account?.needsTwoFactorAuthSetup || account.requiresTwoFactorAuth) { return; @@ -112,7 +117,7 @@ function Expensify() { setAttemptedToOpenPublicRoom(true); }, [isCheckingPublicRoom]); - const isAuthenticated = useMemo(() => !!(session?.authToken ?? null), [session]); + const isAuthenticated = useIsAuthenticated(); const autoAuthState = useMemo(() => session?.autoAuthState ?? '', [session]); const shouldInit = isNavigationReady && hasAttemptedToOpenPublicRoom; @@ -295,6 +300,7 @@ function Expensify() { /> )} {shouldHideSplash && } + ); } diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 1974f9851a88..e7d6990db8d5 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -268,7 +268,7 @@ const ROUTES = { SETTINGS_STATUS_CLEAR_AFTER_DATE: 'settings/profile/status/clear-after/date', SETTINGS_STATUS_CLEAR_AFTER_TIME: 'settings/profile/status/clear-after/time', SETTINGS_TROUBLESHOOT: 'settings/troubleshoot', - SETTINGS_CONSOLE: { + CONSOLE_DEBUG: { route: 'settings/troubleshoot/console', getRoute: (backTo?: string) => getUrlWithBackToParam(`settings/troubleshoot/console`, backTo), }, diff --git a/src/SCREENS.ts b/src/SCREENS.ts index d950fb1cd5db..7c32387244a2 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -62,6 +62,7 @@ const SCREENS = { ADVANCED_FILTERS_IN_RHP: 'Search_Advanced_Filters_In_RHP', TRANSACTION_HOLD_REASON_RHP: 'Search_Transaction_Hold_Reason_RHP', }, + CONSOLE_DEBUG: 'Console_Debug', SETTINGS: { ROOT: 'Settings_Root', SHARE_CODE: 'Settings_Share_Code', @@ -77,7 +78,6 @@ const SCREENS = { CLOSE: 'Settings_Close', REPORT_CARD_LOST_OR_DAMAGED: 'Settings_ReportCardLostOrDamaged', TROUBLESHOOT: 'Settings_Troubleshoot', - CONSOLE: 'Settings_Console', SHARE_LOG: 'Share_Log', PROFILE: { diff --git a/src/components/TestToolMenu.tsx b/src/components/TestToolMenu.tsx index 83aba3d4b61e..8d8c3bc4dc89 100644 --- a/src/components/TestToolMenu.tsx +++ b/src/components/TestToolMenu.tsx @@ -1,11 +1,12 @@ import React from 'react'; import {useOnyx} from 'react-native-onyx'; +import useIsAuthenticated from '@hooks/useIsAuthenticated'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as ApiUtils from '@libs/ApiUtils'; -import * as Network from '@userActions/Network'; -import * as Session from '@userActions/Session'; -import * as User from '@userActions/User'; +import {isUsingStagingApi} from '@libs/ApiUtils'; +import {setShouldFailAllRequests, setShouldForceOffline, setShouldSimulatePoorConnection} from '@userActions/Network'; +import {expireSessionWithDelay, invalidateAuthToken, invalidateCredentials} from '@userActions/Session'; +import {setIsDebugModeEnabled, setShouldUseStagingServer} from '@userActions/User'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; import type {User as UserOnyx} from '@src/types/onyx'; @@ -28,11 +29,14 @@ function TestToolMenu() { const [network] = useOnyx(ONYXKEYS.NETWORK); const [user = USER_DEFAULT] = useOnyx(ONYXKEYS.USER); const [isUsingImportedState] = useOnyx(ONYXKEYS.IS_USING_IMPORTED_STATE); - const shouldUseStagingServer = user?.shouldUseStagingServer ?? ApiUtils.isUsingStagingApi(); + const shouldUseStagingServer = user?.shouldUseStagingServer ?? isUsingStagingApi(); const isDebugModeEnabled = !!user?.isDebugModeEnabled; const styles = useThemeStyles(); const {translate} = useLocalize(); + // Check if the user is authenticated to show options that require authentication + const isAuthenticated = useIsAuthenticated(); + return ( <> {translate('initialSettingsPage.troubleshoot.testingPreferences')} - {/* When toggled the app will be put into debug mode. */} - - User.setIsDebugModeEnabled(!isDebugModeEnabled)} - /> - + {isAuthenticated && ( + <> + {/* When toggled the app will be put into debug mode. */} + + setIsDebugModeEnabled(!isDebugModeEnabled)} + /> + + + {/* Instantly invalidates a user's local authToken. Useful for testing flows related to reauthentication. */} + +