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
7 changes: 7 additions & 0 deletions src/libs/actions/Delegate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {NativeModules} from 'react-native';
import Onyx from 'react-native-onyx';
import type {OnyxUpdate} from 'react-native-onyx';
import * as API from '@libs/API';
Expand All @@ -6,6 +7,7 @@ import {SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import * as ErrorUtils from '@libs/ErrorUtils';
import Log from '@libs/Log';
import * as NetworkStore from '@libs/Network/NetworkStore';
import {getCurrentUserEmail} from '@libs/Network/NetworkStore';
import * as SequentialQueue from '@libs/Network/SequentialQueue';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -107,6 +109,8 @@ function connect(email: string) {
NetworkStore.setAuthToken(response?.restrictedToken ?? null);
confirmReadyToOpenApp();
openApp();

NativeModules.HybridAppModule.switchAccount(email);
});
})
.catch((error) => {
Expand Down Expand Up @@ -170,6 +174,8 @@ function disconnect() {
NetworkStore.setAuthToken(response?.authToken ?? null);
confirmReadyToOpenApp();
openApp();

NativeModules.HybridAppModule.switchAccount(getCurrentUserEmail() ?? '');
});
})
.catch((error) => {
Expand Down Expand Up @@ -607,4 +613,5 @@ export {
clearDelegateRolePendingAction,
updateDelegateRole,
removeDelegate,
KEYS_TO_PRESERVE_DELEGATE_ACCESS,
};
32 changes: 25 additions & 7 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import Timers from '@libs/Timers';
import {hideContextMenu} from '@pages/home/report/ContextMenu/ReportActionContextMenu';
import {KEYS_TO_PRESERVE, openApp} from '@userActions/App';
import * as App from '@userActions/App';
import {KEYS_TO_PRESERVE_DELEGATE_ACCESS} from '@userActions/Delegate';
import * as Device from '@userActions/Device';
import * as PriorityMode from '@userActions/PriorityMode';
import redirectToSignIn from '@userActions/SignInRedirect';
Expand Down Expand Up @@ -483,13 +484,24 @@ function signUpUser() {
function signInAfterTransitionFromOldDot(transitionURL: string) {
const [route, queryParams] = transitionURL.split('?');

const {email, authToken, encryptedAuthToken, accountID, autoGeneratedLogin, autoGeneratedPassword, clearOnyxOnStart, completedHybridAppOnboarding, isSingleNewDotEntry, primaryLogin} =
Object.fromEntries(
queryParams.split('&').map((param) => {
const [key, value] = param.split('=');
return [key, value];
}),
);
const {
email,
authToken,
encryptedAuthToken,
accountID,
autoGeneratedLogin,
autoGeneratedPassword,
clearOnyxOnStart,
completedHybridAppOnboarding,
isSingleNewDotEntry,
primaryLogin,
shouldRemoveDelegatedAccess,
} = Object.fromEntries(
queryParams.split('&').map((param) => {
const [key, value] = param.split('=');
return [key, value];
}),
);

const clearOnyxForNewAccount = () => {
if (clearOnyxOnStart !== 'true') {
Expand All @@ -501,6 +513,12 @@ function signInAfterTransitionFromOldDot(transitionURL: string) {

const setSessionDataAndOpenApp = new Promise<Route>((resolve) => {
clearOnyxForNewAccount()
.then(() => {
if (!shouldRemoveDelegatedAccess) {
return;
}
return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS);
})
.then(() =>
Onyx.multiSet({
[ONYXKEYS.SESSION]: {email, authToken, encryptedAuthToken: decodeURIComponent(encryptedAuthToken), accountID: Number(accountID)},
Expand Down
1 change: 1 addition & 0 deletions src/types/modules/react-native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type StartupTimer from '@libs/StartupTimer/types';
type HybridAppModule = {
closeReactNativeApp: (shouldSignOut: boolean, shouldSetNVP: boolean) => void;
completeOnboarding: (status: boolean) => void;
switchAccount: (newDotCurrentAccount: string) => void;
exitApp: () => void;
};

Expand Down