Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
import type Session from '@src/types/onyx/Session';
import type {AutoAuthState} from '@src/types/onyx/Session';
import pkg from '../../../../package.json';
import {clearCachedAttachments} from '../Attachment';

Check warning on line 72 in src/libs/actions/Session/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unexpected parent import '../Attachment'. Use '@userActions/Attachment' instead
import clearCache from './clearCache';
import updateSessionAuthTokens from './updateSessionAuthTokens';

Expand All @@ -81,7 +81,7 @@
let isHybridAppSetupFinished = false;
let hasSwitchedAccountInHybridMode = false;

Onyx.connect({

Check warning on line 84 in src/libs/actions/Session/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
session = value ?? {};
Expand All @@ -106,19 +106,19 @@
});

let stashedSession: Session = {};
Onyx.connect({

Check warning on line 109 in src/libs/actions/Session/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.STASHED_SESSION,
callback: (value) => (stashedSession = value ?? {}),
});

let credentials: Credentials = {};
Onyx.connect({

Check warning on line 115 in src/libs/actions/Session/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CREDENTIALS,
callback: (value) => (credentials = value ?? {}),
});

let stashedCredentials: Credentials = {};
Onyx.connect({
Onyx.connectWithoutView({
key: ONYXKEYS.STASHED_CREDENTIALS,
callback: (value) => (stashedCredentials = value ?? {}),
});
Expand Down Expand Up @@ -277,8 +277,8 @@
return (sessionParam?.authTokenType ?? session.authTokenType) === CONST.AUTH_TOKEN_TYPES.ANONYMOUS;
}

function hasStashedSession(): boolean {
return !!(stashedSession.authToken && stashedCredentials.autoGeneratedLogin && stashedCredentials.autoGeneratedLogin !== '');
function hasStashedSession(stashedCredentialsParam: Credentials | undefined): boolean {
return !!(stashedSession.authToken && stashedCredentialsParam?.autoGeneratedLogin && stashedCredentialsParam.autoGeneratedLogin !== '');
}

/**
Expand Down Expand Up @@ -367,7 +367,7 @@
// If this is a supportal token, and we've received the parameters to stashSession as true, and
// we already have a stashedSession, that means we are supportal-ed, currently supportal-ing
// into another account and we want to keep the stashed data from the original account.
if (isSupportal && shouldStashSession && hasStashedSession()) {
if (isSupportal && shouldStashSession && hasStashedSession(stashedCredentials)) {
onyxSetParams = {
[ONYXKEYS.STASHED_CREDENTIALS]: stashedCredentials,
[ONYXKEYS.STASHED_SESSION]: stashedSession,
Expand All @@ -376,7 +376,7 @@

// If we should restore the stashed session, and we do not want to stash the current session, and we have a
// stashed session, then switch the account instead of completely logging out.
if (shouldRestoreStashedSession && !shouldStashSession && hasStashedSession()) {
if (shouldRestoreStashedSession && !shouldStashSession && hasStashedSession(stashedCredentials)) {
if (CONFIG.IS_HYBRID_APP) {
HybridAppModule.switchAccount({
newDotCurrentAccountEmail: stashedSession.email ?? '',
Expand All @@ -392,7 +392,7 @@
[ONYXKEYS.SESSION]: stashedSession,
};
}
if (shouldRestoreStashedSession && !shouldStashSession && !hasStashedSession()) {
if (shouldRestoreStashedSession && !shouldStashSession && !hasStashedSession(stashedCredentials)) {
Log.info('No stashed session found, clearing the session');
}

Expand All @@ -419,7 +419,7 @@
true,
true,
);
} else if (isPerformingSupportalLogout && hasStashedSession()) {
} else if (isPerformingSupportalLogout && hasStashedSession(stashedCredentials)) {
// We have confirmed here that the supportal agent was logged in, so we can restore the stashed session
// and then redirect to the oldDot supportal page to restore the stashed session
// Clear the Onyx DB of stale data that might be present from a previous session
Expand All @@ -432,7 +432,7 @@
});
});
});
} else if (isPerformingSupportalLogout && !hasStashedSession()) {
} else if (isPerformingSupportalLogout && !hasStashedSession(stashedCredentials)) {
// If the supportal agent was not logged in, we call `redirectToSignIn` to clear the Onyx DB
// and then redirect to supportal and restore the stashed session
redirectToSignIn().then(() => {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/settings/InitialSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
const [isTrackingGPS = false] = useOnyx(ONYXKEYS.GPS_DRAFT_DETAILS, {selector: isTrackingSelector});
const [lastDayFreeTrial] = useOnyx(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL);
const [unsharedBankAccount] = useOnyx(ONYXKEYS.UNSHARE_BANK_ACCOUNT);
const [stashedCredentials] = useOnyx(ONYXKEYS.STASHED_CREDENTIALS);
const privateSubscription = usePrivateSubscription();
const subscriptionPlan = useSubscriptionPlan();
const previousUserPersonalDetails = usePrevious(currentUserPersonalDetails);
Expand Down Expand Up @@ -344,7 +345,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
* Return a list of menu items data for general section
* @returns object with translationKey, style and items for the general section
*/
const signOutTranslationKey = isSupportAuthToken() && hasStashedSession() ? 'initialSettingsPage.restoreStashed' : 'initialSettingsPage.signOut';
const signOutTranslationKey = isSupportAuthToken() && hasStashedSession(stashedCredentials) ? 'initialSettingsPage.restoreStashed' : 'initialSettingsPage.signOut';
const generalMenuItemsData: Menu = {
sectionStyle: {
...styles.pt4,
Expand Down
Loading