Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Remove unused parameter for short lived authToken #52501

Merged
merged 5 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -568,14 +568,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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does isLoading need to be null coalesced or defaulted in line 25?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agree we should make it as before. Wdyt about this suggestion?

Suggested change
const [account = {}] = useOnyx(ONYXKEYS.ACCOUNT);
const isAccountLoading = account?.isLoading;
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const isAccountLoading = account?.isLoading ?? false;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove the default value for account, but it doesn't need null coalesce because the logic is only doing a falsy check, so undefined would be treated the same as false anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point


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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a default for isLoading or a null coalesce below? Why did you do [account = {}] above and [account] here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't need that (explained in my other comment). The default object was just some copy/paste from other code that I will remove.

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;
Loading