From 34df01bfd6cf9ddb6338f3b46de73a3d28f772ec Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 4 Mar 2024 02:47:26 +0700 Subject: [PATCH 1/4] fix public room is not opened --- src/Expensify.tsx | 4 ++-- src/libs/actions/Report.ts | 4 ++-- src/libs/actions/Session/index.ts | 8 ++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index f822862ec434..5681be838ca8 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -183,12 +183,12 @@ function Expensify({ // If the app is opened from a deep link, get the reportID (if exists) from the deep link and navigate to the chat report Linking.getInitialURL().then((url) => { setInitialUrl(url); - Report.openReportFromDeepLink(url ?? '', isAuthenticated); + Report.openReportFromDeepLink(url ?? ''); }); // Open chat report from a deep link (only mobile native) Linking.addEventListener('url', (state) => { - Report.openReportFromDeepLink(state.url, isAuthenticated); + Report.openReportFromDeepLink(state.url); }); return () => { diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 7ad12cf3e1ed..938a053cab3d 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2214,10 +2214,10 @@ function toggleEmojiReaction( addEmojiReaction(originalReportID, reportAction.reportActionID, emoji, skinTone); } -function openReportFromDeepLink(url: string, isAuthenticated: boolean) { +function openReportFromDeepLink(url: string) { const reportID = ReportUtils.getReportIDFromLink(url); - if (reportID && !isAuthenticated) { + if (reportID && !Session.isAuthenticated()) { // Call the OpenReport command to check in the server if it's a public room. If so, we'll open it as an anonymous user openReport(reportID, [], {}, '0', true); diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 76f335a3bec0..a8e9ccaf1a21 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -110,6 +110,13 @@ function isAnonymousUser(): boolean { return sessionAuthTokenType === CONST.AUTH_TOKEN_TYPE.ANONYMOUS; } +/** + * Checks if the user is authenticated + */ +function isAuthenticated(): boolean { + return !!sessionAuthToken; +} + function signOutAndRedirectToSignIn(shouldReplaceCurrentScreen?: boolean) { Log.info('Redirecting to Sign In because signOut() was called'); hideContextMenu(false); @@ -929,4 +936,5 @@ export { validateTwoFactorAuth, waitForUserSignIn, canAccessRouteByAnonymousUser, + isAuthenticated, }; From 284b2760f86c5dc4595472235e00d47425599231 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 6 Mar 2024 07:40:21 +0700 Subject: [PATCH 2/4] fix session after merge main --- src/libs/actions/Session/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index dcefb429be0e..9fab4ccffebb 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -188,7 +188,7 @@ function hasStashedSession(): boolean { * Checks if the user is authenticated */ function isAuthenticated(): boolean { - return !!sessionAuthToken; + return !!session.authToken; } function signOutAndRedirectToSignIn(shouldReplaceCurrentScreen?: boolean, shouldStashSession?: boolean) { From 29dfda4c25358012ecbd1879c7ff2ef76ec911bf Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 12 Mar 2024 10:43:41 +0700 Subject: [PATCH 3/4] fix rename isAuthenticated to hasAuthToken --- src/libs/actions/Report.ts | 2 +- src/libs/actions/Session/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 938a053cab3d..15ce4f904053 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2217,7 +2217,7 @@ function toggleEmojiReaction( function openReportFromDeepLink(url: string) { const reportID = ReportUtils.getReportIDFromLink(url); - if (reportID && !Session.isAuthenticated()) { + if (reportID && !Session.hasAuthToken()) { // Call the OpenReport command to check in the server if it's a public room. If so, we'll open it as an anonymous user openReport(reportID, [], {}, '0', true); diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 9fab4ccffebb..ae909367e7d5 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -187,7 +187,7 @@ function hasStashedSession(): boolean { /** * Checks if the user is authenticated */ -function isAuthenticated(): boolean { +function hasAuthToken(): boolean { return !!session.authToken; } @@ -994,7 +994,7 @@ export { validateTwoFactorAuth, waitForUserSignIn, canAccessRouteByAnonymousUser, - isAuthenticated, + hasAuthToken, signInWithSupportAuthToken, isSupportAuthToken, hasStashedSession, From 8b7e63b5dcb9dba08f37dd1f540fb76a8388a950 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 12 Mar 2024 10:48:42 +0700 Subject: [PATCH 4/4] fix comment --- src/libs/actions/Session/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index f440f6d2a07d..47d5419893f5 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -185,7 +185,7 @@ function hasStashedSession(): boolean { } /** - * Checks if the user is authenticated + * Checks if the user has authToken */ function hasAuthToken(): boolean { return !!session.authToken;