Skip to content

Commit

Permalink
Merge pull request #32245 from AmjedNazzal/Issue31789
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisl authored Dec 14, 2023
2 parents 9d2ea87 + eb1207f commit 06662fa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/libs/SessionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 16 additions & 6 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,28 +339,38 @@ 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,
value: {
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.
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 06662fa

Please sign in to comment.