From f5ed2423e103ab8cb9be5ff7eda218dcf9805043 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 15 Nov 2024 21:28:07 -0500 Subject: [PATCH 01/25] use fetch instead of simply window.location --- src/pages/signin/SAMLSignInPage/index.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.tsx b/src/pages/signin/SAMLSignInPage/index.tsx index 1ff9d02672be..bc02a7e88112 100644 --- a/src/pages/signin/SAMLSignInPage/index.tsx +++ b/src/pages/signin/SAMLSignInPage/index.tsx @@ -3,11 +3,26 @@ import {withOnyx} from 'react-native-onyx'; import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {SAMLSignInPageOnyxProps, SAMLSignInPageProps} from './types'; +import {getApiRoot} from '@libs/ApiUtils'; +import CONST from '@src/CONST'; function SAMLSignInPage({credentials}: SAMLSignInPageProps) { useEffect(() => { - window.location.replace(`${CONFIG.EXPENSIFY.SAML_URL}?email=${credentials?.login}&referer=${CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER}`); + const body = new FormData(); + body.append('email', credentials?.login ?? ''); + body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER) + + const url = `${getApiRoot()}authentication/saml/login`; + fetch(url, { + method: CONST.NETWORK.METHOD.POST, + body, + credentials: 'omit', + }).then((response) => response.json() as Promise + ).then((response) => { + if (response.url) { + window.location.replace(response.url); + } + }); }, [credentials?.login]); return ; From 67148f69cd536c7f604817430eff772daf855823 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 15 Nov 2024 21:28:24 -0500 Subject: [PATCH 02/25] update to use withOnyx, updated props --- src/pages/signin/SAMLSignInPage/index.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.tsx b/src/pages/signin/SAMLSignInPage/index.tsx index bc02a7e88112..a913d66658e8 100644 --- a/src/pages/signin/SAMLSignInPage/index.tsx +++ b/src/pages/signin/SAMLSignInPage/index.tsx @@ -1,12 +1,13 @@ import React, {useEffect} from 'react'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; import {getApiRoot} from '@libs/ApiUtils'; import CONST from '@src/CONST'; -function SAMLSignInPage({credentials}: SAMLSignInPageProps) { +function SAMLSignInPage() { + const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); useEffect(() => { const body = new FormData(); body.append('email', credentials?.login ?? ''); @@ -30,7 +31,4 @@ function SAMLSignInPage({credentials}: SAMLSignInPageProps) { SAMLSignInPage.displayName = 'SAMLSignInPage'; -export default withOnyx({ - account: {key: ONYXKEYS.ACCOUNT}, - credentials: {key: ONYXKEYS.CREDENTIALS}, -})(SAMLSignInPage); +export default SAMLSignInPage; From 6e71e1a3afc373b26ff36a48e8b3aa398e634c05 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Thu, 21 Nov 2024 22:35:59 +0000 Subject: [PATCH 03/25] minor style --- src/pages/signin/SAMLSignInPage/index.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.tsx b/src/pages/signin/SAMLSignInPage/index.tsx index a913d66658e8..a1b5ea12aa5a 100644 --- a/src/pages/signin/SAMLSignInPage/index.tsx +++ b/src/pages/signin/SAMLSignInPage/index.tsx @@ -11,17 +11,17 @@ function SAMLSignInPage() { useEffect(() => { const body = new FormData(); body.append('email', credentials?.login ?? ''); - body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER) + body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); - const url = `${getApiRoot()}authentication/saml/login`; - fetch(url, { + fetch(`${getApiRoot()}authentication/saml/login`, { method: CONST.NETWORK.METHOD.POST, body, credentials: 'omit', - }).then((response) => response.json() as Promise - ).then((response) => { - if (response.url) { - window.location.replace(response.url); + }) + .then((response) => response.json() as Promise) + .then((json) => { + if (json.url) { + window.location.replace(json.url); } }); }, [credentials?.login]); From 193e33333970017eeae4ac775d7a2a1827332b9a Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Thu, 21 Nov 2024 23:30:55 +0000 Subject: [PATCH 04/25] introduce post for SAML native --- .../signin/SAMLSignInPage/index.native.tsx | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index 3b9bc456a680..d08ef772962f 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -1,4 +1,4 @@ -import React, {useCallback, useState} from 'react'; +import React, {useCallback, useEffect, useRef, useState} from 'react'; import {useOnyx} from 'react-native-onyx'; import WebView from 'react-native-webview'; import type {WebViewNativeEvent} from 'react-native-webview/lib/WebViewTypes'; @@ -13,12 +13,37 @@ import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import {getApiRoot} from '@libs/ApiUtils'; +import CONST from '@src/CONST'; +import getUAForWebView from '@libs/getUAForWebView'; 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); + const [url, setURL] = useState(''); + const webViewRef = useRef(null); + + useEffect(() => { + const body = new FormData(); + body.append('email', credentials?.login ?? ''); + body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); + body.append('platform', getPlatform()); + + if (!url) { + fetch(`${getApiRoot()}authentication/saml/login`, { + method: CONST.NETWORK.METHOD.POST, + body, + credentials: 'omit', + }).then((response) => { + return response.json() as Promise + }).then((response) => { + if (response.url) { + setURL(response.url); + } + }); + } + }, [credentials?.login, url]); /** * Handles in-app navigation once we get a response back from Expensify @@ -58,6 +83,7 @@ function SAMLSignInPage() { { + setURL(''); Session.clearSignInData(); Navigation.isNavigationReady().then(() => { Navigation.goBack(); @@ -66,14 +92,17 @@ function SAMLSignInPage() { /> )} + {!!url && ( } onNavigationStateChange={handleNavigationStateChange} /> + )} ); From 5354911b616fdf54c5074d30525e613ee9e4753d Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Thu, 21 Nov 2024 23:41:02 +0000 Subject: [PATCH 05/25] style --- .../signin/SAMLSignInPage/index.native.tsx | 44 ++++++++++--------- src/pages/signin/SAMLSignInPage/index.tsx | 16 +++---- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index d08ef772962f..bf950bf5c568 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -6,16 +6,16 @@ import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOffli import HeaderWithBackButton from '@components/HeaderWithBackButton'; import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator'; import ScreenWrapper from '@components/ScreenWrapper'; +import {getApiRoot} from '@libs/ApiUtils'; import getPlatform from '@libs/getPlatform'; +import getUAForWebView from '@libs/getUAForWebView'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; +import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import {getApiRoot} from '@libs/ApiUtils'; -import CONST from '@src/CONST'; -import getUAForWebView from '@libs/getUAForWebView'; function SAMLSignInPage() { const [account] = useOnyx(ONYXKEYS.ACCOUNT); @@ -35,13 +35,15 @@ function SAMLSignInPage() { method: CONST.NETWORK.METHOD.POST, body, credentials: 'omit', - }).then((response) => { - return response.json() as Promise - }).then((response) => { - if (response.url) { - setURL(response.url); - } - }); + }) + .then((response) => { + return response.json() as Promise; + }) + .then((response) => { + if (response.url) { + setURL(response.url); + } + }); } }, [credentials?.login, url]); @@ -92,17 +94,17 @@ function SAMLSignInPage() { /> )} - {!!url && ( - } - onNavigationStateChange={handleNavigationStateChange} - /> - )} + {!!url && ( + } + onNavigationStateChange={handleNavigationStateChange} + /> + )} ); diff --git a/src/pages/signin/SAMLSignInPage/index.tsx b/src/pages/signin/SAMLSignInPage/index.tsx index a1b5ea12aa5a..633eb0728258 100644 --- a/src/pages/signin/SAMLSignInPage/index.tsx +++ b/src/pages/signin/SAMLSignInPage/index.tsx @@ -1,10 +1,10 @@ import React, {useEffect} from 'react'; import {useOnyx} from 'react-native-onyx'; import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator'; -import CONFIG from '@src/CONFIG'; -import ONYXKEYS from '@src/ONYXKEYS'; import {getApiRoot} from '@libs/ApiUtils'; +import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; function SAMLSignInPage() { const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); @@ -18,12 +18,12 @@ function SAMLSignInPage() { body, credentials: 'omit', }) - .then((response) => response.json() as Promise) - .then((json) => { - if (json.url) { - window.location.replace(json.url); - } - }); + .then((response) => response.json() as Promise) + .then((json) => { + if (json.url) { + window.location.replace(json.url); + } + }); }, [credentials?.login]); return ; From 488e69e0033fc0ff4692ac348de8435d49d2eed4 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 22 Nov 2024 17:22:54 +0000 Subject: [PATCH 06/25] dry up saml url logic --- src/libs/LoginUtils.ts | 17 +++++++- .../signin/SAMLSignInPage/index.native.tsx | 42 +++++++++---------- src/pages/signin/SAMLSignInPage/index.tsx | 20 +++------ 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/libs/LoginUtils.ts b/src/libs/LoginUtils.ts index 191fd72db4e9..fd0d316cf94d 100644 --- a/src/libs/LoginUtils.ts +++ b/src/libs/LoginUtils.ts @@ -3,6 +3,7 @@ import Onyx from 'react-native-onyx'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import {parsePhoneNumber} from './PhoneNumber'; +import CONFIG from '@src/CONFIG'; let countryCodeByIP: number; Onyx.connect({ @@ -75,4 +76,18 @@ function areEmailsFromSamePrivateDomain(email1: string, email2: string): boolean return Str.extractEmailDomain(email1).toLowerCase() === Str.extractEmailDomain(email2).toLowerCase(); } -export {getPhoneNumberWithoutSpecialChars, appendCountryCode, isEmailPublicDomain, validateNumber, getPhoneLogin, areEmailsFromSamePrivateDomain}; +function fetchSAMLUrl(body: FormData): Promise { + return fetch(CONFIG.EXPENSIFY.SAML_URL, { + method: CONST.NETWORK.METHOD.POST, + body, + credentials: 'omit', + }) + .then((response) => { + if (!response.ok) { + throw new Error('An error occurred while logging in. Please try again'); + } + return response.json() as Promise; + }).then((response) => response) +} + +export {getPhoneNumberWithoutSpecialChars, appendCountryCode, isEmailPublicDomain, validateNumber, getPhoneLogin, areEmailsFromSamePrivateDomain, fetchSAMLUrl}; diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index bf950bf5c568..d024991f84dc 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -6,46 +6,41 @@ import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOffli import HeaderWithBackButton from '@components/HeaderWithBackButton'; import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator'; import ScreenWrapper from '@components/ScreenWrapper'; -import {getApiRoot} from '@libs/ApiUtils'; import getPlatform from '@libs/getPlatform'; import getUAForWebView from '@libs/getUAForWebView'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; -import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import { fetchSAMLUrl } from '@libs/LoginUtils'; function SAMLSignInPage() { const [account] = useOnyx(ONYXKEYS.ACCOUNT); const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); const [showNavigation, shouldShowNavigation] = useState(true); - const [url, setURL] = useState(''); + const [SAMLUrl, setSAMLUrl] = useState(''); const webViewRef = useRef(null); useEffect(() => { + + // If we've already gotten a url back to log into the user's IdP, then don't re-fetch it + if (SAMLUrl) { + return; + } + const body = new FormData(); body.append('email', credentials?.login ?? ''); body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); body.append('platform', getPlatform()); - - if (!url) { - fetch(`${getApiRoot()}authentication/saml/login`, { - method: CONST.NETWORK.METHOD.POST, - body, - credentials: 'omit', - }) - .then((response) => { - return response.json() as Promise; - }) - .then((response) => { - if (response.url) { - setURL(response.url); - } - }); - } - }, [credentials?.login, url]); + fetchSAMLUrl(body).then((response) => { + if (response && response.url) { + console.log("meep meep: " + JSON.stringify(response)); + setSAMLUrl(response.url); + } + }); + }, [credentials?.login, SAMLUrl]); /** * Handles in-app navigation once we get a response back from Expensify @@ -85,7 +80,7 @@ function SAMLSignInPage() { { - setURL(''); + setSAMLUrl(''); Session.clearSignInData(); Navigation.isNavigationReady().then(() => { Navigation.goBack(); @@ -94,10 +89,11 @@ function SAMLSignInPage() { /> )} - {!!url && ( + {!!SAMLUrl && ( { @@ -13,17 +11,11 @@ function SAMLSignInPage() { body.append('email', credentials?.login ?? ''); body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); - fetch(`${getApiRoot()}authentication/saml/login`, { - method: CONST.NETWORK.METHOD.POST, - body, - credentials: 'omit', - }) - .then((response) => response.json() as Promise) - .then((json) => { - if (json.url) { - window.location.replace(json.url); - } - }); + fetchSAMLUrl(body).then((response) => { + if (response && response.url) { + window.location.replace(response.url); + } + }); }, [credentials?.login]); return ; From 2326cd01ccd4b33ea8f11a233d467345377fcea2 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 22 Nov 2024 17:35:17 +0000 Subject: [PATCH 07/25] style --- src/libs/LoginUtils.ts | 7 ++++--- src/pages/signin/SAMLSignInPage/index.native.tsx | 3 +-- src/pages/signin/SAMLSignInPage/index.tsx | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libs/LoginUtils.ts b/src/libs/LoginUtils.ts index fd0d316cf94d..e0d20b78e1bf 100644 --- a/src/libs/LoginUtils.ts +++ b/src/libs/LoginUtils.ts @@ -1,9 +1,9 @@ import {PUBLIC_DOMAINS, Str} from 'expensify-common'; import Onyx from 'react-native-onyx'; +import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import {parsePhoneNumber} from './PhoneNumber'; -import CONFIG from '@src/CONFIG'; let countryCodeByIP: number; Onyx.connect({ @@ -76,7 +76,7 @@ function areEmailsFromSamePrivateDomain(email1: string, email2: string): boolean return Str.extractEmailDomain(email1).toLowerCase() === Str.extractEmailDomain(email2).toLowerCase(); } -function fetchSAMLUrl(body: FormData): Promise { +function fetchSAMLUrl(body: FormData): Promise { return fetch(CONFIG.EXPENSIFY.SAML_URL, { method: CONST.NETWORK.METHOD.POST, body, @@ -87,7 +87,8 @@ function fetchSAMLUrl(body: FormData): Promise { throw new Error('An error occurred while logging in. Please try again'); } return response.json() as Promise; - }).then((response) => response) + }) + .then((response) => response); } export {getPhoneNumberWithoutSpecialChars, appendCountryCode, isEmailPublicDomain, validateNumber, getPhoneLogin, areEmailsFromSamePrivateDomain, fetchSAMLUrl}; diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index d024991f84dc..cb399780da03 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -9,12 +9,12 @@ import ScreenWrapper from '@components/ScreenWrapper'; import getPlatform from '@libs/getPlatform'; import getUAForWebView from '@libs/getUAForWebView'; import Log from '@libs/Log'; +import {fetchSAMLUrl} from '@libs/LoginUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import { fetchSAMLUrl } from '@libs/LoginUtils'; function SAMLSignInPage() { const [account] = useOnyx(ONYXKEYS.ACCOUNT); @@ -24,7 +24,6 @@ function SAMLSignInPage() { const webViewRef = useRef(null); useEffect(() => { - // If we've already gotten a url back to log into the user's IdP, then don't re-fetch it if (SAMLUrl) { return; diff --git a/src/pages/signin/SAMLSignInPage/index.tsx b/src/pages/signin/SAMLSignInPage/index.tsx index 9fbaf64f6552..deece2730579 100644 --- a/src/pages/signin/SAMLSignInPage/index.tsx +++ b/src/pages/signin/SAMLSignInPage/index.tsx @@ -4,6 +4,7 @@ import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator'; import {fetchSAMLUrl} from '@libs/LoginUtils'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; + function SAMLSignInPage() { const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); useEffect(() => { From 9d63639c055538b9f3b468b2e4930ecc1744c4da Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Thu, 28 Nov 2024 17:32:15 +0000 Subject: [PATCH 08/25] update SAML native logic to handle errors --- src/pages/signin/SAMLSignInPage/index.native.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index cb399780da03..e027015ff21a 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -35,7 +35,6 @@ function SAMLSignInPage() { body.append('platform', getPlatform()); fetchSAMLUrl(body).then((response) => { if (response && response.url) { - console.log("meep meep: " + JSON.stringify(response)); setSAMLUrl(response.url); } }); @@ -46,7 +45,6 @@ function SAMLSignInPage() { */ const handleNavigationStateChange = useCallback( ({url}: WebViewNativeEvent) => { - Log.info('SAMLSignInPage - Handling SAML navigation change'); // If we've gotten a callback then remove the option to navigate back to the sign-in page if (url.includes('loginCallback')) { shouldShowNavigation(false); @@ -63,7 +61,12 @@ function SAMLSignInPage() { if (searchParams.has('error')) { Session.clearSignInData(); Session.setAccountError(searchParams.get('error') ?? ''); - Navigation.navigate(ROUTES.HOME); + + Navigation.isNavigationReady().then(() => { + // We must call goBack() to remove the /transition route from history + Navigation.goBack(); + Navigation.navigate(ROUTES.HOME); + }); } }, [credentials?.login, shouldShowNavigation, account?.isLoading], From 455fb475dfa66d8b9c4c596f95b6ede8146521df Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Thu, 28 Nov 2024 17:32:29 +0000 Subject: [PATCH 09/25] fix error handling for signing in with short lived authtoken --- src/pages/LogInWithShortLivedAuthTokenPage.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pages/LogInWithShortLivedAuthTokenPage.tsx b/src/pages/LogInWithShortLivedAuthTokenPage.tsx index 64e4572d4ed2..d17418f0de11 100644 --- a/src/pages/LogInWithShortLivedAuthTokenPage.tsx +++ b/src/pages/LogInWithShortLivedAuthTokenPage.tsx @@ -49,8 +49,11 @@ function LogInWithShortLivedAuthTokenPage({route}: LogInWithShortLivedAuthTokenP // For HybridApp we have separate logic to handle transitions. if (!NativeModules.HybridAppModule && exitTo) { Navigation.isNavigationReady().then(() => { + // We must call goBack() to remove the /transition route from history + Navigation.goBack(); Navigation.navigate(exitTo as Route); }); + return; } // The only dependencies of the effect are based on props.route // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps From 3f678b6e329a2b820daa02ea50209ee1bada2475 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Thu, 28 Nov 2024 19:17:52 +0000 Subject: [PATCH 10/25] minor style --- src/pages/LogInWithShortLivedAuthTokenPage.tsx | 1 - src/pages/signin/SAMLSignInPage/index.native.tsx | 5 +++-- src/pages/signin/SAMLSignInPage/index.tsx | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/pages/LogInWithShortLivedAuthTokenPage.tsx b/src/pages/LogInWithShortLivedAuthTokenPage.tsx index d17418f0de11..c5357d11d7da 100644 --- a/src/pages/LogInWithShortLivedAuthTokenPage.tsx +++ b/src/pages/LogInWithShortLivedAuthTokenPage.tsx @@ -53,7 +53,6 @@ function LogInWithShortLivedAuthTokenPage({route}: LogInWithShortLivedAuthTokenP Navigation.goBack(); Navigation.navigate(exitTo as Route); }); - return; } // The only dependencies of the effect are based on props.route // 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 e027015ff21a..5242811e3a14 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -34,9 +34,10 @@ function SAMLSignInPage() { body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); body.append('platform', getPlatform()); fetchSAMLUrl(body).then((response) => { - if (response && response.url) { - setSAMLUrl(response.url); + if (!response || !response.url) { + return; } + setSAMLUrl(response.url); }); }, [credentials?.login, SAMLUrl]); diff --git a/src/pages/signin/SAMLSignInPage/index.tsx b/src/pages/signin/SAMLSignInPage/index.tsx index deece2730579..62bebf365d4c 100644 --- a/src/pages/signin/SAMLSignInPage/index.tsx +++ b/src/pages/signin/SAMLSignInPage/index.tsx @@ -13,9 +13,10 @@ function SAMLSignInPage() { body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); fetchSAMLUrl(body).then((response) => { - if (response && response.url) { - window.location.replace(response.url); + if (!response || !response.url) { + return; } + window.location.replace(response.url); }); }, [credentials?.login]); From 72d735d8846d43bd809c0e2d976cc26e6ab63f75 Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Fri, 29 Nov 2024 10:43:22 +0000 Subject: [PATCH 11/25] Add clarification Co-authored-by: Maria D'Costa --- src/pages/signin/SAMLSignInPage/index.native.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index 5242811e3a14..d2df3c956f1a 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -24,7 +24,7 @@ function SAMLSignInPage() { const webViewRef = useRef(null); useEffect(() => { - // If we've already gotten a url back to log into the user's IdP, then don't re-fetch it + // If we've already gotten a url back to log into the user's Identity Provider (IdP), then don't re-fetch it if (SAMLUrl) { return; } From fc12c62fab17be07ddf7d8dcc37387be3a52bd7b Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 29 Nov 2024 22:09:34 +0000 Subject: [PATCH 12/25] return early with clean session if no login --- .../signin/SAMLSignInPage/index.native.tsx | 12 +++++++++++- src/pages/signin/SAMLSignInPage/index.tsx | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index 5242811e3a14..a1e61c95c9e4 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -15,6 +15,7 @@ import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import useLocalize from '@hooks/useLocalize'; function SAMLSignInPage() { const [account] = useOnyx(ONYXKEYS.ACCOUNT); @@ -22,15 +23,24 @@ function SAMLSignInPage() { const [showNavigation, shouldShowNavigation] = useState(true); const [SAMLUrl, setSAMLUrl] = useState(''); const webViewRef = useRef(null); + const {translate} = useLocalize(); useEffect(() => { + // If we don't have a valid login to pass here, direct the user back to a clean sign in state to try again + if (!credentials?.login) { + Session.clearSignInData(); + Session.setAccountError(translate('common.error.email')); + Navigation.goBack(ROUTES.HOME); + return; + } + // If we've already gotten a url back to log into the user's IdP, then don't re-fetch it if (SAMLUrl) { return; } const body = new FormData(); - body.append('email', credentials?.login ?? ''); + body.append('email', credentials.login); body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); body.append('platform', getPlatform()); fetchSAMLUrl(body).then((response) => { diff --git a/src/pages/signin/SAMLSignInPage/index.tsx b/src/pages/signin/SAMLSignInPage/index.tsx index 62bebf365d4c..f857f5250970 100644 --- a/src/pages/signin/SAMLSignInPage/index.tsx +++ b/src/pages/signin/SAMLSignInPage/index.tsx @@ -4,12 +4,27 @@ import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator'; import {fetchSAMLUrl} from '@libs/LoginUtils'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; +import Navigation from '@libs/Navigation/Navigation'; +import ROUTES from '@src/ROUTES'; +import * as Session from '@userActions/Session'; +import useLocalize from '@hooks/useLocalize'; function SAMLSignInPage() { + const {translate} = useLocalize(); const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); + + useEffect(() => { + // If we don't have a valid login to pass here, direct the user back to a clean sign in state to try again + if (!credentials?.login) { + Session.clearSignInData(); + Session.setAccountError(translate('common.error.email')); + Navigation.goBack(ROUTES.HOME); + return; + } + const body = new FormData(); - body.append('email', credentials?.login ?? ''); + body.append('email', credentials.login); body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); fetchSAMLUrl(body).then((response) => { From d60395c36a06978770e1e0517639215d8e8cb3c6 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 29 Nov 2024 22:11:01 +0000 Subject: [PATCH 13/25] prettier --- src/pages/signin/SAMLSignInPage/index.native.tsx | 2 +- src/pages/signin/SAMLSignInPage/index.tsx | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index a1e61c95c9e4..492c97bf1827 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -6,6 +6,7 @@ import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOffli import HeaderWithBackButton from '@components/HeaderWithBackButton'; import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator'; import ScreenWrapper from '@components/ScreenWrapper'; +import useLocalize from '@hooks/useLocalize'; import getPlatform from '@libs/getPlatform'; import getUAForWebView from '@libs/getUAForWebView'; import Log from '@libs/Log'; @@ -15,7 +16,6 @@ import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import useLocalize from '@hooks/useLocalize'; function SAMLSignInPage() { const [account] = useOnyx(ONYXKEYS.ACCOUNT); diff --git a/src/pages/signin/SAMLSignInPage/index.tsx b/src/pages/signin/SAMLSignInPage/index.tsx index f857f5250970..aae9bdd63736 100644 --- a/src/pages/signin/SAMLSignInPage/index.tsx +++ b/src/pages/signin/SAMLSignInPage/index.tsx @@ -1,19 +1,18 @@ import React, {useEffect} from 'react'; import {useOnyx} from 'react-native-onyx'; import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator'; +import useLocalize from '@hooks/useLocalize'; import {fetchSAMLUrl} from '@libs/LoginUtils'; +import Navigation from '@libs/Navigation/Navigation'; +import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; -import Navigation from '@libs/Navigation/Navigation'; import ROUTES from '@src/ROUTES'; -import * as Session from '@userActions/Session'; -import useLocalize from '@hooks/useLocalize'; function SAMLSignInPage() { const {translate} = useLocalize(); const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); - useEffect(() => { // If we don't have a valid login to pass here, direct the user back to a clean sign in state to try again if (!credentials?.login) { From cc16359e202b4e95a07fad8527b04920e5b56833 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Sat, 30 Nov 2024 00:09:41 +0000 Subject: [PATCH 14/25] add copy --- src/languages/en.ts | 1 + src/languages/es.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/languages/en.ts b/src/languages/en.ts index 13ff38a0bc58..35c1dbfc7876 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -351,6 +351,7 @@ const translations = { invalidRateError: 'Please enter a valid rate.', lowRateError: 'Rate must be greater than 0.', email: 'Please enter a valid email address.', + login: 'An error occurred while logging in. Please try again.', }, comma: 'comma', semicolon: 'semicolon', diff --git a/src/languages/es.ts b/src/languages/es.ts index 6477827fd0a1..03b5bf0d372f 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -342,6 +342,7 @@ const translations = { invalidRateError: 'Por favor, introduce una tarifa válida.', lowRateError: 'La tarifa debe ser mayor que 0.', email: 'Por favor, introduzca una dirección de correo electrónico válida.', + login: 'Se produjo un error al iniciar sesión. Por favor intente nuevamente.', }, comma: 'la coma', semicolon: 'el punto y coma', From 01dd6fffba6f362ceb72caa2769c171a126bc521 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Sat, 30 Nov 2024 00:09:54 +0000 Subject: [PATCH 15/25] add handleError function --- .../signin/SAMLSignInPage/index.native.tsx | 18 +++++++++++++++--- src/pages/signin/SAMLSignInPage/index.tsx | 18 +++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index 0fbfca706771..fa1accc49b07 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -28,9 +28,7 @@ function SAMLSignInPage() { useEffect(() => { // If we don't have a valid login to pass here, direct the user back to a clean sign in state to try again if (!credentials?.login) { - Session.clearSignInData(); - Session.setAccountError(translate('common.error.email')); - Navigation.goBack(ROUTES.HOME); + handleError(translate('common.error.email'), true); return; } @@ -45,9 +43,14 @@ function SAMLSignInPage() { body.append('platform', getPlatform()); fetchSAMLUrl(body).then((response) => { if (!response || !response.url) { + handleError(translate('common.error.login')); return; } setSAMLUrl(response.url); + }) + .catch((response) => { + handleError(response.message ?? translate('common.error.login')); + return; }); }, [credentials?.login, SAMLUrl]); @@ -83,6 +86,15 @@ function SAMLSignInPage() { [credentials?.login, shouldShowNavigation, account?.isLoading], ); + function handleError(errorMessage: string, cleanSignInData: boolean = false) { + if (cleanSignInData) { + Session.clearSignInData(); + } + + Session.setAccountError(errorMessage); + Navigation.goBack(ROUTES.HOME); + } + return ( { // If we don't have a valid login to pass here, direct the user back to a clean sign in state to try again if (!credentials?.login) { - Session.clearSignInData(); - Session.setAccountError(translate('common.error.email')); - Navigation.goBack(ROUTES.HOME); + handleError(translate('common.error.email'), true); return; } @@ -28,12 +26,26 @@ function SAMLSignInPage() { fetchSAMLUrl(body).then((response) => { if (!response || !response.url) { + handleError(translate('common.error.login')); return; } window.location.replace(response.url); + }) + .catch((response) => { + handleError(response.message ?? translate('common.error.login')); + return; }); }, [credentials?.login]); + function handleError(errorMessage: string, cleanSignInData: boolean = false) { + if (cleanSignInData) { + Session.clearSignInData(); + } + + Session.setAccountError(errorMessage); + Navigation.goBack(ROUTES.HOME); + } + return ; } From 9312a299b24ee9f431094153583aa189bda4b578 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Sat, 30 Nov 2024 00:16:02 +0000 Subject: [PATCH 16/25] style --- .../signin/SAMLSignInPage/index.native.tsx | 21 ++++++++++--------- src/pages/signin/SAMLSignInPage/index.tsx | 21 ++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index fa1accc49b07..03c3e9034944 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -41,17 +41,18 @@ function SAMLSignInPage() { body.append('email', credentials.login); body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); body.append('platform', getPlatform()); - fetchSAMLUrl(body).then((response) => { - if (!response || !response.url) { - handleError(translate('common.error.login')); + fetchSAMLUrl(body) + .then((response) => { + if (!response || !response.url) { + handleError(translate('common.error.login')); + return; + } + setSAMLUrl(response.url); + }) + .catch((response) => { + handleError(response.message ?? translate('common.error.login')); return; - } - setSAMLUrl(response.url); - }) - .catch((response) => { - handleError(response.message ?? translate('common.error.login')); - return; - }); + }); }, [credentials?.login, SAMLUrl]); /** diff --git a/src/pages/signin/SAMLSignInPage/index.tsx b/src/pages/signin/SAMLSignInPage/index.tsx index 523b0c7bfccf..16504bb3a31e 100644 --- a/src/pages/signin/SAMLSignInPage/index.tsx +++ b/src/pages/signin/SAMLSignInPage/index.tsx @@ -24,17 +24,18 @@ function SAMLSignInPage() { body.append('email', credentials.login); body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); - fetchSAMLUrl(body).then((response) => { - if (!response || !response.url) { - handleError(translate('common.error.login')); + fetchSAMLUrl(body) + .then((response) => { + if (!response || !response.url) { + handleError(translate('common.error.login')); + return; + } + window.location.replace(response.url); + }) + .catch((response) => { + handleError(response.message ?? translate('common.error.login')); return; - } - window.location.replace(response.url); - }) - .catch((response) => { - handleError(response.message ?? translate('common.error.login')); - return; - }); + }); }, [credentials?.login]); function handleError(errorMessage: string, cleanSignInData: boolean = false) { From 8f1cb9fb689dd08993fe7e3d979bfd4a3ce5aff6 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Mon, 2 Dec 2024 12:06:02 +0000 Subject: [PATCH 17/25] linting changes --- src/pages/signin/SAMLSignInPage/index.native.tsx | 7 +++---- src/pages/signin/SAMLSignInPage/index.tsx | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index 03c3e9034944..4dda0f586d1c 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -50,10 +50,9 @@ function SAMLSignInPage() { setSAMLUrl(response.url); }) .catch((response) => { - handleError(response.message ?? translate('common.error.login')); - return; + handleError(response?.message ?? translate('common.error.login')); }); - }, [credentials?.login, SAMLUrl]); + }, [credentials?.login, SAMLUrl, translate]); /** * Handles in-app navigation once we get a response back from Expensify @@ -87,7 +86,7 @@ function SAMLSignInPage() { [credentials?.login, shouldShowNavigation, account?.isLoading], ); - function handleError(errorMessage: string, cleanSignInData: boolean = false) { + function handleError(errorMessage: string, cleanSignInData = false) { if (cleanSignInData) { Session.clearSignInData(); } diff --git a/src/pages/signin/SAMLSignInPage/index.tsx b/src/pages/signin/SAMLSignInPage/index.tsx index 16504bb3a31e..13f4e57f88d5 100644 --- a/src/pages/signin/SAMLSignInPage/index.tsx +++ b/src/pages/signin/SAMLSignInPage/index.tsx @@ -33,12 +33,11 @@ function SAMLSignInPage() { window.location.replace(response.url); }) .catch((response) => { - handleError(response.message ?? translate('common.error.login')); - return; + handleError(response?.message ?? translate('common.error.login')); }); - }, [credentials?.login]); + }, [credentials?.login, translate]); - function handleError(errorMessage: string, cleanSignInData: boolean = false) { + function handleError(errorMessage: string, cleanSignInData = false) { if (cleanSignInData) { Session.clearSignInData(); } From 2d614f74600670ae770cee4b88bccba8a4c5287a Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Mon, 2 Dec 2024 13:55:09 +0000 Subject: [PATCH 18/25] error handling --- src/pages/signin/SAMLSignInPage/index.native.tsx | 4 ++-- src/pages/signin/SAMLSignInPage/index.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index 4dda0f586d1c..868a9fbc2c50 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -49,8 +49,8 @@ function SAMLSignInPage() { } setSAMLUrl(response.url); }) - .catch((response) => { - handleError(response?.message ?? translate('common.error.login')); + .catch((error: Error) => { + handleError(error.message ?? translate('common.error.login')); }); }, [credentials?.login, SAMLUrl, translate]); diff --git a/src/pages/signin/SAMLSignInPage/index.tsx b/src/pages/signin/SAMLSignInPage/index.tsx index 13f4e57f88d5..2d54ddeda966 100644 --- a/src/pages/signin/SAMLSignInPage/index.tsx +++ b/src/pages/signin/SAMLSignInPage/index.tsx @@ -32,8 +32,8 @@ function SAMLSignInPage() { } window.location.replace(response.url); }) - .catch((response) => { - handleError(response?.message ?? translate('common.error.login')); + .catch((error: Error) => { + handleError(error.message ?? translate('common.error.login')); }); }, [credentials?.login, translate]); From 75aa238f3695ed0ee0a5d6b7c5541a0d29683dbb Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Wed, 11 Dec 2024 20:33:29 +0100 Subject: [PATCH 19/25] remove unneeded url clean --- src/pages/signin/SAMLSignInPage/index.native.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index 868a9fbc2c50..970ddce0b030 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -105,7 +105,6 @@ function SAMLSignInPage() { { - setSAMLUrl(''); Session.clearSignInData(); Navigation.isNavigationReady().then(() => { Navigation.goBack(); From c36685758713f9b4fbb220d83e807d2f67d02c3b Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Thu, 19 Dec 2024 18:41:25 -0500 Subject: [PATCH 20/25] dry handle error functionality and rename function --- src/libs/LoginUtils.ts | 16 ++++++++++++-- .../signin/SAMLSignInPage/index.native.tsx | 20 +++++------------ src/pages/signin/SAMLSignInPage/index.tsx | 22 +++++-------------- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/src/libs/LoginUtils.ts b/src/libs/LoginUtils.ts index e0d20b78e1bf..16610d09af2e 100644 --- a/src/libs/LoginUtils.ts +++ b/src/libs/LoginUtils.ts @@ -1,8 +1,11 @@ import {PUBLIC_DOMAINS, Str} from 'expensify-common'; import Onyx from 'react-native-onyx'; +import Navigation from '@libs/Navigation/Navigation'; +import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import ROUTES from '@src/ROUTES'; import {parsePhoneNumber} from './PhoneNumber'; let countryCodeByIP: number; @@ -76,7 +79,7 @@ function areEmailsFromSamePrivateDomain(email1: string, email2: string): boolean return Str.extractEmailDomain(email1).toLowerCase() === Str.extractEmailDomain(email2).toLowerCase(); } -function fetchSAMLUrl(body: FormData): Promise { +function postSAMLLogin(body: FormData): Promise { return fetch(CONFIG.EXPENSIFY.SAML_URL, { method: CONST.NETWORK.METHOD.POST, body, @@ -91,4 +94,13 @@ function fetchSAMLUrl(body: FormData): Promise { .then((response) => response); } -export {getPhoneNumberWithoutSpecialChars, appendCountryCode, isEmailPublicDomain, validateNumber, getPhoneLogin, areEmailsFromSamePrivateDomain, fetchSAMLUrl}; +function handleSAMLLoginError(errorMessage: string, cleanSignInData: boolean) { + if (cleanSignInData) { + Session.clearSignInData(); + } + + Session.setAccountError(errorMessage); + Navigation.goBack(ROUTES.HOME); +} + +export {getPhoneNumberWithoutSpecialChars, appendCountryCode, isEmailPublicDomain, validateNumber, getPhoneLogin, areEmailsFromSamePrivateDomain, postSAMLLogin, handleSAMLLoginError}; diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index 970ddce0b030..501a4e0fde10 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -10,8 +10,7 @@ import useLocalize from '@hooks/useLocalize'; import getPlatform from '@libs/getPlatform'; import getUAForWebView from '@libs/getUAForWebView'; import Log from '@libs/Log'; -import {fetchSAMLUrl} from '@libs/LoginUtils'; -import Navigation from '@libs/Navigation/Navigation'; +import {handleSAMLLoginError, postSAMLLogin} from '@libs/LoginUtils'; import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -28,7 +27,7 @@ function SAMLSignInPage() { useEffect(() => { // If we don't have a valid login to pass here, direct the user back to a clean sign in state to try again if (!credentials?.login) { - handleError(translate('common.error.email'), true); + handleSAMLLoginError(translate('common.error.email'), true); return; } @@ -41,16 +40,16 @@ function SAMLSignInPage() { body.append('email', credentials.login); body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); body.append('platform', getPlatform()); - fetchSAMLUrl(body) + postSAMLLogin(body) .then((response) => { if (!response || !response.url) { - handleError(translate('common.error.login')); + handleSAMLLoginError(translate('common.error.login'), false); return; } setSAMLUrl(response.url); }) .catch((error: Error) => { - handleError(error.message ?? translate('common.error.login')); + handleSAMLLoginError(error.message ?? translate('common.error.login'), false); }); }, [credentials?.login, SAMLUrl, translate]); @@ -86,15 +85,6 @@ function SAMLSignInPage() { [credentials?.login, shouldShowNavigation, account?.isLoading], ); - function handleError(errorMessage: string, cleanSignInData = false) { - if (cleanSignInData) { - Session.clearSignInData(); - } - - Session.setAccountError(errorMessage); - Navigation.goBack(ROUTES.HOME); - } - return ( { // If we don't have a valid login to pass here, direct the user back to a clean sign in state to try again if (!credentials?.login) { - handleError(translate('common.error.email'), true); + handleSAMLLoginError(translate('common.error.email'), true); return; } @@ -24,28 +21,19 @@ function SAMLSignInPage() { body.append('email', credentials.login); body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); - fetchSAMLUrl(body) + postSAMLLogin(body) .then((response) => { if (!response || !response.url) { - handleError(translate('common.error.login')); + handleSAMLLoginError(translate('common.error.login'), false); return; } window.location.replace(response.url); }) .catch((error: Error) => { - handleError(error.message ?? translate('common.error.login')); + handleSAMLLoginError(error.message ?? translate('common.error.login'), false); }); }, [credentials?.login, translate]); - function handleError(errorMessage: string, cleanSignInData = false) { - if (cleanSignInData) { - Session.clearSignInData(); - } - - Session.setAccountError(errorMessage); - Navigation.goBack(ROUTES.HOME); - } - return ; } From 50f47d19f248761e16591313954c33a5c9794e40 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Thu, 19 Dec 2024 19:55:47 -0500 Subject: [PATCH 21/25] remove noop --- src/libs/LoginUtils.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/libs/LoginUtils.ts b/src/libs/LoginUtils.ts index 16610d09af2e..237ecb5aa98e 100644 --- a/src/libs/LoginUtils.ts +++ b/src/libs/LoginUtils.ts @@ -84,14 +84,12 @@ function postSAMLLogin(body: FormData): Promise { method: CONST.NETWORK.METHOD.POST, body, credentials: 'omit', - }) - .then((response) => { - if (!response.ok) { - throw new Error('An error occurred while logging in. Please try again'); - } - return response.json() as Promise; - }) - .then((response) => response); + }).then((response) => { + if (!response.ok) { + throw new Error('An error occurred while logging in. Please try again'); + } + return response.json() as Promise; + }); } function handleSAMLLoginError(errorMessage: string, cleanSignInData: boolean) { From bd30dd4d988bf044246db8f2a681caa82efdfc20 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Thu, 19 Dec 2024 19:58:42 -0500 Subject: [PATCH 22/25] fix imports --- src/libs/LoginUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/LoginUtils.ts b/src/libs/LoginUtils.ts index 237ecb5aa98e..f496c9de0e6e 100644 --- a/src/libs/LoginUtils.ts +++ b/src/libs/LoginUtils.ts @@ -1,11 +1,11 @@ import {PUBLIC_DOMAINS, Str} from 'expensify-common'; import Onyx from 'react-native-onyx'; -import Navigation from '@libs/Navigation/Navigation'; -import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import * as Session from './actions/Session'; +import Navigation from './Navigation/Navigation'; import {parsePhoneNumber} from './PhoneNumber'; let countryCodeByIP: number; From 4ce67c8bc152043598fbddb349a74ffee5b6d5f2 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Thu, 19 Dec 2024 21:16:51 -0500 Subject: [PATCH 23/25] add back navigation import --- src/pages/signin/SAMLSignInPage/index.native.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index 501a4e0fde10..b252cb9cbed2 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -11,6 +11,7 @@ import getPlatform from '@libs/getPlatform'; import getUAForWebView from '@libs/getUAForWebView'; import Log from '@libs/Log'; import {handleSAMLLoginError, postSAMLLogin} from '@libs/LoginUtils'; +import Navigation from '@libs/Navigation/Navigation'; import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; From 9dc8399ed5a867eefb6a26bacf25118b2954e975 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 20 Dec 2024 20:47:36 -0500 Subject: [PATCH 24/25] fix import and show loading screen --- src/pages/signin/SAMLSignInPage/index.native.tsx | 14 ++++++++------ src/pages/signin/SAMLSignInPage/index.tsx | 10 +++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index b252cb9cbed2..a96859e876fd 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -10,7 +10,7 @@ import useLocalize from '@hooks/useLocalize'; import getPlatform from '@libs/getPlatform'; import getUAForWebView from '@libs/getUAForWebView'; import Log from '@libs/Log'; -import {handleSAMLLoginError, postSAMLLogin} from '@libs/LoginUtils'; +import * as LoginUtils from '@libs/LoginUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; @@ -28,7 +28,7 @@ function SAMLSignInPage() { useEffect(() => { // If we don't have a valid login to pass here, direct the user back to a clean sign in state to try again if (!credentials?.login) { - handleSAMLLoginError(translate('common.error.email'), true); + LoginUtils.handleSAMLLoginError(translate('common.error.email'), true); return; } @@ -41,16 +41,16 @@ function SAMLSignInPage() { body.append('email', credentials.login); body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); body.append('platform', getPlatform()); - postSAMLLogin(body) + LoginUtils.postSAMLLogin(body) .then((response) => { if (!response || !response.url) { - handleSAMLLoginError(translate('common.error.login'), false); + LoginUtils.handleSAMLLoginError(translate('common.error.login'), false); return; } setSAMLUrl(response.url); }) .catch((error: Error) => { - handleSAMLLoginError(error.message ?? translate('common.error.login'), false); + LoginUtils.handleSAMLLoginError(error.message ?? translate('common.error.login'), false); }); }, [credentials?.login, SAMLUrl, translate]); @@ -104,7 +104,7 @@ function SAMLSignInPage() { /> )} - {!!SAMLUrl && ( + {!!SAMLUrl ? ( } onNavigationStateChange={handleNavigationStateChange} /> + ) : ( + )} diff --git a/src/pages/signin/SAMLSignInPage/index.tsx b/src/pages/signin/SAMLSignInPage/index.tsx index e0c02a0d7b93..c78bce74c01b 100644 --- a/src/pages/signin/SAMLSignInPage/index.tsx +++ b/src/pages/signin/SAMLSignInPage/index.tsx @@ -2,7 +2,7 @@ import React, {useEffect} from 'react'; import {useOnyx} from 'react-native-onyx'; import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator'; import useLocalize from '@hooks/useLocalize'; -import {handleSAMLLoginError, postSAMLLogin} from '@libs/LoginUtils'; +import * as LoginUtils from '@libs/LoginUtils'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -13,7 +13,7 @@ function SAMLSignInPage() { useEffect(() => { // If we don't have a valid login to pass here, direct the user back to a clean sign in state to try again if (!credentials?.login) { - handleSAMLLoginError(translate('common.error.email'), true); + LoginUtils.handleSAMLLoginError(translate('common.error.email'), true); return; } @@ -21,16 +21,16 @@ function SAMLSignInPage() { body.append('email', credentials.login); body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); - postSAMLLogin(body) + LoginUtils.postSAMLLogin(body) .then((response) => { if (!response || !response.url) { - handleSAMLLoginError(translate('common.error.login'), false); + LoginUtils.handleSAMLLoginError(translate('common.error.login'), false); return; } window.location.replace(response.url); }) .catch((error: Error) => { - handleSAMLLoginError(error.message ?? translate('common.error.login'), false); + LoginUtils.handleSAMLLoginError(error.message ?? translate('common.error.login'), false); }); }, [credentials?.login, translate]); From 73e8164d31d8e1d0b094fba232785ffb10811b12 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 20 Dec 2024 20:53:02 -0500 Subject: [PATCH 25/25] fix double negation --- src/pages/signin/SAMLSignInPage/index.native.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index a96859e876fd..5f2a90fba4a6 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -104,7 +104,9 @@ function SAMLSignInPage() { /> )} - {!!SAMLUrl ? ( + {!SAMLUrl ? ( + + ) : ( } onNavigationStateChange={handleNavigationStateChange} /> - ) : ( - )}