From 762bdde2a626f6d4a3fff29ca19e1124db859b13 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Wed, 2 Apr 2025 17:11:40 +0200 Subject: [PATCH] Redirect user to sign in page if auth expired and there are no creds --- src/libs/Authentication.ts | 15 ++++++++++++--- src/libs/E2E/actions/e2eLogin.ts | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libs/Authentication.ts b/src/libs/Authentication.ts index f72d7891d0e..1237e681d7c 100644 --- a/src/libs/Authentication.ts +++ b/src/libs/Authentication.ts @@ -31,10 +31,19 @@ Onyx.connect({ }, }); -function Authenticate(parameters: Parameters): Promise { +function Authenticate(parameters: Parameters): Promise | undefined { const commandName = 'Authenticate'; - requireParameters(['partnerName', 'partnerPassword', 'partnerUserID', 'partnerUserSecret'], parameters, commandName); + try { + requireParameters(['partnerName', 'partnerPassword', 'partnerUserID', 'partnerUserSecret'], parameters, commandName); + } catch (error) { + const errorMessage = (error as Error).message; + Log.hmmm('Redirecting to Sign In because we failed to reauthenticate', { + error: errorMessage, + }); + redirectToSignIn(errorMessage); + return; + } return post(commandName, { // When authenticating for the first time, we pass useExpensifyLogin as true so we check @@ -77,7 +86,7 @@ function reauthenticate(command = ''): Promise | undefined { partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD, partnerUserID: credentials?.autoGeneratedLogin, partnerUserSecret: credentials?.autoGeneratedPassword, - }).then((response) => { + })?.then((response) => { if (response.jsonCode === CONST.JSON_CODE.UNABLE_TO_RETRY) { // When a fetch() fails due to a network issue and an error is thrown we won't log the user out. Most likely they // have a spotty connection and will need to retry reauthenticate when they come back online. Error so it can be handled by the retry mechanism. diff --git a/src/libs/E2E/actions/e2eLogin.ts b/src/libs/E2E/actions/e2eLogin.ts index e325332d7dc..e01e51dec88 100644 --- a/src/libs/E2E/actions/e2eLogin.ts +++ b/src/libs/E2E/actions/e2eLogin.ts @@ -52,7 +52,7 @@ export default function (): Promise { // authenticate with a predefined user console.debug('[E2E] Signing in…'); Authenticate(e2eUserCredentials) - .then((response) => { + ?.then((response) => { Onyx.merge(ONYXKEYS.SESSION, { authToken: response.authToken, creationDate: new Date().getTime(),