Send beta user state with AppView requests (#11474)

This commit is contained in:
DS Boyce
2026-08-18 09:50:15 -07:00
committed by GitHub
parent 45aa1a67b0
commit cc3622b583
7 changed files with 159 additions and 22 deletions
+28 -1
View File
@@ -7,8 +7,33 @@ import {
PUBLIC_BSKY_SERVICE,
} from '#/lib/constants'
import {createLexClient} from '#/lib/lexClient'
import {getCachedIsBetaUser} from '#/state/preferences/beta-user-cache'
import {networkAwareFetch} from './network'
const IS_BETA_USER_HEADER = 'X-Bsky-Is-Beta-User'
/**
* Add account-scoped headers to appview requests.
*
* Values are read from memory per request so preference changes are reflected
* immediately without rebuilding the session bundle.
*/
function withAppviewRequestHeaders(agent: Agent): Agent {
return {
get did() {
return agent.did
},
fetchHandler(path, init) {
const headers = new Headers(init?.headers)
const isBetaUser = agent.did ? getCachedIsBetaUser(agent.did) : undefined
if (isBetaUser !== undefined) {
headers.set(IS_BETA_USER_HEADER, String(isBetaUser))
}
return agent.fetchHandler(path, {...init, headers})
},
}
}
/**
* Build the signed-in appview {@link Client}.
*
@@ -28,7 +53,9 @@ import {networkAwareFetch} from './network'
* fetch, which is `networkAwareFetch` wrapped in the disposal kill switch.
*/
export function buildAppviewClient(agent: Agent): Client {
return createLexClient(agent, {service: BLUESKY_PROXY_HEADER.get()})
return createLexClient(withAppviewRequestHeaders(agent), {
service: BLUESKY_PROXY_HEADER.get(),
})
}
/**