From 69cf6f93b829d1d25e5fa37875d90070f68ef2ed Mon Sep 17 00:00:00 2001 From: mary.my.id Date: Fri, 16 Jan 2026 02:09:57 +0000 Subject: [PATCH] fix: ensure `com.atproto.*` calls go through without proxying `atproto-proxy` behavior seems ambiguous right now, it's not really clear whether PDS implementors should interpret atproto-proxy *before* or *after* PDS' own route handlers. This PR ensures that `com.atproto.*` calls go through without a proxy set (with some exception) --- src/ageAssurance/data.tsx | 3 ++- src/ageAssurance/useBeginAgeAssurance.ts | 3 ++- src/components/dialogs/EmailDialog/data/useConfirmEmail.ts | 3 ++- src/components/dialogs/EmailDialog/data/useManageEmail2FA.ts | 3 ++- src/components/dialogs/EmailDialog/data/useRequestEmailUpdate.ts | 4 +++- src/components/dialogs/EmailDialog/data/useRequestEmailVerification.ts | 3 ++- src/components/dialogs/EmailDialog/data/useUpdateEmail.ts | 6 +++++- src/components/intents/VerifyEmailIntentDialog.tsx | 3 ++- src/components/live/queries.ts | 7 ++++--- src/lib/api/index.ts | 3 ++- src/lib/generate-starterpack.ts | 3 ++- src/lib/media/video/upload.shared.ts | 3 ++- src/screens/Deactivated.tsx | 3 ++- src/screens/Onboarding/util.ts | 3 ++- src/screens/Settings/components/ChangePasswordDialog.tsx | 5 +++-- src/screens/Settings/components/DeactivateAccountDialog.tsx | 3 ++- src/screens/Settings/components/DisableEmail2FADialog.tsx | 5 +++-- src/screens/Settings/components/ExportCarDialog.tsx | 3 ++- src/screens/SignupQueued.tsx | 3 ++- src/state/queries/app-passwords.ts | 7 ++++--- src/state/queries/list.ts | 5 +++-- src/state/queries/messages/actor-declaration.ts | 5 +++-- src/state/queries/postgate/index.ts | 3 ++- src/state/queries/preferences/index.ts | 5 +++-- src/state/queries/starter-packs.ts | 7 ++++--- src/state/queries/threadgate/index.ts | 3 ++- src/state/session/agent.ts | 13 ++++++++++++- src/state/session/index.tsx | 3 ++- src/view/com/modals/DeleteAccount.tsx | 5 +++-- 29 file(s) changed, 84 insertion(s)(+), 41 deletion(s)(-) diff --git a/src/ageAssurance/data.tsx b/src/ageAssurance/data.tsx --- a/src/ageAssurance/data.tsx +++ b/src/ageAssurance/data.tsx @@ -20,6 +20,7 @@ hasSnoozedBirthdateUpdateForDid, snoozeBirthdateUpdateAllowedForDid, } from '#/state/birthdate' import {useAgent, useSession} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import * as debug from '#/ageAssurance/debug' import {logger} from '#/ageAssurance/logger' import { @@ -323,7 +324,7 @@ }: { agent: AtpAgent }): Promise { if (debug.enabled) return debug.resolve(debug.otherRequiredData) - const [prefs] = await Promise.all([agent.getPreferences()]) + const [prefs] = await Promise.all([pdsAgent(agent).getPreferences()]) const data: OtherRequiredData = { birthdate: prefs.birthDate ? prefs.birthDate.toISOString() : undefined, } diff --git a/src/ageAssurance/useBeginAgeAssurance.ts b/src/ageAssurance/useBeginAgeAssurance.ts --- a/src/ageAssurance/useBeginAgeAssurance.ts +++ b/src/ageAssurance/useBeginAgeAssurance.ts @@ -10,6 +10,7 @@ PUBLIC_APPVIEW_DID, } from '#/lib/constants' import {isNetworkError} from '#/lib/hooks/useCleanError' import {useAgent} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import {usePatchAgeAssuranceServerState} from '#/ageAssurance' import {logger} from '#/ageAssurance/logger' import {BLUESKY_PROXY_DID} from '#/env' @@ -38,7 +39,7 @@ } const { data: {token}, - } = await agent.com.atproto.server.getServiceAuth({ + } = await pdsAgent(agent).com.atproto.server.getServiceAuth({ aud: BLUESKY_PROXY_DID, lxm: `app.bsky.ageassurance.begin`, }) diff --git a/src/components/dialogs/EmailDialog/data/useConfirmEmail.ts b/src/components/dialogs/EmailDialog/data/useConfirmEmail.ts --- a/src/components/dialogs/EmailDialog/data/useConfirmEmail.ts +++ b/src/components/dialogs/EmailDialog/data/useConfirmEmail.ts @@ -1,6 +1,7 @@ import {useMutation} from '@tanstack/react-query' import {useAgent, useSession} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' export function useConfirmEmail({ onSuccess, @@ -15,7 +16,7 @@ if (!currentAccount?.email) { throw new Error('No email found for the current account') } - await agent.com.atproto.server.confirmEmail({ + await pdsAgent(agent).com.atproto.server.confirmEmail({ email: currentAccount.email.trim(), token: token.trim(), }) diff --git a/src/components/dialogs/EmailDialog/data/useManageEmail2FA.ts b/src/components/dialogs/EmailDialog/data/useManageEmail2FA.ts --- a/src/components/dialogs/EmailDialog/data/useManageEmail2FA.ts +++ b/src/components/dialogs/EmailDialog/data/useManageEmail2FA.ts @@ -1,6 +1,7 @@ import {useMutation} from '@tanstack/react-query' import {useAgent, useSession} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' export function useManageEmail2FA() { const agent = useAgent() @@ -17,7 +18,7 @@ if (!currentAccount?.email) { throw new Error('No email found for the current account') } - await agent.com.atproto.server.updateEmail({ + await pdsAgent(agent).com.atproto.server.updateEmail({ email: currentAccount.email, emailAuthFactor: enabled, token, diff --git a/src/components/dialogs/EmailDialog/data/useRequestEmailUpdate.ts b/src/components/dialogs/EmailDialog/data/useRequestEmailUpdate.ts --- a/src/components/dialogs/EmailDialog/data/useRequestEmailUpdate.ts +++ b/src/components/dialogs/EmailDialog/data/useRequestEmailUpdate.ts @@ -1,13 +1,15 @@ import {useMutation} from '@tanstack/react-query' import {useAgent} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' export function useRequestEmailUpdate() { const agent = useAgent() return useMutation({ mutationFn: async () => { - return (await agent.com.atproto.server.requestEmailUpdate()).data + return (await pdsAgent(agent).com.atproto.server.requestEmailUpdate()) + .data }, }) } diff --git a/src/components/dialogs/EmailDialog/data/useRequestEmailVerification.ts b/src/components/dialogs/EmailDialog/data/useRequestEmailVerification.ts --- a/src/components/dialogs/EmailDialog/data/useRequestEmailVerification.ts +++ b/src/components/dialogs/EmailDialog/data/useRequestEmailVerification.ts @@ -1,13 +1,14 @@ import {useMutation} from '@tanstack/react-query' import {useAgent} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' export function useRequestEmailVerification() { const agent = useAgent() return useMutation({ mutationFn: async () => { - await agent.com.atproto.server.requestEmailConfirmation() + await pdsAgent(agent).com.atproto.server.requestEmailConfirmation() }, }) } diff --git a/src/components/dialogs/EmailDialog/data/useUpdateEmail.ts b/src/components/dialogs/EmailDialog/data/useUpdateEmail.ts --- a/src/components/dialogs/EmailDialog/data/useUpdateEmail.ts +++ b/src/components/dialogs/EmailDialog/data/useUpdateEmail.ts @@ -1,6 +1,7 @@ import {useMutation} from '@tanstack/react-query' import {useAgent} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import {useRequestEmailUpdate} from '#/components/dialogs/EmailDialog/data/useRequestEmailUpdate' async function updateEmailAndRefreshSession( @@ -8,7 +9,10 @@ agent: ReturnType, email: string, token?: string, ) { - await agent.com.atproto.server.updateEmail({email: email.trim(), token}) + await pdsAgent(agent).com.atproto.server.updateEmail({ + email: email.trim(), + token, + }) await agent.resumeSession(agent.session!) } diff --git a/src/components/intents/VerifyEmailIntentDialog.tsx b/src/components/intents/VerifyEmailIntentDialog.tsx --- a/src/components/intents/VerifyEmailIntentDialog.tsx +++ b/src/components/intents/VerifyEmailIntentDialog.tsx @@ -5,6 +5,7 @@ import {useLingui} from '@lingui/react' import {isNative} from '#/platform/detection' import {useAgent, useSession} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import {atoms as a, useBreakpoints, useTheme} from '#/alf' import {Button, ButtonIcon, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' @@ -51,7 +52,7 @@ }, [state?.code, confirmEmail]) const onPressResendEmail = async () => { setSending(true) - await agent.com.atproto.server.requestEmailConfirmation() + await pdsAgent(agent).com.atproto.server.requestEmailConfirmation() setSending(false) setStatus('resent') } diff --git a/src/components/live/queries.ts b/src/components/live/queries.ts --- a/src/components/live/queries.ts +++ b/src/components/live/queries.ts @@ -16,6 +16,7 @@ import {logger} from '#/logger' import {updateProfileShadow} from '#/state/cache/profile-shadow' import {useLiveNowConfig} from '#/state/service-config' import {useAgent, useSession} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import * as Toast from '#/view/com/util/Toast' import {useDialogContext} from '#/components/Dialog' @@ -108,11 +109,11 @@ const upsert = async () => { const repo = currentAccount.did const collection = 'app.bsky.actor.status' - const existing = await agent.com.atproto.repo - .getRecord({repo, collection, rkey: 'self'}) + const existing = await pdsAgent(agent) + .com.atproto.repo.getRecord({repo, collection, rkey: 'self'}) .catch(_e => undefined) - await agent.com.atproto.repo.putRecord({ + await pdsAgent(agent).com.atproto.repo.putRecord({ repo, collection, rkey: 'self', diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -34,6 +34,7 @@ import { createThreadgateRecord, threadgateAllowUISettingToAllowRecordValue, } from '#/state/queries/threadgate' +import {pdsAgent} from '#/state/session/agent' import { type EmbedDraft, type PostDraft, @@ -172,7 +173,7 @@ } } try { - await agent.com.atproto.repo.applyWrites({ + await pdsAgent(agent).com.atproto.repo.applyWrites({ repo: agent.assertDid, writes: writes, validate: true, diff --git a/src/lib/generate-starterpack.ts b/src/lib/generate-starterpack.ts --- a/src/lib/generate-starterpack.ts +++ b/src/lib/generate-starterpack.ts @@ -15,6 +15,7 @@ import {sanitizeDisplayName} from '#/lib/strings/display-names' import {sanitizeHandle} from '#/lib/strings/handles' import {enforceLen} from '#/lib/strings/helpers' import {useAgent} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import type * as bsky from '#/types/bsky' export const createStarterPackList = async ({ @@ -44,7 +45,7 @@ purpose: 'app.bsky.graph.defs#referencelist', }, ) if (!list) throw new Error('List creation failed') - await agent.com.atproto.repo.applyWrites({ + await pdsAgent(agent).com.atproto.repo.applyWrites({ repo: agent.session!.did, writes: profiles.map(p => createListItem({did: p.did, listUri: list.uri})), }) diff --git a/src/lib/media/video/upload.shared.ts b/src/lib/media/video/upload.shared.ts --- a/src/lib/media/video/upload.shared.ts +++ b/src/lib/media/video/upload.shared.ts @@ -3,6 +3,7 @@ import {type I18n} from '@lingui/core' import {msg} from '@lingui/macro' import {VIDEO_SERVICE_DID} from '#/lib/constants' +import {pdsAgent} from '#/state/session/agent' import {UploadLimitError} from '#/lib/media/video/errors' import {getServiceAuthAudFromUrl} from '#/lib/strings/url-helpers' import {createVideoAgent} from './util' @@ -22,7 +23,7 @@ const pdsAud = getServiceAuthAudFromUrl(agent.dispatchUrl) if (!pdsAud) { throw new Error('Agent does not have a PDS URL') } - const {data: serviceAuth} = await agent.com.atproto.server.getServiceAuth({ + const {data: serviceAuth} = await pdsAgent(agent).com.atproto.server.getServiceAuth({ aud: aud ?? pdsAud, lxm, exp, diff --git a/src/screens/Deactivated.tsx b/src/screens/Deactivated.tsx --- a/src/screens/Deactivated.tsx +++ b/src/screens/Deactivated.tsx @@ -14,6 +14,7 @@ useAgent, useSession, useSessionApi, } from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import {useLoggedOutViewControls} from '#/state/shell/logged-out' import {Logo} from '#/view/icons/Logo' import {atoms as a, useTheme} from '#/alf' @@ -69,7 +70,7 @@ const handleActivate = React.useCallback(async () => { try { setPending(true) - await agent.com.atproto.server.activateAccount() + await pdsAgent(agent).com.atproto.server.activateAccount() await queryClient.resetQueries() await agent.resumeSession(agent.session!) } catch (e: any) { diff --git a/src/screens/Onboarding/util.ts b/src/screens/Onboarding/util.ts --- a/src/screens/Onboarding/util.ts +++ b/src/screens/Onboarding/util.ts @@ -9,6 +9,7 @@ import {TID} from '@atproto/common-web' import chunk from 'lodash.chunk' import {until} from '#/lib/async/until' +import {pdsAgent} from '#/state/session/agent' export async function bulkWriteFollows(agent: BskyAgent, dids: string[]) { const session = agent.session @@ -35,7 +36,7 @@ })) const chunks = chunk(followWrites, 50) for (const chunk of chunks) { - await agent.com.atproto.repo.applyWrites({ + await pdsAgent(agent).com.atproto.repo.applyWrites({ repo: session.did, writes: chunk, }) diff --git a/src/screens/Settings/components/ChangePasswordDialog.tsx b/src/screens/Settings/components/ChangePasswordDialog.tsx --- a/src/screens/Settings/components/ChangePasswordDialog.tsx +++ b/src/screens/Settings/components/ChangePasswordDialog.tsx @@ -9,6 +9,7 @@ import {checkAndFormatResetCode} from '#/lib/strings/password' import {logger} from '#/logger' import {isNative} from '#/platform/detection' import {useAgent, useSession} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import {ErrorMessage} from '#/view/com/util/error/ErrorMessage' import {android, atoms as a, web} from '#/alf' import {Button, ButtonIcon, ButtonText} from '#/components/Button' @@ -84,7 +85,7 @@ setError('') setIsProcessing(true) try { - await agent.com.atproto.server.requestPasswordReset({ + await pdsAgent(agent).com.atproto.server.requestPasswordReset({ email: currentAccount.email, }) setStage(Stages.ChangePassword) @@ -128,7 +129,7 @@ setError('') setIsProcessing(true) try { - await agent.com.atproto.server.resetPassword({ + await pdsAgent(agent).com.atproto.server.resetPassword({ token: formattedCode, password: newPassword, }) diff --git a/src/screens/Settings/components/DeactivateAccountDialog.tsx b/src/screens/Settings/components/DeactivateAccountDialog.tsx --- a/src/screens/Settings/components/DeactivateAccountDialog.tsx +++ b/src/screens/Settings/components/DeactivateAccountDialog.tsx @@ -5,6 +5,7 @@ import {useLingui} from '@lingui/react' import {logger} from '#/logger' import {useAgent, useSessionApi} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import {atoms as a, useBreakpoints, useTheme} from '#/alf' import {Button, ButtonIcon, ButtonText} from '#/components/Button' import {type DialogOuterProps} from '#/components/Dialog' @@ -42,7 +43,7 @@ const handleDeactivate = React.useCallback(async () => { try { setPending(true) - await agent.com.atproto.server.deactivateAccount({}) + await pdsAgent(agent).com.atproto.server.deactivateAccount({}) control.close(() => { logoutCurrentAccount('Deactivated') }) diff --git a/src/screens/Settings/components/DisableEmail2FADialog.tsx b/src/screens/Settings/components/DisableEmail2FADialog.tsx --- a/src/screens/Settings/components/DisableEmail2FADialog.tsx +++ b/src/screens/Settings/components/DisableEmail2FADialog.tsx @@ -6,6 +6,7 @@ import {cleanError} from '#/lib/strings/errors' import {isNative} from '#/platform/detection' import {useAgent, useSession} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import {ErrorMessage} from '#/view/com/util/error/ErrorMessage' import * as Toast from '#/view/com/util/Toast' import {atoms as a, useBreakpoints, useTheme} from '#/alf' @@ -41,7 +42,7 @@ const onSendEmail = async () => { setError('') setIsProcessing(true) try { - await agent.com.atproto.server.requestEmailUpdate() + await pdsAgent(agent).com.atproto.server.requestEmailUpdate() setStage(Stages.ConfirmCode) } catch (e) { setError(cleanError(String(e))) @@ -55,7 +56,7 @@ setError('') setIsProcessing(true) try { if (currentAccount?.email) { - await agent.com.atproto.server.updateEmail({ + await pdsAgent(agent).com.atproto.server.updateEmail({ email: currentAccount!.email, token: confirmationCode.trim(), emailAuthFactor: false, diff --git a/src/screens/Settings/components/ExportCarDialog.tsx b/src/screens/Settings/components/ExportCarDialog.tsx --- a/src/screens/Settings/components/ExportCarDialog.tsx +++ b/src/screens/Settings/components/ExportCarDialog.tsx @@ -6,6 +6,7 @@ import {saveBytesToDisk} from '#/lib/media/manip' import {logger} from '#/logger' import {useAgent} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import {atoms as a, useTheme, web} from '#/alf' import {Button, ButtonIcon, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' @@ -32,7 +33,7 @@ } try { setLoading(true) const did = agent.session.did - const downloadRes = await agent.com.atproto.sync.getRepo({did}) + const downloadRes = await pdsAgent(agent).com.atproto.sync.getRepo({did}) const saveRes = await saveBytesToDisk( 'repo.car', downloadRes.data, diff --git a/src/screens/SignupQueued.tsx b/src/screens/SignupQueued.tsx --- a/src/screens/SignupQueued.tsx +++ b/src/screens/SignupQueued.tsx @@ -8,6 +8,7 @@ import {logger} from '#/logger' import {isIOS, isWeb} from '#/platform/detection' import {isSignupQueued, useAgent, useSessionApi} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import {useOnboardingDispatch} from '#/state/shell' import {Logo} from '#/view/icons/Logo' import {atoms as a, native, useBreakpoints, useTheme, web} from '#/alf' @@ -37,7 +38,7 @@ const checkStatus = React.useCallback(async () => { setProcessing(true) try { - const res = await agent.com.atproto.temp.checkSignupQueue() + const res = await pdsAgent(agent).com.atproto.temp.checkSignupQueue() if (res.data.activated) { // ready to go, exchange the access token for a usable one and kick off onboarding await agent.sessionManager.refreshSession() diff --git a/src/state/queries/app-passwords.ts b/src/state/queries/app-passwords.ts --- a/src/state/queries/app-passwords.ts +++ b/src/state/queries/app-passwords.ts @@ -3,6 +3,7 @@ import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query' import {STALE} from '#/state/queries' import {useAgent} from '../session' +import {pdsAgent} from '../session/agent' const RQKEY_ROOT = 'app-passwords' export const RQKEY = () => [RQKEY_ROOT] @@ -13,7 +14,7 @@ return useQuery({ staleTime: STALE.MINUTES.FIVE, queryKey: RQKEY(), queryFn: async () => { - const res = await agent.com.atproto.server.listAppPasswords({}) + const res = await pdsAgent(agent).com.atproto.server.listAppPasswords({}) return res.data.passwords }, }) @@ -29,7 +30,7 @@ {name: string; privileged: boolean} >({ mutationFn: async ({name, privileged}) => { return ( - await agent.com.atproto.server.createAppPassword({ + await pdsAgent(agent).com.atproto.server.createAppPassword({ name, privileged, }) @@ -48,7 +49,7 @@ const queryClient = useQueryClient() const agent = useAgent() return useMutation({ mutationFn: async ({name}) => { - await agent.com.atproto.server.revokeAppPassword({ + await pdsAgent(agent).com.atproto.server.revokeAppPassword({ name, }) }, diff --git a/src/state/queries/list.ts b/src/state/queries/list.ts --- a/src/state/queries/list.ts +++ b/src/state/queries/list.ts @@ -17,6 +17,7 @@ import {until} from '#/lib/async/until' import {type ImageMeta} from '#/state/gallery' import {STALE} from '#/state/queries' import {useAgent, useSession} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import {invalidate as invalidateMyLists} from './my-lists' import {RQKEY as PROFILE_LISTS_RQKEY} from './profile-lists' @@ -152,7 +153,7 @@ } else if (avatar === null) { record.avatar = undefined } const res = ( - await agent.com.atproto.repo.putRecord({ + await pdsAgent(agent).com.atproto.repo.putRecord({ repo: currentAccount.did, collection: 'app.bsky.graph.list', rkey, @@ -231,7 +232,7 @@ .concat([createDel(uri)]) // apply in chunks for (const writesChunk of chunk(writes, 10)) { - await agent.com.atproto.repo.applyWrites({ + await pdsAgent(agent).com.atproto.repo.applyWrites({ repo: currentAccount.did, writes: writesChunk, }) diff --git a/src/state/queries/messages/actor-declaration.ts b/src/state/queries/messages/actor-declaration.ts --- a/src/state/queries/messages/actor-declaration.ts +++ b/src/state/queries/messages/actor-declaration.ts @@ -3,6 +3,7 @@ import {useMutation, useQueryClient} from '@tanstack/react-query' import {logger} from '#/logger' import {useAgent, useSession} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import {RQKEY as PROFILE_RKEY} from '../profile' export function useUpdateActorDeclaration({ @@ -19,7 +20,7 @@ return useMutation({ mutationFn: async (allowIncoming: 'all' | 'none' | 'following') => { if (!currentAccount) throw new Error('Not signed in') - const result = await agent.com.atproto.repo.putRecord({ + const result = await pdsAgent(agent).com.atproto.repo.putRecord({ repo: currentAccount.did, collection: 'chat.bsky.actor.declaration', rkey: 'self', @@ -69,7 +70,7 @@ return useMutation({ mutationFn: async () => { if (!currentAccount) throw new Error('Not signed in') - const result = await agent.api.com.atproto.repo.deleteRecord({ + const result = await pdsAgent(agent).com.atproto.repo.deleteRecord({ repo: currentAccount.did, collection: 'chat.bsky.actor.declaration', rkey: 'self', diff --git a/src/state/queries/postgate/index.ts b/src/state/queries/postgate/index.ts --- a/src/state/queries/postgate/index.ts +++ b/src/state/queries/postgate/index.ts @@ -21,6 +21,7 @@ mergePostgateRecords, POSTGATE_COLLECTION, } from '#/state/queries/postgate/util' import {useAgent} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import * as bsky from '#/types/bsky' export async function getPostgateRecord({ @@ -96,7 +97,7 @@ }) { const postUrip = new AtUri(postUri) await networkRetry(2, () => - agent.api.com.atproto.repo.putRecord({ + pdsAgent(agent).com.atproto.repo.putRecord({ repo: agent.session!.did, collection: POSTGATE_COLLECTION, rkey: postUrip.rkey, diff --git a/src/state/queries/preferences/index.ts b/src/state/queries/preferences/index.ts --- a/src/state/queries/preferences/index.ts +++ b/src/state/queries/preferences/index.ts @@ -21,6 +21,7 @@ type ThreadViewPreferences, type UsePreferencesQueryResponse, } from '#/state/queries/preferences/types' import {useBlankPrefAuthedAgent as useAgent} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import {saveLabelers} from '#/state/session/agent-config' import {useAgeAssurance} from '#/ageAssurance' import {makeAgeRestrictedModerationPrefs} from '#/ageAssurance/util' @@ -45,7 +46,7 @@ queryFn: async () => { if (!agent.did) { return DEFAULT_LOGGED_OUT_PREFERENCES } else { - const res = await agent.getPreferences() + const res = await pdsAgent(agent).getPreferences() // save to local storage to ensure there are labels on initial requests saveLabelers( @@ -100,7 +101,7 @@ const agent = useAgent() return useMutation({ mutationFn: async () => { - await agent.app.bsky.actor.putPreferences({preferences: []}) + await pdsAgent(agent).app.bsky.actor.putPreferences({preferences: []}) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, diff --git a/src/state/queries/starter-packs.ts b/src/state/queries/starter-packs.ts --- a/src/state/queries/starter-packs.ts +++ b/src/state/queries/starter-packs.ts @@ -27,6 +27,7 @@ import {invalidateActorStarterPacksQuery} from '#/state/queries/actor-starter-packs' import {STALE} from '#/state/queries/index' import {invalidateListMembersQuery} from '#/state/queries/list-members' import {useAgent} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import * as bsky from '#/types/bsky' const RQKEY_ROOT = 'starter-pack' @@ -203,7 +204,7 @@ ) if (removedItems.length !== 0) { const chunks = chunk(removedItems, 50) for (const chunk of chunks) { - await agent.com.atproto.repo.applyWrites({ + await pdsAgent(agent).com.atproto.repo.applyWrites({ repo: agent.session!.did, writes: chunk.map(i => ({ $type: 'com.atproto.repo.applyWrites#delete', @@ -220,7 +221,7 @@ ) if (addedProfiles.length > 0) { const chunks = chunk(addedProfiles, 50) for (const chunk of chunks) { - await agent.com.atproto.repo.applyWrites({ + await pdsAgent(agent).com.atproto.repo.applyWrites({ repo: agent.session!.did, writes: chunk.map(p => ({ $type: 'com.atproto.repo.applyWrites#create', @@ -237,7 +238,7 @@ } } const rkey = parseStarterPackUri(currentStarterPack.uri)!.rkey - await agent.com.atproto.repo.putRecord({ + await pdsAgent(agent).com.atproto.repo.putRecord({ repo: agent.session!.did, collection: 'app.bsky.graph.starterpack', rkey, diff --git a/src/state/queries/threadgate/index.ts b/src/state/queries/threadgate/index.ts --- a/src/state/queries/threadgate/index.ts +++ b/src/state/queries/threadgate/index.ts @@ -18,6 +18,7 @@ threadgateViewToAllowUISetting, } from '#/state/queries/threadgate/util' import {useUpdatePostThreadThreadgateQueryCache} from '#/state/queries/usePostThread' import {useAgent} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import {useThreadgateHiddenReplyUrisAPI} from '#/state/threadgate-hidden-replies' import * as bsky from '#/types/bsky' @@ -162,7 +163,7 @@ hiddenReplies: threadgate.hiddenReplies || [], }) await networkRetry(2, () => - agent.api.com.atproto.repo.putRecord({ + pdsAgent(agent).com.atproto.repo.putRecord({ repo: agent.session!.did, collection: 'app.bsky.feed.threadgate', rkey: postUrip.rkey, diff --git a/src/state/session/agent.ts b/src/state/session/agent.ts --- a/src/state/session/agent.ts +++ b/src/state/session/agent.ts @@ -242,7 +242,7 @@ throw e }), getAge(birthDate) < 18 && networkRetry(3, () => { - return agent.com.atproto.repo.putRecord({ + return pdsAgent(agent).com.atproto.repo.putRecord({ repo: account.did, collection: 'chat.bsky.actor.declaration', rkey: 'self', @@ -457,6 +457,17 @@ const cloned = new BskyAgent({service: this.serviceUrl.toString()}) cloned.sessionManager.session = this.sessionManager.session return cloned } +} + +/** + * Returns an agent configured to make requests directly to the user's PDS + * without the appview proxy header. Use this for com.atproto.* methods and + * other PDS-specific operations like preferences. + */ +export function pdsAgent(agent: T): T { + const clone = agent.clone() as T + clone.configureProxy(null) + return clone } export type {BskyAppAgent} diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx --- a/src/state/session/index.tsx +++ b/src/state/session/index.tsx @@ -12,6 +12,7 @@ type BskyAppAgent, createAgentAndCreateAccount, createAgentAndLogin, createAgentAndResume, + pdsAgent, sessionAccountToSession, } from './agent' import {type Action, getInitialState, reducer, type State} from './reducer' @@ -248,7 +249,7 @@ SessionApiContext['partialRefreshSession'] >(async () => { const agent = state.currentAgentState.agent as BskyAppAgent const signal = cancelPendingTask() - const {data} = await agent.com.atproto.server.getSession() + const {data} = await pdsAgent(agent).com.atproto.server.getSession() if (signal.aborted) return store.dispatch({ type: 'partial-refresh-session', diff --git a/src/view/com/modals/DeleteAccount.tsx b/src/view/com/modals/DeleteAccount.tsx --- a/src/view/com/modals/DeleteAccount.tsx +++ b/src/view/com/modals/DeleteAccount.tsx @@ -19,6 +19,7 @@ import {useTheme} from '#/lib/ThemeContext' import {isAndroid, isWeb} from '#/platform/detection' import {useModalControls} from '#/state/modals' import {useAgent, useSession, useSessionApi} from '#/state/session' +import {pdsAgent} from '#/state/session/agent' import {atoms as a, useTheme as useNewTheme} from '#/alf' import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo' import {Text as NewText} from '#/components/Typography' @@ -49,7 +50,7 @@ const onPressSendEmail = async () => { setError('') setIsProcessing(true) try { - await agent.com.atproto.server.requestAccountDelete() + await pdsAgent(agent).com.atproto.server.requestAccountDelete() setIsEmailSent(true) } catch (e: any) { setError(cleanError(e)) @@ -76,7 +77,7 @@ ) if (!success) { throw new Error('Failed to inform chat service of account deletion') } - await agent.com.atproto.server.deleteAccount({ + await pdsAgent(agent).com.atproto.server.deleteAccount({ did: currentAccount.did, password, token, -- tangled.sh