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 73 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
9 changes: 5 additions & 4 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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 Expand Up @@ -3341,10 +3346,6 @@ const CONST = {
SESSION_STORAGE_KEYS: {
INITIAL_URL: 'INITIAL_URL',
},

AUTH_TOKEN_TYPE: {
ANONYMOUS: 'anonymousAccount',
},
} as const;

type Country = keyof typeof CONST.ALL_COUNTRIES;
Expand Down
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const ONYXKEYS = {

/** Credentials to authenticate the user */
CREDENTIALS: 'credentials',
STASHED_CREDENTIALS: 'stashedCredentials',

// Contains loading data for the IOU feature (MoneyRequestModal, IOUDetail, & MoneyRequestPreview Components)
IOU: 'iou',
Expand Down Expand Up @@ -102,6 +103,7 @@ const ONYXKEYS = {

/** Information about the current session (authToken, accountID, email, loading, error) */
SESSION: 'session',
STASHED_SESSION: 'stashedSession',
BETAS: 'betas',

/** NVP keys
Expand Down Expand Up @@ -491,6 +493,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.PERSISTED_REQUESTS]: OnyxTypes.Request[];
[ONYXKEYS.CURRENT_DATE]: string;
[ONYXKEYS.CREDENTIALS]: OnyxTypes.Credentials;
[ONYXKEYS.STASHED_CREDENTIALS]: OnyxTypes.Credentials;
[ONYXKEYS.IOU]: OnyxTypes.IOU;
[ONYXKEYS.MODAL]: OnyxTypes.Modal;
[ONYXKEYS.NETWORK]: OnyxTypes.Network;
Expand All @@ -509,6 +512,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.USER_LOCATION]: OnyxTypes.UserLocation;
[ONYXKEYS.LOGIN_LIST]: OnyxTypes.LoginList;
[ONYXKEYS.SESSION]: OnyxTypes.Session;
[ONYXKEYS.STASHED_SESSION]: OnyxTypes.Session;
[ONYXKEYS.BETAS]: OnyxTypes.Beta[];
[ONYXKEYS.NVP_PRIORITY_MODE]: ValueOf<typeof CONST.PRIORITY_MODE>;
[ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE]: OnyxTypes.BlockedFromConcierge;
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ export default {
},
security: 'Security',
signOut: 'Sign out',
restoreStashed: 'Restore stashed login',
signOutConfirmationText: "You'll lose any offline changes if you sign-out.",
versionLetter: 'v',
readTheTermsAndPrivacy: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ export default {
logSizeTooLarge: ({size}: LogSizeParams) => `El tamaño del registro excede el límite de ${size} MB. Utilice "Guardar registro" para descargar el archivo de registro.`,
},
security: 'Seguridad',
restoreStashed: 'Restablecer login guardado',
signOut: 'Desconectar',
signOutConfirmationText: 'Si cierras sesión perderás los cambios hechos mientras estabas desconectado',
versionLetter: 'v',
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 @@ -51,6 +51,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 @@ -336,6 +336,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 @@ -369,6 +370,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
3 changes: 2 additions & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ function AuthScreens({session, lastOpenedPublicRoomID, isUsingMemoryOnlyKeys = f
const shouldGetAllData = !!isUsingMemoryOnlyKeys || SessionUtils.didUserLogInDuringSession();
// Sign out the current user if we're transitioning with a different user
const isTransitioning = currentUrl.includes(ROUTES.TRANSITION_BETWEEN_APPS);
const isSupportalTransition = currentUrl.includes('authTokenType=support');
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
if (isLoggingInAsNewUser && isTransitioning) {
Session.signOutAndRedirectToSignIn();
Session.signOutAndRedirectToSignIn(false, isSupportalTransition);
Comment on lines +172 to +174
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it was strange we had to add this here, but while testing, around 30% of the times we called signOutAndRedirectToSignIn from here instead of LogoutPreviousUserPage

return;
}

Expand Down
23 changes: 9 additions & 14 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,21 +515,27 @@ 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;
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
authTokenType?: ValueOf<typeof CONST.AUTH_TOKEN_TYPES>;
exitTo?: Routes | HybridAppRoute;
shouldForceLogin: string;
domain?: Routes;
};
[SCREENS.VALIDATE_LOGIN]: {
accountID: string;
validateCode: string;
exitTo?: Routes | HybridAppRoute;
};
};

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

type AuthScreensParamList = {
[NAVIGATORS.BOTTOM_TAB_NAVIGATOR]: NavigatorScreenParams<BottomTabNavigatorParamList>;
type AuthScreensParamList = SharedScreensParamList & {
[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;
};
[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 {SIDE_EFFECT_REQUEST_COMMANDS, WRITE_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 [WRITE_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 @@ -439,7 +439,7 @@ Onyx.connect({

currentUserEmail = value.email;
currentUserAccountID = value.accountID;
isAnonymousUser = value.authTokenType === CONST.AUTH_TOKEN_TYPE.ANONYMOUS;
isAnonymousUser = value.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS;
currentUserPrivateDomain = isEmailPublicDomain(currentUserEmail ?? '') ? '' : Str.extractEmailDomain(currentUserEmail ?? '');
},
});
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
Loading
Loading