From be60f00ac13fab53cf6b19cca406189462f5520d Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 13 Nov 2024 14:27:35 -0700 Subject: [PATCH 1/4] Remove unused parameter for short lived authToken --- .../API/parameters/SignInWithShortLivedAuthTokenParams.ts | 1 - src/libs/actions/Session/index.ts | 7 +------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/libs/API/parameters/SignInWithShortLivedAuthTokenParams.ts b/src/libs/API/parameters/SignInWithShortLivedAuthTokenParams.ts index 447c0ede0399..675c3a54399f 100644 --- a/src/libs/API/parameters/SignInWithShortLivedAuthTokenParams.ts +++ b/src/libs/API/parameters/SignInWithShortLivedAuthTokenParams.ts @@ -1,6 +1,5 @@ type SignInWithShortLivedAuthTokenParams = { authToken: string; - oldPartnerUserID: string; skipReauthentication: boolean; }; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index eda761b9637b..89dd481af5af 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -570,12 +570,7 @@ function beginGoogleSignIn(token: string | null) { */ function signInWithShortLivedAuthToken(email: string, authToken: string) { const {optimisticData, finallyData} = getShortLivedLoginParams(); - - // If the user is signing in with a different account from the current app, should not pass the auto-generated login as it may be tied to the old account. - // scene 1: the user is transitioning to newDot from a different account on oldDot. - // scene 2: the user is transitioning to desktop app from a different account on web app. - const oldPartnerUserID = credentials.login === email && credentials.autoGeneratedLogin ? credentials.autoGeneratedLogin : ''; - API.read(READ_COMMANDS.SIGN_IN_WITH_SHORT_LIVED_AUTH_TOKEN, {authToken, oldPartnerUserID, skipReauthentication: true}, {optimisticData, finallyData}); + API.read(READ_COMMANDS.SIGN_IN_WITH_SHORT_LIVED_AUTH_TOKEN, {authToken, skipReauthentication: true}, {optimisticData, finallyData}); } /** From 1ab2d641c4b2bf033fd7872dc2b63cff37b6280a Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Thu, 14 Nov 2024 09:16:27 -0700 Subject: [PATCH 2/4] Remove unused parameter --- src/libs/actions/Session/index.ts | 2 +- src/pages/LogInWithShortLivedAuthTokenPage.tsx | 4 ++-- src/pages/LogOutPreviousUserPage.tsx | 3 +-- src/pages/signin/SAMLSignInPage/index.native.tsx | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 89dd481af5af..af7da709d456 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -568,7 +568,7 @@ function beginGoogleSignIn(token: string | null) { * Will create a temporary login for the user in the passed authenticate response which is used when * re-authenticating after an authToken expires. */ -function signInWithShortLivedAuthToken(email: string, authToken: string) { +function signInWithShortLivedAuthToken(authToken: string) { const {optimisticData, finallyData} = getShortLivedLoginParams(); API.read(READ_COMMANDS.SIGN_IN_WITH_SHORT_LIVED_AUTH_TOKEN, {authToken, skipReauthentication: true}, {optimisticData, finallyData}); } diff --git a/src/pages/LogInWithShortLivedAuthTokenPage.tsx b/src/pages/LogInWithShortLivedAuthTokenPage.tsx index e604f2ccf847..64e4572d4ed2 100644 --- a/src/pages/LogInWithShortLivedAuthTokenPage.tsx +++ b/src/pages/LogInWithShortLivedAuthTokenPage.tsx @@ -17,7 +17,7 @@ import SessionExpiredPage from './ErrorPage/SessionExpiredPage'; type LogInWithShortLivedAuthTokenPageProps = StackScreenProps; function LogInWithShortLivedAuthTokenPage({route}: LogInWithShortLivedAuthTokenPageProps) { - const {email = '', shortLivedAuthToken = '', shortLivedToken = '', authTokenType, exitTo, error} = route?.params ?? {}; + const {shortLivedAuthToken = '', shortLivedToken = '', authTokenType, exitTo, error} = route?.params ?? {}; const [account] = useOnyx(ONYXKEYS.ACCOUNT); useEffect(() => { @@ -37,7 +37,7 @@ function LogInWithShortLivedAuthTokenPage({route}: LogInWithShortLivedAuthTokenP // Try to authenticate using the shortLivedToken if we're not already trying to load the accounts if (token && !account?.isLoading) { Log.info('LogInWithShortLivedAuthTokenPage - Successfully received shortLivedAuthToken. Signing in...'); - Session.signInWithShortLivedAuthToken(email, token); + Session.signInWithShortLivedAuthToken(token); return; } diff --git a/src/pages/LogOutPreviousUserPage.tsx b/src/pages/LogOutPreviousUserPage.tsx index deb95a576c3d..260fe8942926 100644 --- a/src/pages/LogOutPreviousUserPage.tsx +++ b/src/pages/LogOutPreviousUserPage.tsx @@ -61,9 +61,8 @@ function LogOutPreviousUserPage({session, route, isAccountLoading}: LogOutPrevio // On Enabling 2FA, authToken stored in Onyx becomes expired and hence we need to fetch new authToken const shouldForceLogin = route.params.shouldForceLogin === 'true'; if (shouldForceLogin) { - const email = route.params.email ?? ''; const shortLivedAuthToken = route.params.shortLivedAuthToken ?? ''; - SessionActions.signInWithShortLivedAuthToken(email, shortLivedAuthToken); + SessionActions.signInWithShortLivedAuthToken(shortLivedAuthToken); } // We only want to run this effect once on mount (when the page first loads after transitioning from OldDot) // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index c6f8b8061c05..9ce73b675320 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -34,7 +34,7 @@ function SAMLSignInPage({credentials, account}: SAMLSignInPageProps) { const shortLivedAuthToken = searchParams.get('shortLivedAuthToken'); if (!account?.isLoading && credentials?.login && !!shortLivedAuthToken) { Log.info('SAMLSignInPage - Successfully received shortLivedAuthToken. Signing in...'); - Session.signInWithShortLivedAuthToken(credentials.login, shortLivedAuthToken); + Session.signInWithShortLivedAuthToken(shortLivedAuthToken); } // If the login attempt is unsuccessful, set the error message for the account and redirect to sign in page From 6611508099bcbee7b18bdc4c2211bf104816ce3b Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 15 Nov 2024 14:03:48 -0700 Subject: [PATCH 3/4] Refactor files to use useOnyx --- src/pages/LogOutPreviousUserPage.tsx | 29 +++++-------------- .../signin/SAMLSignInPage/index.native.tsx | 12 ++++---- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/src/pages/LogOutPreviousUserPage.tsx b/src/pages/LogOutPreviousUserPage.tsx index 260fe8942926..5e40342a7b9d 100644 --- a/src/pages/LogOutPreviousUserPage.tsx +++ b/src/pages/LogOutPreviousUserPage.tsx @@ -1,8 +1,7 @@ import type {StackScreenProps} from '@react-navigation/stack'; import React, {useContext, useEffect} from 'react'; import {NativeModules} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; -import type {OnyxEntry} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; import {InitialURLContext} from '@components/InitialURLContextProvider'; import * as SessionUtils from '@libs/SessionUtils'; @@ -14,24 +13,18 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {Route} from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {Session} from '@src/types/onyx'; -type LogOutPreviousUserPageOnyxProps = { - /** The data about the current session which will be set once the user is authenticated and we return to this component as an AuthScreen */ - session: OnyxEntry; - - /** Is the account loading? */ - isAccountLoading: boolean; -}; - -type LogOutPreviousUserPageProps = LogOutPreviousUserPageOnyxProps & StackScreenProps; +type LogOutPreviousUserPageProps = StackScreenProps; // This page is responsible for handling transitions from OldDot. Specifically, it logs the current user // out if the transition is for another user. // // This component should not do any other navigation as that handled in App.setUpPoliciesAndNavigate -function LogOutPreviousUserPage({session, route, isAccountLoading}: LogOutPreviousUserPageProps) { +function LogOutPreviousUserPage({route}: LogOutPreviousUserPageProps) { const {initialURL} = useContext(InitialURLContext); + const [session] = useOnyx(ONYXKEYS.SESSION); + const [account = {}] = useOnyx(ONYXKEYS.ACCOUNT); + const isAccountLoading = account?.isLoading; useEffect(() => { const sessionEmail = session?.email; @@ -92,12 +85,4 @@ function LogOutPreviousUserPage({session, route, isAccountLoading}: LogOutPrevio LogOutPreviousUserPage.displayName = 'LogOutPreviousUserPage'; -export default withOnyx({ - isAccountLoading: { - key: ONYXKEYS.ACCOUNT, - selector: (account) => account?.isLoading ?? false, - }, - session: { - key: ONYXKEYS.SESSION, - }, -})(LogOutPreviousUserPage); +export default LogOutPreviousUserPage; diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index 9ce73b675320..3b9bc456a680 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -1,5 +1,5 @@ import React, {useCallback, useState} from 'react'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import WebView from 'react-native-webview'; import type {WebViewNativeEvent} from 'react-native-webview/lib/WebViewTypes'; import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView'; @@ -13,9 +13,10 @@ import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {SAMLSignInPageOnyxProps, SAMLSignInPageProps} from './types'; -function SAMLSignInPage({credentials, account}: SAMLSignInPageProps) { +function SAMLSignInPage() { + const [account] = useOnyx(ONYXKEYS.ACCOUNT); + const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); const samlLoginURL = `${CONFIG.EXPENSIFY.SAML_URL}?email=${credentials?.login}&referer=${CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER}&platform=${getPlatform()}`; const [showNavigation, shouldShowNavigation] = useState(true); @@ -80,7 +81,4 @@ function SAMLSignInPage({credentials, account}: SAMLSignInPageProps) { SAMLSignInPage.displayName = 'SAMLSignInPage'; -export default withOnyx({ - credentials: {key: ONYXKEYS.CREDENTIALS}, - account: {key: ONYXKEYS.ACCOUNT}, -})(SAMLSignInPage); +export default SAMLSignInPage; From 3d8b70634e28be1acc2178964bad05ea859ce0bd Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 18 Nov 2024 14:57:21 -0700 Subject: [PATCH 4/4] Remove default object --- src/pages/LogOutPreviousUserPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/LogOutPreviousUserPage.tsx b/src/pages/LogOutPreviousUserPage.tsx index 5e40342a7b9d..f37759eeaa88 100644 --- a/src/pages/LogOutPreviousUserPage.tsx +++ b/src/pages/LogOutPreviousUserPage.tsx @@ -23,7 +23,7 @@ type LogOutPreviousUserPageProps = StackScreenProps {