Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

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

Persist PDS URL for session resumption (#3620)

* fix: store PDS URL for session resumption

* fix: handle a few more cases

* fix: blocking resumption should also use pds url

* refactor: do it in the construct itself

* fix: revert ce96223

authored by

Mary and committed by
GitHub
15055cb8 05212ca9

+21 -4
+1
src/state/persisted/schema.ts
··· 15 15 refreshJwt: z.string().optional(), // optional because it can expire 16 16 accessJwt: z.string().optional(), // optional because it can expire 17 17 deactivated: z.boolean().optional(), 18 + pdsUrl: z.string().optional(), 18 19 }) 19 20 export type PersistedAccount = z.infer<typeof accountSchema> 20 21
+20 -4
src/state/session/index.tsx
··· 117 117 }) 118 118 119 119 function createPersistSessionHandler( 120 + agent: BskyAgent, 120 121 account: SessionAccount, 121 122 persistSessionCallback: (props: { 122 123 expired: boolean ··· 144 145 email: session?.email || account.email, 145 146 emailConfirmed: session?.emailConfirmed || account.emailConfirmed, 146 147 deactivated: isSessionDeactivated(session?.accessJwt), 148 + pdsUrl: agent.pdsUrl?.toString(), 147 149 148 150 /* 149 151 * Tokens are undefined if the session expires, or if creation fails for ··· 276 278 refreshJwt: agent.session.refreshJwt, 277 279 accessJwt: agent.session.accessJwt, 278 280 deactivated, 281 + pdsUrl: agent.pdsUrl?.toString(), 279 282 } 280 283 281 284 await configureModeration(agent, account) 282 285 283 286 agent.setPersistSessionHandler( 284 287 createPersistSessionHandler( 288 + agent, 285 289 account, 286 290 ({expired, refreshedAccount}) => { 287 291 upsertAccount(refreshedAccount, expired) ··· 327 331 refreshJwt: agent.session.refreshJwt, 328 332 accessJwt: agent.session.accessJwt, 329 333 deactivated: isSessionDeactivated(agent.session.accessJwt), 334 + pdsUrl: agent.pdsUrl?.toString(), 330 335 } 331 336 332 337 await configureModeration(agent, account) 333 338 334 339 agent.setPersistSessionHandler( 335 340 createPersistSessionHandler( 341 + agent, 336 342 account, 337 343 ({expired, refreshedAccount}) => { 338 344 upsertAccount(refreshedAccount, expired) ··· 379 385 logger.debug(`session: initSession`, {}, logger.DebugContext.session) 380 386 const fetchingGates = tryFetchGates(account.did, 'prefer-low-latency') 381 387 382 - const agent = new BskyAgent({ 383 - service: account.service, 384 - persistSession: createPersistSessionHandler( 388 + const agent = new BskyAgent({service: account.service}) 389 + 390 + // restore the correct PDS URL if available 391 + if (account.pdsUrl) { 392 + agent.pdsUrl = agent.api.xrpc.uri = new URL(account.pdsUrl) 393 + } 394 + 395 + agent.setPersistSessionHandler( 396 + createPersistSessionHandler( 397 + agent, 385 398 account, 386 399 ({expired, refreshedAccount}) => { 387 400 upsertAccount(refreshedAccount, expired) 388 401 }, 389 402 {networkErrorCallback: clearCurrentAccount}, 390 403 ), 391 - }) 404 + ) 405 + 392 406 // @ts-ignore 393 407 if (IS_DEV && isWeb) window.agent = agent 394 408 await configureModeration(agent, account) ··· 421 435 logger.debug(`session: attempting to reuse previous session`) 422 436 423 437 agent.session = prevSession 438 + 424 439 __globalAgent = agent 425 440 await fetchingGates 426 441 upsertAccount(account) ··· 498 513 refreshJwt: agent.session.refreshJwt, 499 514 accessJwt: agent.session.accessJwt, 500 515 deactivated: isSessionDeactivated(agent.session.accessJwt), 516 + pdsUrl: agent.pdsUrl?.toString(), 501 517 } 502 518 } 503 519 },