Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add supportal navigation #35410

Merged
merged 81 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
eb42af8
adding new properties
danieldoglas Jan 30, 2024
fe65f54
adding new logic for setting supportal token on public pages
danieldoglas Jan 30, 2024
ad993ab
adding logic in case you already have a session
danieldoglas Jan 30, 2024
f5acfa8
converting accountID to Number
danieldoglas Jan 30, 2024
9020de7
adding type of auth token to setSupportAuthToken
danieldoglas Jan 30, 2024
214590e
Merge branch 'main' into dsilva_addSupportalNavigation
danieldoglas Feb 2, 2024
9343f30
Merge branch 'main' into dsilva_addSupportalNavigation
danieldoglas Feb 6, 2024
28c567f
adding logs
danieldoglas Feb 6, 2024
0b896fd
fixing linter
danieldoglas Feb 6, 2024
a4a6ab1
Merge branch 'main' into dsilva_addSupportalNavigation
danieldoglas Feb 6, 2024
72391f0
Merge branch 'main' into dsilva_addSupportalNavigation
danieldoglas Feb 6, 2024
9b015a2
prettier
danieldoglas Feb 6, 2024
53bcd57
Merge branch 'main' into dsilva_addSupportalNavigation
danieldoglas Feb 9, 2024
1553c7f
Merge branch 'main' into dsilva_addSupportalNavigation
danieldoglas Feb 19, 2024
fde063a
fixes after merge
danieldoglas Feb 19, 2024
807a030
remove unused file
danieldoglas Feb 19, 2024
39c18b1
removing function setSupportAuthToken from network since it is alread…
danieldoglas Feb 19, 2024
0a79955
creating new parameters for using on API request
danieldoglas Feb 19, 2024
594693c
adding new method to call API with support token
danieldoglas Feb 19, 2024
a453d37
reusing function on signInWithShortLivedAuthToken
danieldoglas Feb 19, 2024
234df26
prettier
danieldoglas Feb 19, 2024
fccc71e
calling right method now
danieldoglas Feb 19, 2024
e8401c1
changing to right method on login page
danieldoglas Feb 19, 2024
51a84d3
prettier
danieldoglas Feb 20, 2024
fe97f39
changing method from getSupportAuthToken to isSupportAuthToken
danieldoglas Feb 20, 2024
f9b4116
simplifying token check
danieldoglas Feb 20, 2024
eaa9186
checking new method for support auth token
danieldoglas Feb 20, 2024
25032f1
updating comment
danieldoglas Feb 20, 2024
e7fd9c9
prettier
danieldoglas Feb 20, 2024
2bd4030
DRYing the types
danieldoglas Feb 23, 2024
2826307
adding token types to the const file
danieldoglas Feb 23, 2024
b00fe7b
changing method to isSupportTAuthToken to check the type from const
danieldoglas Feb 23, 2024
d7400f4
changing type to use valueOF const
danieldoglas Feb 23, 2024
8dc2f7e
changing usages to constant
danieldoglas Feb 23, 2024
61f0b39
updating usage to const
danieldoglas Feb 23, 2024
0956d29
separate set and clear support auth token
danieldoglas Feb 23, 2024
d136642
prettier
danieldoglas Feb 23, 2024
6eada6e
using finally data
danieldoglas Feb 23, 2024
286d4b8
addressing the last reference to supportal to use const
danieldoglas Feb 23, 2024
0e03fc5
changing inheritance to reference
danieldoglas Feb 23, 2024
533bff2
undo changes to ref
danieldoglas Feb 23, 2024
f1772a0
readding optional parameters and fixing routes to include central pan…
danieldoglas Feb 24, 2024
42e0295
removing explicity typing
danieldoglas Feb 24, 2024
53e8803
Merge branch 'main' into dsilva_addSupportalNavigation
danieldoglas Feb 28, 2024
aa31296
using new parameter of authtokentype
danieldoglas Feb 28, 2024
7bd9d4b
adding key for new translated item
danieldoglas Feb 29, 2024
1c8bcf1
exporting function to check if it's supportal
danieldoglas Feb 29, 2024
2a34120
changing text based on which type of token we're using
danieldoglas Feb 29, 2024
c052286
creating new keys for stashed sessiond ata
danieldoglas Feb 29, 2024
65ad0ab
mapping new keys
danieldoglas Feb 29, 2024
4258128
ignoring new keys when clearing the storage
danieldoglas Feb 29, 2024
226f6aa
adding logic to restore stashed login
danieldoglas Feb 29, 2024
e5b27b5
passing new parameters to stash login
danieldoglas Feb 29, 2024
4760635
using the whole session object so we can store it easily
danieldoglas Feb 29, 2024
0930f3c
logic should work
danieldoglas Feb 29, 2024
54db30b
adding one more check on the translation key
danieldoglas Feb 29, 2024
463fcb4
returning promise on signin redirect
danieldoglas Feb 29, 2024
caf1cf6
using promise to wait before setting the stashed data on session and …
danieldoglas Feb 29, 2024
bb51ff6
fixing message that should be shown
danieldoglas Feb 29, 2024
ddc3271
changin order on login page so we can check if it's supportal first
danieldoglas Feb 29, 2024
2df9180
passing parameter to store stashed login data
danieldoglas Feb 29, 2024
5a5d5bf
Removing stashed keys from clear storage
danieldoglas Mar 4, 2024
0240d99
removing transition from history on logout previous user page
danieldoglas Mar 4, 2024
907b2e4
removing transition from route on loginWithShortLivedAuthToken
danieldoglas Mar 4, 2024
25021a3
add additional logic to Session to confirm we're stashing credentials…
danieldoglas Mar 4, 2024
61ec184
Add propertitieson authscreen to guarantee we're executing the right …
danieldoglas Mar 4, 2024
ffb1d56
adding spanish translation
danieldoglas Mar 4, 2024
eed0aaf
prettier
danieldoglas Mar 4, 2024
e7b135f
Merge branch 'main' into dsilva_addSupportalNavigation
danieldoglas Mar 4, 2024
f06e890
linter
danieldoglas Mar 4, 2024
573bbb5
setting settion import as type
danieldoglas Mar 4, 2024
6d63941
refactor function for simplicity
danieldoglas Mar 4, 2024
a5f45b2
prettier again
danieldoglas Mar 4, 2024
114aee3
renaming property to clearer name
danieldoglas Mar 4, 2024
4af67a9
removing check if it's supportal call when enhancing the parameters
danieldoglas Mar 4, 2024
20b943d
setting parameters as optional
danieldoglas Mar 4, 2024
6fd8978
DRYing functions
danieldoglas Mar 4, 2024
992ed3a
DRYing functions
danieldoglas Mar 4, 2024
2931b5e
getting function back to network
danieldoglas Mar 4, 2024
9904a01
Merge branch 'main' into dsilva_addSupportalNavigation
danieldoglas Mar 4, 2024
205cb7f
fix comment after merge
danieldoglas Mar 4, 2024
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: 5 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ const CONST = {
FAILED: 'failed',
},

