diff --git a/src/libs/SessionUtils.ts b/src/libs/SessionUtils.ts index 1afa3a75e081..c73513c747af 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 82d371e16bed..d7043ee7b3eb 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -339,19 +339,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, @@ -359,8 +359,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;