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 82b51651cacc..160746b90554 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -332,19 +332,19 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) { isLoading: true, }, }, - ]; - - const successData: OnyxUpdate[] = [ + // We are making a temporary modification to 'signedInWithShortLivedAuthToken' to ensure that 'App.openApp' will be called at least once { onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.ACCOUNT, + key: ONYXKEYS.SESSION, value: { - isLoading: false, + signedInWithShortLivedAuthToken: true, }, }, ]; - const failureData: OnyxUpdate[] = [ + // 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[] = [ { onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.ACCOUNT, @@ -352,8 +352,18 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) { isLoading: false, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.SESSION, + value: { + signedInWithShortLivedAuthToken: null, + }, + }, ]; + 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. // scene 2: the user is transitioning to desktop app from a different account on web app. 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;