AUTH_TOKEN_TYPES: {
ANONYMOUS: 'anonymousAccount',
SUPPORT: 'support',
},

AVATAR_MAX_ATTACHMENT_SIZE: 6291456,

AVATAR_ALLOWED_EXTENSIONS: ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg'],
Expand Down
5 changes: 5 additions & 0 deletions src/libs/API/parameters/SignInWithSupportAuthTokenParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type SignInWithSupportAuthTokenParams = {
authToken: string;
};

export default SignInWithSupportAuthTokenParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type {default as SendPerformanceTimingParams} from './SendPerformanceTimi
export type {default as SetContactMethodAsDefaultParams} from './SetContactMethodAsDefaultParams';
export type {default as SignInUserWithLinkParams} from './SignInUserWithLinkParams';
export type {default as SignInWithShortLivedAuthTokenParams} from './SignInWithShortLivedAuthTokenParams';
export type {default as SignInWithSupportAuthTokenParams} from './SignInWithSupportAuthTokenParams';
export type {default as UnlinkLoginParams} from './UnlinkLoginParams';
export type {default as UpdateAutomaticTimezoneParams} from './UpdateAutomaticTimezoneParams';
export type {default as UpdateChatPriorityModeParams} from './UpdateChatPriorityModeParams';
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ const READ_COMMANDS = {
OPEN_ENABLE_PAYMENTS_PAGE: 'OpenEnablePaymentsPage',
BEGIN_SIGNIN: 'BeginSignIn',
SIGN_IN_WITH_SHORT_LIVED_AUTH_TOKEN: 'SignInWithShortLivedAuthToken',
SIGN_IN_WITH_SUPPORT_AUTH_TOKEN: 'SignInWithSupportAuthToken',
OPEN_WORKSPACE_REIMBURSE_VIEW: 'OpenWorkspaceReimburseView',
OPEN_WORKSPACE: 'OpenWorkspace',
OPEN_WORKSPACE_MEMBERS_PAGE: 'OpenWorkspaceMembersPage',
Expand Down Expand Up @@ -351,6 +352,7 @@ type ReadCommandParameters = {
[READ_COMMANDS.OPEN_ENABLE_PAYMENTS_PAGE]: EmptyObject;
[READ_COMMANDS.BEGIN_SIGNIN]: Parameters.BeginSignInParams;
[READ_COMMANDS.SIGN_IN_WITH_SHORT_LIVED_AUTH_TOKEN]: Parameters.SignInWithShortLivedAuthTokenParams;
[READ_COMMANDS.SIGN_IN_WITH_SUPPORT_AUTH_TOKEN]: Parameters.SignInWithSupportAuthTokenParams;
[READ_COMMANDS.OPEN_WORKSPACE_REIMBURSE_VIEW]: Parameters.OpenWorkspaceReimburseViewParams;
[READ_COMMANDS.OPEN_WORKSPACE]: Parameters.OpenWorkspaceParams;
[READ_COMMANDS.OPEN_WORKSPACE_MEMBERS_PAGE]: Parameters.OpenWorkspaceMembersPageParams;
Expand Down
28 changes: 11 additions & 17 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,20 +460,26 @@ type BottomTabNavigatorParamList = {
[SCREENS.WORKSPACE.INITIAL]: undefined;
};

type PublicScreensParamList = {
type SharedScreensParamList = {
[NAVIGATORS.BOTTOM_TAB_NAVIGATOR]: NavigatorScreenParams<BottomTabNavigatorParamList>;
[SCREENS.TRANSITION_BETWEEN_APPS]: {
email?: string;
email: string;
danieldoglas marked this conversation as resolved.
Show resolved Hide resolved
accountID: number;
error?: string;
shortLivedAuthToken?: string;
shortLivedToken?: string;
supportAuthToken: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like most of these should be optional. Keep in mind that these are basically URL params. We won't always have a supportAuthToken, so that should be optional:

Suggested change
supportAuthToken: string;
supportAuthToken?: string;

shortLivedAuthToken: string;
shortLivedToken: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk why we have both shortLivedAuthToken and shortLivedToken, but I hate it

exitTo?: Routes | HybridAppRoute;
shouldForceLogin: string;
};
[SCREENS.VALIDATE_LOGIN]: {
accountID: string;
validateCode: string;
exitTo?: Routes | HybridAppRoute;
};
};

type PublicScreensParamList = SharedScreensParamList & {
[SCREENS.UNLINK_LOGIN]: {
accountID?: string;
validateCode?: string;
Expand All @@ -483,19 +489,7 @@ type PublicScreensParamList = {
[SCREENS.SAML_SIGN_IN]: undefined;
};

type AuthScreensParamList = {
[NAVIGATORS.BOTTOM_TAB_NAVIGATOR]: NavigatorScreenParams<BottomTabNavigatorParamList>;
[NAVIGATORS.CENTRAL_PANE_NAVIGATOR]: NavigatorScreenParams<CentralPaneNavigatorParamList>;
danieldoglas marked this conversation as resolved.
Show resolved Hide resolved
[SCREENS.VALIDATE_LOGIN]: {
accountID: string;
validateCode: string;
};
[SCREENS.TRANSITION_BETWEEN_APPS]: {
shouldForceLogin: string;
email: string;
shortLivedAuthToken: string;
exitTo: string;
};
type AuthScreensParamList = SharedScreensParamList & {
[SCREENS.CONCIERGE]: undefined;
[SCREENS.REPORT_ATTACHMENTS]: {
reportID: string;
Expand Down
17 changes: 7 additions & 10 deletions src/libs/Network/NetworkStore.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Onyx from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS} from '@libs/API/types';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type Credentials from '@src/types/onyx/Credentials';

let credentials: Credentials | null = null;
let authToken: string | null = null;
let supportAuthToken: string | null = null;
let authTokenType: ValueOf<typeof CONST.AUTH_TOKEN_TYPES> | null;
let currentUserEmail: string | null = null;
let offline = false;
let authenticating = false;
Expand Down Expand Up @@ -51,7 +53,7 @@ Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => {
authToken = val?.authToken ?? null;
supportAuthToken = val?.supportAuthToken ?? null;
authTokenType = val?.authTokenType ?? null;
currentUserEmail = val?.email ?? null;
checkRequiredData();
},
Expand Down Expand Up @@ -99,12 +101,8 @@ function isSupportRequest(command: string): boolean {
return [READ_COMMANDS.OPEN_APP, SIDE_EFFECT_REQUEST_COMMANDS.RECONNECT_APP, SIDE_EFFECT_REQUEST_COMMANDS.OPEN_REPORT].some((cmd) => cmd === command);
}

function getSupportAuthToken(): string | null {
return supportAuthToken;
}

function setSupportAuthToken(newSupportAuthToken: string) {
supportAuthToken = newSupportAuthToken;
function isSupportAuthToken(): boolean {
return authTokenType === CONST.AUTH_TOKEN_TYPES.SUPPORT;
}

function setAuthToken(newAuthToken: string | null) {
Expand Down Expand Up @@ -139,7 +137,6 @@ export {
setIsAuthenticating,
getCredentials,
checkRequiredData,
getSupportAuthToken,
setSupportAuthToken,
isSupportAuthToken,
isSupportRequest,
};
8 changes: 2 additions & 6 deletions src/libs/Network/enhanceParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ function isAuthTokenRequired(command: string): boolean {
export default function enhanceParameters(command: string, parameters: Record<string, unknown>): Record<string, unknown> {
const finalParameters = {...parameters};

if (isAuthTokenRequired(command)) {
if (NetworkStore.getSupportAuthToken() && NetworkStore.isSupportRequest(command)) {
finalParameters.authToken = NetworkStore.getSupportAuthToken();
} else if (!parameters.authToken) {
finalParameters.authToken = NetworkStore.getAuthToken();
}
if (isAuthTokenRequired(command) && ((NetworkStore.isSupportAuthToken() && NetworkStore.isSupportRequest(command)) || !parameters.authToken)) {
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
finalParameters.authToken = NetworkStore.getAuthToken();
}

finalParameters.referer = CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ Onyx.connect({

currentUserEmail = value.email;
currentUserAccountID = value.accountID;
isAnonymousUser = value.authTokenType === 'anonymousAccount';
isAnonymousUser = value.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS;
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/libs/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function makeXHR(request: Request): Promise<Response | void> {
return NetworkStore.hasReadRequiredDataFromStorage().then((): Promise<Response | void> => {
// If we're using the Supportal token and this is not a Supportal request
// let's just return a promise that will resolve itself.
if (NetworkStore.getSupportAuthToken() && !NetworkStore.isSupportRequest(request.command)) {
if (NetworkStore.isSupportAuthToken() && !NetworkStore.isSupportRequest(request.command)) {
return new Promise<void>((resolve) => resolve());
}

Expand Down
168 changes: 100 additions & 68 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
RequestUnlinkValidationLinkParams,
SignInUserWithLinkParams,
SignInWithShortLivedAuthTokenParams,
SignInWithSupportAuthTokenParams,
UnlinkLoginParams,
ValidateTwoFactorAuthParams,
} from '@libs/API/parameters';
Expand Down Expand Up @@ -52,7 +53,7 @@ import type Credentials from '@src/types/onyx/Credentials';
import type {AutoAuthState} from '@src/types/onyx/Session';
import clearCache from './clearCache';

let sessionAuthTokenType: string | null = '';
let sessionAuthTokenType: ValueOf<typeof CONST.AUTH_TOKEN_TYPES> | null = null;
let sessionAuthToken: string | null = null;
let authPromiseResolver: ((value: boolean) => void) | null = null;

Expand Down Expand Up @@ -81,22 +82,108 @@ Onyx.connect({
callback: (val) => (preferredLocale = val),
});

function isSupportalToken(): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like it's effectively the same as NetworkStore.isSupportAuthToken. Can we DRY this up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, there was a reason why this was added in both places when we first implemented this. I think it was something related to cyclical imports and that the middleware couldn't use the place where we kept isSupportAuthToken before. But it's been a while since the first version, so I don't remember why anymore, and looks like I can use the Session. isSupportAuthToken everywhere.

Copy link
Contributor Author

@danieldoglas danieldoglas Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it actually fails to execute if I try to use Session.isSupportAuthToken here.

return sessionAuthTokenType === CONST.AUTH_TOKEN_TYPES.SUPPORT;
}

/**
* Sets the SupportToken. This method will only be used on dev.
*/
function setSupportAuthToken(supportAuthToken: string, email?: string, accountID?: number) {
danieldoglas marked this conversation as resolved.
Show resolved Hide resolved
if (supportAuthToken) {
Onyx.merge(ONYXKEYS.SESSION, {
authTokenType: CONST.AUTH_TOKEN_TYPES.SUPPORT,
authToken: supportAuthToken,
email,
accountID,
}).then(() => {
Log.info('[Supportal] Authtoken set');
});
}
Onyx.set(ONYXKEYS.LAST_VISITED_PATH, '');
}

function clearSupportAuthToken() {
Onyx.set(ONYXKEYS.SESSION, null).then(() => {
Log.info('[Supportal] Authtoken removed');
});
Onyx.set(ONYXKEYS.LAST_VISITED_PATH, null);
}

function getShortLivedLoginParams() {
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.ACCOUNT,
value: {
...CONST.DEFAULT_ACCOUNT_DATA,
isLoading: true,
},
},
// We are making a temporary modification to 'signedInWithShortLivedAuthToken' to ensure that 'App.openApp' will be called at least once
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.SESSION,
value: {
signedInWithShortLivedAuthToken: true,
},
},
];

// 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
danieldoglas marked this conversation as resolved.
Show resolved Hide resolved
const finallyData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.ACCOUNT,
value: {
isLoading: false,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.SESSION,
value: {
signedInWithShortLivedAuthToken: null,
},
},
];

return {optimisticData, finallyData};
}

/**
* This method should be used when we are being redirected from oldDot to NewDot on a supportal request
*/
function signInWithSupportAuthToken(authToken: string) {
const {optimisticData, finallyData} = getShortLivedLoginParams();
const params: SignInWithSupportAuthTokenParams = {authToken};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the explicit typing needed here? Or can you just pass {authToken} to API.read directly?

Copy link
Contributor Author

@danieldoglas danieldoglas Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's needed, but I thought that would be the good practices we would follow starting now, which is why I created the type file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it's not needed. API.read and API.write are smart. They look at the API command passed in and reference the central map of API param type definitions to find the param types for that API.

You can verify this by noodling with it a bit:

image image image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were a few reasons I advocated for us to set it up this way, but one of the reasons for creating a central map of API params would be to make it easier to one day set up compile-time checks that verify API param correctness across layers.

API.read(READ_COMMANDS.SIGN_IN_WITH_SUPPORT_AUTH_TOKEN, params, {optimisticData, finallyData});
}

/**
* Clears the Onyx store and redirects user to the sign in page
*/
function signOut() {
Log.info('Flushing logs before signing out', true, {}, true);

const params: LogOutParams = {
// Send current authToken because we will immediately clear it once triggering this command
authToken: NetworkStore.getAuthToken(),
partnerUserID: credentials?.autoGeneratedLogin ?? '',
partnerName: CONFIG.EXPENSIFY.PARTNER_NAME,
partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD,
shouldRetry: false,
};
// In case this is a supportal token, we won't have infinite sessions setup since the token will be
// short lived. So we can just remove the token and we can just skip calling logout.
if (isSupportalToken()) {
clearSupportAuthToken();
} else {
const params: LogOutParams = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, you should just inline the params and rely on type inference

// Send current authToken because we will immediately clear it once triggering this command
authToken: NetworkStore.getAuthToken(),
partnerUserID: credentials?.autoGeneratedLogin ?? '',
partnerName: CONFIG.EXPENSIFY.PARTNER_NAME,
partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD,
shouldRetry: false,
};

API.write(WRITE_COMMANDS.LOG_OUT, params);
}

API.write(WRITE_COMMANDS.LOG_OUT, params);
clearCache().then(() => {
Log.info('Cleared all cache data', true, {}, true);
});
Expand Down Expand Up @@ -314,46 +401,7 @@ function beginGoogleSignIn(token: string | null) {
* re-authenticating after an authToken expires.
*/
function signInWithShortLivedAuthToken(email: string, authToken: string) {
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.ACCOUNT,
value: {
...CONST.DEFAULT_ACCOUNT_DATA,
isLoading: true,
},
},
// 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.SESSION,
value: {
signedInWithShortLivedAuthToken: true,
},
},
];

// 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;
const {optimisticData, finallyData} = getShortLivedLoginParams();

// 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.
Expand All @@ -362,7 +410,7 @@ function signInWithShortLivedAuthToken(email: string, authToken: string) {

const params: SignInWithShortLivedAuthTokenParams = {authToken, oldPartnerUserID, skipReauthentication: true};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here


API.read(READ_COMMANDS.SIGN_IN_WITH_SHORT_LIVED_AUTH_TOKEN, params, {optimisticData, successData, failureData});
API.read(READ_COMMANDS.SIGN_IN_WITH_SHORT_LIVED_AUTH_TOKEN, params, {optimisticData, finallyData});
}

/**
Expand Down Expand Up @@ -530,23 +578,6 @@ function invalidateAuthToken() {
Onyx.merge(ONYXKEYS.SESSION, {authToken: 'pizza'});
}

/**
* Sets the SupportToken
*/
function setSupportAuthToken(supportAuthToken: string, email: string, accountID: number) {
if (supportAuthToken) {
Onyx.merge(ONYXKEYS.SESSION, {
authToken: '1',
supportAuthToken,
email,
accountID,
});
} else {
Onyx.set(ONYXKEYS.SESSION, {});
}
NetworkStore.setSupportAuthToken(supportAuthToken);
}

/**
* Clear the credentials and partial sign in session so the user can taken back to first Login step
*/
Expand Down Expand Up @@ -929,4 +960,5 @@ export {
validateTwoFactorAuth,
waitForUserSignIn,
canAccessRouteByAnonymousUser,
signInWithSupportAuthToken,
};
Loading
Loading