Skip to content

Commit

Permalink
Merge pull request #52501 from Expensify/tgolen-remove-partneridparam
Browse files Browse the repository at this point in the history
[No QA] Remove unused parameter for short lived authToken
  • Loading branch information
rafecolton authored Nov 18, 2024
2 parents 6ac7513 + 3d8b706 commit ac6b16e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
type SignInWithShortLivedAuthTokenParams = {
authToken: string;
oldPartnerUserID: string;
skipReauthentication: boolean;
};

Expand Down
9 changes: 2 additions & 7 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,14 +575,9 @@ 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();

// 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});
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/pages/LogInWithShortLivedAuthTokenPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import SessionExpiredPage from './ErrorPage/SessionExpiredPage';
type LogInWithShortLivedAuthTokenPageProps = StackScreenProps<PublicScreensParamList, typeof SCREENS.TRANSITION_BETWEEN_APPS>;

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(() => {
Expand All @@ -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;
}

Expand Down
32 changes: 8 additions & 24 deletions src/pages/LogOutPreviousUserPage.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<Session>;

/** Is the account loading? */
isAccountLoading: boolean;
};

type LogOutPreviousUserPageProps = LogOutPreviousUserPageOnyxProps & StackScreenProps<AuthScreensParamList, typeof SCREENS.TRANSITION_BETWEEN_APPS>;
type LogOutPreviousUserPageProps = StackScreenProps<AuthScreensParamList, typeof SCREENS.TRANSITION_BETWEEN_APPS>;

// 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;
Expand Down Expand Up @@ -61,9 +54,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
Expand Down Expand Up @@ -93,12 +85,4 @@ function LogOutPreviousUserPage({session, route, isAccountLoading}: LogOutPrevio

LogOutPreviousUserPage.displayName = 'LogOutPreviousUserPage';

export default withOnyx<LogOutPreviousUserPageProps, LogOutPreviousUserPageOnyxProps>({
isAccountLoading: {
key: ONYXKEYS.ACCOUNT,
selector: (account) => account?.isLoading ?? false,
},
session: {
key: ONYXKEYS.SESSION,
},
})(LogOutPreviousUserPage);
export default LogOutPreviousUserPage;
14 changes: 6 additions & 8 deletions src/pages/signin/SAMLSignInPage/index.native.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);

Expand All @@ -34,7 +35,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
Expand Down Expand Up @@ -80,7 +81,4 @@ function SAMLSignInPage({credentials, account}: SAMLSignInPageProps) {

SAMLSignInPage.displayName = 'SAMLSignInPage';

export default withOnyx<SAMLSignInPageProps, SAMLSignInPageOnyxProps>({
credentials: {key: ONYXKEYS.CREDENTIALS},
account: {key: ONYXKEYS.ACCOUNT},
})(SAMLSignInPage);
export default SAMLSignInPage;

0 comments on commit ac6b16e

Please sign in to comment.