From f93f34b708b51d0188fb1b8ba99c21e02aa330c2 Mon Sep 17 00:00:00 2001 From: AmjedNazzal Date: Thu, 30 Nov 2023 10:54:05 +0300 Subject: [PATCH 1/6] Fix for issue #31789 --- src/libs/SessionUtils.ts | 5 +++-- src/libs/actions/Session/index.ts | 16 ++++++++++++++++ src/types/onyx/Session.ts | 3 +++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/libs/SessionUtils.ts b/src/libs/SessionUtils.ts index 6cd20e0b56b2..53de614f0f8d 100644 --- a/src/libs/SessionUtils.ts +++ b/src/libs/SessionUtils.ts @@ -35,8 +35,9 @@ Onyx.connect({ if (loggedInDuringSession) { return; } - - if (session?.authToken) { + // We are incorporating a check for 'signedInWithShortLivedAuthToken' to handle cases where login is performed using a ShortLivedAuthToken + // This check is necessary because, with ShortLivedAuthToken, 'authToken' gets populated, leading to 'loggedInDuringSession' being assigned a false value + if (session?.authToken && !session?.signedInWithShortLivedAuthToken) { loggedInDuringSession = false; } else { loggedInDuringSession = true; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 559f60a21c98..5d86bcb74bb2 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -331,6 +331,15 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) { isLoading: true, }, }, + // We are making a temporary modification to 'signedInWithShortLivedAuthToken' to ensure that 'App.openApp' will be called at least once + // Subsequently, we revert it back to the default value (undefined) in 'successData' to ensure the user is logged out on refresh + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.SESSION, + value: { + signedInWithShortLivedAuthToken: true, + }, + }, ]; const successData: OnyxUpdate[] = [ @@ -341,6 +350,13 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) { isLoading: false, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.SESSION, + value: { + signedInWithShortLivedAuthToken: undefined, + }, + }, ]; const failureData: OnyxUpdate[] = [ diff --git a/src/types/onyx/Session.ts b/src/types/onyx/Session.ts index faaa493b1286..aa4d52075d34 100644 --- a/src/types/onyx/Session.ts +++ b/src/types/onyx/Session.ts @@ -27,6 +27,9 @@ type Session = { /** Server side errors keyed by microtime */ errors?: OnyxCommon.Errors; + + /** User signed in with short lived token */ + signedInWithShortLivedAuthToken?: boolean; }; export default Session; From cb6b0170ac51f36f3cb75d615111fcfc2ce8c2e2 Mon Sep 17 00:00:00 2001 From: Amjed Nazzal <74202751+AmjedNazzal@users.noreply.github.com> Date: Thu, 30 Nov 2023 16:33:02 +0300 Subject: [PATCH 2/6] Update index.ts --- src/libs/actions/Session/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 5d86bcb74bb2..62ad5020f3c3 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -332,7 +332,6 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) { }, }, // We are making a temporary modification to 'signedInWithShortLivedAuthToken' to ensure that 'App.openApp' will be called at least once - // Subsequently, we revert it back to the default value (undefined) in 'successData' to ensure the user is logged out on refresh { onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.SESSION, @@ -342,6 +341,7 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) { }, ]; + // Subsequently, we revert it back to the default value of signedInWithShortLivedAuthToken (undefined) in 'successData' to ensure the user is logged out on refresh const successData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -367,6 +367,13 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) { isLoading: false, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.SESSION, + value: { + signedInWithShortLivedAuthToken: undefined, + }, + }, ]; // 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. From 771e292bf1e7fa0769fad7b26b4b6b0ca29b75af Mon Sep 17 00:00:00 2001 From: Amjed Nazzal <74202751+AmjedNazzal@users.noreply.github.com> Date: Thu, 30 Nov 2023 17:24:42 +0300 Subject: [PATCH 3/6] Fix - issue #31789 adjusting comments --- 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 62ad5020f3c3..ccdb5216420e 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -341,7 +341,6 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) { }, ]; - // Subsequently, we revert it back to the default value of signedInWithShortLivedAuthToken (undefined) in 'successData' to ensure the user is logged out on refresh const successData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -350,6 +349,7 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) { isLoading: false, }, }, + // Subsequently, we revert it back to the default value of signedInWithShortLivedAuthToken (undefined) in 'successData' to ensure the user is logged out on refresh { onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.SESSION, From 9b6dca761ee11b90384b8b475b88400b9af282ab Mon Sep 17 00:00:00 2001 From: Amjed Nazzal <74202751+AmjedNazzal@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:01:52 +0300 Subject: [PATCH 4/6] Fix - issue #31789 merging success and failure data --- src/libs/actions/Session/index.ts | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index ccdb5216420e..0e6fb9099de3 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -341,25 +341,9 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) { }, ]; - const successData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.ACCOUNT, - value: { - isLoading: false, - }, - }, - // Subsequently, we revert it back to the default value of signedInWithShortLivedAuthToken (undefined) in 'successData' to ensure the user is logged out on refresh - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.SESSION, - value: { - signedInWithShortLivedAuthToken: undefined, - }, - }, - ]; - - const failureData: OnyxUpdate[] = [ + // Subsequently, we revert it back to the default value of 'signedInWithShortLivedAuthToken' (undefined) in 'successData' or 'failureData' to ensure the user is logged out on refresh + // We are combining both success and failure data params into one const as they are identical + const resolutionData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.ACCOUNT, @@ -375,6 +359,9 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) { }, }, ]; + + const successData = resolutionData; + const failureData = resolutionData; // 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. From 4ecc326b2d700c0a7128f4d824541fa48a3d14c9 Mon Sep 17 00:00:00 2001 From: AmjedNazzal Date: Fri, 1 Dec 2023 17:11:00 +0300 Subject: [PATCH 5/6] Fix - Issue #31789 - Lint fix --- 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 0e6fb9099de3..5b7b460580fc 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -359,7 +359,7 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) { }, }, ]; - + const successData = resolutionData; const failureData = resolutionData; From eb1207f34d1d429a10882a049a121e34a0bb9234 Mon Sep 17 00:00:00 2001 From: Amjed Nazzal <74202751+AmjedNazzal@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:16:32 +0300 Subject: [PATCH 6/6] Fix issue #31789 changed undefined to null --- src/libs/actions/Session/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 5bca9fee89c7..160746b90554 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -342,7 +342,7 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) { }, ]; - // Subsequently, we revert it back to the default value of 'signedInWithShortLivedAuthToken' (undefined) in 'successData' or 'failureData' to ensure the user is logged out on refresh + // Subsequently, we revert it back to the default value of 'signedInWithShortLivedAuthToken' in 'successData' or 'failureData' to ensure the user is logged out on refresh // We are combining both success and failure data params into one const as they are identical const resolutionData: OnyxUpdate[] = [ { @@ -356,7 +356,7 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) { onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.SESSION, value: { - signedInWithShortLivedAuthToken: undefined, + signedInWithShortLivedAuthToken: null, }, }, ];