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
5 changes: 3 additions & 2 deletions src/Expensify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function Expensify() {
const [onboardingInitialPath] = useOnyx(ONYXKEYS.ONBOARDING_LAST_VISITED_PATH, {canBeMissing: true});
const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false});
const [stashedCredentials = CONST.EMPTY_OBJECT] = useOnyx(ONYXKEYS.STASHED_CREDENTIALS, {canBeMissing: true});
const [stashedSession] = useOnyx(ONYXKEYS.STASHED_SESSION, {canBeMissing: true});

useDebugShortcut();
usePriorityMode();
Expand Down Expand Up @@ -285,8 +286,8 @@ function Expensify() {
if (account?.delegatedAccess?.delegates?.some((d) => d.email === account?.delegatedAccess?.delegate)) {
return;
}
disconnect({stashedCredentials});
}, [account?.delegatedAccess?.delegates, account?.delegatedAccess?.delegate, stashedCredentials]);
disconnect({stashedCredentials, stashedSession});
}, [account?.delegatedAccess?.delegates, account?.delegatedAccess?.delegate, stashedCredentials, stashedSession]);

// Display a blank page until the onyx migration completes
if (!isOnyxMigrated) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/AccountSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) {
const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS, {canBeMissing: true});
const [stashedCredentials = CONST.EMPTY_OBJECT] = useOnyx(ONYXKEYS.STASHED_CREDENTIALS, {canBeMissing: true});
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true});
const [stashedSession] = useOnyx(ONYXKEYS.STASHED_SESSION, {canBeMissing: true});

const buttonRef = useRef<HTMLDivElement>(null);
const {windowHeight} = useWindowDimensions();
Expand Down Expand Up @@ -142,7 +143,7 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) {
close(() => setShouldShowOfflineModal(true));
return;
}
disconnect({stashedCredentials});
disconnect({stashedCredentials, stashedSession});
},
}),
currentUserMenuItem,
Expand Down
18 changes: 8 additions & 10 deletions src/libs/actions/Delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ import {getCurrentUserAccountID} from './Report';
import updateSessionAuthTokens from './Session/updateSessionAuthTokens';
import updateSessionUser from './Session/updateSessionUser';

let stashedSession: Session = {};
Onyx.connect({
key: ONYXKEYS.STASHED_SESSION,
callback: (value) => (stashedSession = value ?? {}),
});

let activePolicyID: OnyxEntry<string>;
Onyx.connect({
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
Expand Down Expand Up @@ -91,7 +85,11 @@ type WithSession = {
session: Session | undefined;
};

type DisconnectParams = WithStashedCredentials;
type WithStashedSession = {
stashedSession: Session | undefined;
};

type DisconnectParams = WithStashedCredentials & WithStashedSession;

// Clear delegator-level errors
type ClearDelegatorErrorsParams = WithDelegatedAccess;
Expand Down Expand Up @@ -225,7 +223,7 @@ function connect({email, delegatedAccess, credentials, session, isFromOldDot = f
});
}

function disconnect({stashedCredentials}: DisconnectParams) {
function disconnect({stashedCredentials, stashedSession}: DisconnectParams) {
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -268,13 +266,13 @@ function disconnect({stashedCredentials}: DisconnectParams) {
.then((response) => {
if (!response?.authToken || !response?.encryptedAuthToken) {
Log.alert('[Delegate] No auth token returned while disconnecting as a delegate');
restoreDelegateSession(stashedSession);
restoreDelegateSession(stashedSession ?? {});
return;
}

if (!response?.requesterID || !response?.requesterEmail) {
Log.alert('[Delegate] No requester data returned while disconnecting as a delegate');
restoreDelegateSession(stashedSession);
restoreDelegateSession(stashedSession ?? {});
return;
}

Expand Down
Loading