mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Strip back

+25 -92
+25 -92
src/state/session/index.tsx
··· 12 12 import {logEvent, LogEvents} from '#/lib/statsig/statsig' 13 13 import {hasProp} from '#/lib/type-guards' 14 14 import {logger} from '#/logger' 15 - import {isWeb} from '#/platform/detection' 16 15 import * as persisted from '#/state/persisted' 17 16 import {PUBLIC_BSKY_AGENT} from '#/state/queries' 18 17 import {useLoggedOutViewControls} from '#/state/shell/logged-out' 19 18 import {useCloseAllActiveElements} from '#/state/util' 20 - import {IS_DEV} from '#/env' 21 19 import {emitSessionDropped} from '../events' 22 20 import {readLabelers} from './agent-config' 23 21 ··· 328 326 ) 329 327 330 328 __globalAgent = agent 331 - // @ts-ignore 332 - if (IS_DEV && isWeb) window.agent = agent 333 329 upsertAccount(account) 334 330 335 331 logger.debug(`session: logged in`, {}, logger.DebugContext.session) ··· 367 363 service: account.service, 368 364 persistSession: createPersistSessionHandler( 369 365 account, 370 - ({expired, refreshedAccount}) => { 366 + async ({expired, refreshedAccount}) => { 367 + __globalAgent = agent 368 + await configureModeration(agent, account) 371 369 upsertAccount(refreshedAccount, expired) 372 370 }, 373 371 {networkErrorCallback: clearCurrentAccount}, 374 372 ), 375 373 }) 376 - // @ts-ignore 377 - if (IS_DEV && isWeb) window.agent = agent 378 - await configureModeration(agent, account) 374 + 375 + const prevSession = { 376 + accessJwt: account.accessJwt || '', 377 + refreshJwt: account.refreshJwt || '', 378 + did: account.did, 379 + handle: account.handle, 380 + deactivated: 381 + isSessionDeactivated(account.accessJwt) || account.deactivated, 382 + } 379 383 380 384 let canReusePrevSession = false 381 385 try { ··· 392 396 logger.error(`session: could not decode jwt`) 393 397 } 394 398 395 - const prevSession = { 396 - accessJwt: account.accessJwt || '', 397 - refreshJwt: account.refreshJwt || '', 398 - did: account.did, 399 - handle: account.handle, 400 - deactivated: 401 - isSessionDeactivated(account.accessJwt) || account.deactivated, 402 - } 403 - 404 399 if (canReusePrevSession) { 405 - logger.debug(`session: attempting to reuse previous session`) 406 - 400 + logger.debug( 401 + `session: attempting to reuse previous session`, 402 + {}, 403 + logger.DebugContext.session, 404 + ) 407 405 agent.session = prevSession 408 406 __globalAgent = agent 407 + await configureModeration(agent, account) 409 408 upsertAccount(account) 410 - 411 - if (prevSession.deactivated) { 412 - // don't attempt to resume 413 - // use will be taken to the deactivated screen 414 - logger.debug(`session: reusing session for deactivated account`) 415 - return 416 - } 417 - 418 - // Intentionally not awaited to unblock the UI: 419 - resumeSessionWithFreshAccount() 420 - .then(freshAccount => { 421 - if (JSON.stringify(account) !== JSON.stringify(freshAccount)) { 422 - logger.info( 423 - `session: reuse of previous session returned a fresh account, upserting`, 424 - ) 425 - upsertAccount(freshAccount) 426 - } 427 - }) 428 - .catch(e => { 429 - /* 430 - * Note: `agent.persistSession` is also called when this fails, and 431 - * we handle that failure via `createPersistSessionHandler` 432 - */ 433 - logger.info(`session: resumeSessionWithFreshAccount failed`, { 434 - message: e, 435 - }) 436 - 437 - __globalAgent = PUBLIC_BSKY_AGENT 438 - }) 439 409 } else { 440 - logger.debug(`session: attempting to resume using previous session`) 441 - 442 - try { 443 - const freshAccount = await resumeSessionWithFreshAccount() 444 - __globalAgent = agent 445 - upsertAccount(freshAccount) 446 - } catch (e) { 447 - /* 448 - * Note: `agent.persistSession` is also called when this fails, and 449 - * we handle that failure via `createPersistSessionHandler` 450 - */ 451 - logger.info(`session: resumeSessionWithFreshAccount failed`, { 452 - message: e, 453 - }) 454 - 455 - __globalAgent = PUBLIC_BSKY_AGENT 456 - } 457 - } 458 - 459 - async function resumeSessionWithFreshAccount(): Promise<SessionAccount> { 460 - logger.debug(`session: resumeSessionWithFreshAccount`) 461 - 410 + logger.debug( 411 + `session: attempting to resume using previous session`, 412 + {}, 413 + logger.DebugContext.session, 414 + ) 462 415 await networkRetry(1, () => agent.resumeSession(prevSession)) 463 - 464 - /* 465 - * If `agent.resumeSession` fails above, it'll throw. This is just to 466 - * make TypeScript happy. 467 - */ 468 - if (!agent.session) { 469 - throw new Error(`session: initSession failed to establish a session`) 470 - } 471 - 472 - // ensure changes in handle/email etc are captured on reload 473 - return { 474 - service: agent.service.toString(), 475 - did: agent.session.did, 476 - handle: agent.session.handle, 477 - email: agent.session.email, 478 - emailConfirmed: agent.session.emailConfirmed || false, 479 - refreshJwt: agent.session.refreshJwt, 480 - accessJwt: agent.session.accessJwt, 481 - deactivated: isSessionDeactivated(agent.session.accessJwt), 482 - } 483 416 } 484 417 }, 485 418 [upsertAccount, clearCurrentAccount], ··· 576 509 }, [state]) 577 510 578 511 React.useEffect(() => { 579 - return persisted.onUpdate(() => { 512 + return persisted.onUpdate(async () => { 580 513 const session = persisted.get('session') 581 514 582 515 logger.debug(`session: persisted onUpdate`, {}) ··· 594 527 }, 595 528 }) 596 529 597 - initSession(session.currentAccount) 530 + await initSession(session.currentAccount) 598 531 } else { 599 532 logger.debug(`session: persisted onUpdate, updating session`, {}) 600 533