-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[Part 1] Remove Onyx.connect(ONYXKEYS.SESSION) in /Session/index.ts: thread sesion through isSupportAuthToken #96368
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
d2c751e
4b55783
297fd3d
e275d10
93959fa
fc0285b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,7 +83,7 @@ import updateSessionAuthTokens from './updateSessionAuthTokens'; | |
|
|
||
| const INVALID_TOKEN = 'pizza'; | ||
|
|
||
| let session: Session = {}; | ||
| let deprecatedSession: Session = {}; | ||
| let authPromiseResolver: ((value: boolean) => void) | null = null; | ||
|
|
||
| let isHybridAppSetupFinished = false; | ||
|
|
@@ -92,25 +92,32 @@ let hasSwitchedAccountInHybridMode = false; | |
| Onyx.connect({ | ||
| key: ONYXKEYS.SESSION, | ||
| callback: (value) => { | ||
| session = value ?? {}; | ||
| deprecatedSession = value ?? {}; | ||
|
|
||
| if (!session.creationDate) { | ||
| session.creationDate = new Date().getTime(); | ||
| if (!deprecatedSession.creationDate) { | ||
| deprecatedSession.creationDate = new Date().getTime(); | ||
| } | ||
| if (session.authToken && authPromiseResolver) { | ||
| if (deprecatedSession.authToken && authPromiseResolver) { | ||
| authPromiseResolver(true); | ||
| authPromiseResolver = null; | ||
| } | ||
| if (CONFIG.IS_HYBRID_APP && isHybridAppSetupFinished && session.authToken && !isAnonymousUser(value)) { | ||
| HybridAppModule.sendAuthToken({authToken: session.authToken}); | ||
| if (CONFIG.IS_HYBRID_APP && isHybridAppSetupFinished && deprecatedSession.authToken && !isAnonymousUser(value)) { | ||
| HybridAppModule.sendAuthToken({authToken: deprecatedSession.authToken}); | ||
| } | ||
| }, | ||
| }); | ||
|
|
||
| let fullstorySession: Session = {}; | ||
| // Use connectWithoutView because it is only for fullstory initialization | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd really love for all the full story stuff to exist in its own module. That will also help isolate the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MelvinBot, give me plan to do it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Onyx.connectWithoutView({ | ||
| key: ONYXKEYS.SESSION, | ||
| callback: (value) => (fullstorySession = value ?? {}), | ||
| }); | ||
|
|
||
| // Use connectWithoutView because it is only for fullstory initialization | ||
| Onyx.connectWithoutView({ | ||
| key: ONYXKEYS.USER_METADATA, | ||
| callback: Fullstory.consentAndIdentify, | ||
| callback: (value) => Fullstory.consentAndIdentify(value, fullstorySession), | ||
| }); | ||
|
|
||
| let stashedSession: Session = {}; | ||
|
|
@@ -139,12 +146,12 @@ Onyx.connectWithoutView({ | |
| }, | ||
| }); | ||
|
|
||
| function isSupportAuthToken(): boolean { | ||
| return session.authTokenType === CONST.AUTH_TOKEN_TYPES.SUPPORT; | ||
| function isSupportAuthToken(session: OnyxEntry<Session> = deprecatedSession): boolean { | ||
| return session?.authTokenType === CONST.AUTH_TOKEN_TYPES.SUPPORT; | ||
| } | ||
|
|
||
| function isSupportalSession(): boolean { | ||
| return isSupportAuthToken() || !!session?.isSupportAuthTokenUsed; | ||
| return isSupportAuthToken() || !!deprecatedSession?.isSupportAuthTokenUsed; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -305,7 +312,7 @@ function callSAMLSignOut(params: LogOutParams, authToken: string): Promise<void | |
| * Checks if the account is an anonymous account. | ||
| */ | ||
| function isAnonymousUser(sessionParam?: OnyxEntry<Session>): boolean { | ||
| return (sessionParam?.authTokenType ?? session.authTokenType) === CONST.AUTH_TOKEN_TYPES.ANONYMOUS; | ||
| return (sessionParam?.authTokenType ?? deprecatedSession.authTokenType) === CONST.AUTH_TOKEN_TYPES.ANONYMOUS; | ||
| } | ||
|
|
||
| function hasStashedSession(stashedSessionParam: Session | undefined, stashedCredentialsParam: Credentials | undefined): boolean { | ||
|
|
@@ -316,7 +323,7 @@ function hasStashedSession(stashedSessionParam: Session | undefined, stashedCred | |
| * Checks if the user has authToken | ||
| */ | ||
| function hasAuthToken(): boolean { | ||
| return !!session.authToken; | ||
| return !!deprecatedSession.authToken; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -378,7 +385,7 @@ function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSess | |
| // session. | ||
| const signOutPromise: Promise<void | Response<never>> = | ||
| !shouldRestoreStashedSession && !shouldStashSession | ||
| ? signOut({autoGeneratedLogin: credentials?.autoGeneratedLogin, signedInWithSAML: !!session.signedInWithSAML, authToken: session.authToken}) | ||
| ? signOut({autoGeneratedLogin: credentials?.autoGeneratedLogin, signedInWithSAML: !!deprecatedSession.signedInWithSAML, authToken: deprecatedSession.authToken}) | ||
| : Promise.resolve(); | ||
|
|
||
| // The function redirectToSignIn will clear the whole storage, so let's create our onyx params | ||
|
|
@@ -391,7 +398,7 @@ function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSess | |
| if (!isSupportal && shouldStashSession) { | ||
| onyxSetParams = { | ||
| [ONYXKEYS.STASHED_CREDENTIALS]: credentials, | ||
| [ONYXKEYS.STASHED_SESSION]: session, | ||
| [ONYXKEYS.STASHED_SESSION]: deprecatedSession, | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -413,7 +420,7 @@ function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSess | |
| newDotCurrentAccountEmail: stashedSession.email ?? '', | ||
| authToken: stashedSession.authToken ?? '', | ||
| policyID: '', | ||
| accountID: session.accountID ? String(session.accountID) : '', | ||
| accountID: deprecatedSession.accountID ? String(deprecatedSession.accountID) : '', | ||
| }); | ||
| hasSwitchedAccountInHybridMode = true; | ||
| } | ||
|
|
@@ -620,8 +627,8 @@ function beginSignIn(email: string) { | |
| */ | ||
| function buildOnyxDataToCleanUpAnonymousUser(): OnyxUpdate<typeof ONYXKEYS.PERSONAL_DETAILS_LIST> { | ||
| const data: Record<string, null> = {}; | ||
| if (session.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS && session.accountID) { | ||
| data[session.accountID] = null; | ||
| if (deprecatedSession.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS && deprecatedSession.accountID) { | ||
| data[deprecatedSession.accountID] = null; | ||
| } | ||
| return { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
|
|
@@ -719,7 +726,7 @@ function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: HybridAppSettin | |
| const stashedData = hybridApp?.delegateAccessData?.isDelegateAccess | ||
| ? { | ||
| [ONYXKEYS.STASHED_CREDENTIALS]: credentials, | ||
| [ONYXKEYS.STASHED_SESSION]: session, | ||
| [ONYXKEYS.STASHED_SESSION]: deprecatedSession, | ||
| } | ||
| : { | ||
| [ONYXKEYS.STASHED_CREDENTIALS]: {}, | ||
|
|
@@ -1446,7 +1453,7 @@ function clearTwoFactorAuthSecretKey() { | |
| */ | ||
| function waitForUserSignIn(): Promise<boolean> { | ||
| return new Promise<boolean>((resolve) => { | ||
| if (session.authToken) { | ||
| if (deprecatedSession.authToken) { | ||
| resolve(true); | ||
| } else { | ||
| authPromiseResolver = resolve; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.