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
3 changes: 2 additions & 1 deletion src/components/AccountSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) {
const [isDebugModeEnabled] = useOnyx(ONYXKEYS.IS_DEBUG_MODE_ENABLED, {canBeMissing: true});
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 buttonRef = useRef<HTMLDivElement>(null);
const {windowHeight} = useWindowDimensions();
Expand Down Expand Up @@ -161,7 +162,7 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) {
close(() => setShouldShowOfflineModal(true));
return;
}
connect({email, delegatedAccess: account?.delegatedAccess, credentials});
connect({email, delegatedAccess: account?.delegatedAccess, credentials, session});
},
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function AuthScreens() {
// or returning from background. If so, we'll assume they have some app data already and we can call reconnectApp() instead of openApp() and connect() for delegator from OldDot.
if (SessionUtils.didUserLogInDuringSession() || delegatorEmail) {
if (delegatorEmail) {
connect({email: delegatorEmail, delegatedAccess: account?.delegatedAccess, credentials, isFromOldDot: true})
connect({email: delegatorEmail, delegatedAccess: account?.delegatedAccess, credentials, session, isFromOldDot: true})
?.then((success) => {
App.setAppLoading(!!success);
})
Expand Down
16 changes: 7 additions & 9 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 session: Session = {};
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (value) => (session = value ?? {}),
});

let stashedSession: Session = {};
Onyx.connect({
key: ONYXKEYS.STASHED_SESSION,
Expand Down Expand Up @@ -93,6 +87,10 @@ type WithStashedCredentials = {
stashedCredentials: Credentials | undefined;
};

type WithSession = {
session: Session | undefined;
};

type DisconnectParams = WithStashedCredentials;

// Clear delegator-level errors
Expand All @@ -114,7 +112,7 @@ type UpdateDelegateRoleParams = WithEmail & WithRole & WithValidateCode & WithDe
type IsConnectedAsDelegateParams = WithDelegatedAccess;

// Connect as delegate
type ConnectParams = WithEmail & WithDelegatedAccess & WithOldDotFlag & WithCredentials;
type ConnectParams = WithEmail & WithDelegatedAccess & WithOldDotFlag & WithCredentials & WithSession;

// Clear pending action for role update
type ClearDelegateRolePendingActionParams = WithEmail & WithDelegatedAccess;
Expand All @@ -123,13 +121,13 @@ type ClearDelegateRolePendingActionParams = WithEmail & WithDelegatedAccess;
* Connects the user as a delegate to another account.
* Returns a Promise that resolves to true on success, false on failure, or undefined if not applicable.
*/
function connect({email, delegatedAccess, credentials, isFromOldDot = false}: ConnectParams) {
function connect({email, delegatedAccess, credentials, session, isFromOldDot = false}: ConnectParams) {
if (!delegatedAccess?.delegators && !isFromOldDot) {
return;
}

Onyx.set(ONYXKEYS.STASHED_CREDENTIALS, credentials ?? {});
Onyx.set(ONYXKEYS.STASHED_SESSION, session);
Onyx.set(ONYXKEYS.STASHED_SESSION, session ?? {});

const previousAccountID = getCurrentUserAccountID();

Expand Down