migrate pds detection handle resolution to the public appview client

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-03 18:00:21 +03:00
parent 6e59eeb9a6
commit 5e88752fc0
+17 -6
View File
@@ -1,13 +1,15 @@
import {useState} from 'react'
import {type DidDocument, getPdsEndpoint} from '@atproto/common-web'
import {type HandleString} from '@atproto/syntax'
import {useQuery, useQueryClient} from '@tanstack/react-query'
import {DEFAULT_SERVICE, PUBLIC_BSKY_SERVICE} from '#/lib/constants'
import {DEFAULT_SERVICE} from '#/lib/constants'
import {useDebouncedValue} from '#/lib/hooks/useDebouncedValue'
import {isNetworkError} from '#/lib/strings/errors'
import {logger} from '#/logger'
import {STALE} from '#/state/queries'
import {Agent} from '#/state/session/agent'
import {getPublicAppviewClient} from '#/state/session/clients'
import {com} from '#/lexicons'
const RQKEY_ROOT = 'pds-detection'
export const RQKEY = (identifier: string) => [RQKEY_ROOT, identifier]
@@ -147,16 +149,25 @@ export async function resolvePdsForIdentifier(
identifier: string,
): Promise<{did: string; pdsUrl: string | null} | null> {
const norm = normalizeIdentifier(identifier)
const agent = new Agent(null, {service: PUBLIC_BSKY_SERVICE})
/*
* Resolution runs without a session, so this uses the public appview client
* rather than a session-scoped one. It matches the unauthenticated,
* unproxied public agent this previously constructed by hand.
*/
const client = getPublicAppviewClient()
try {
let did: string
if (norm.startsWith('did:')) {
did = norm
} else {
const res = await withResolveTimeout(signal =>
agent.resolveHandle({handle: norm}, {signal}),
const data = await withResolveTimeout(signal =>
client.call(
com.atproto.identity.resolveHandle,
{handle: norm as HandleString},
{signal},
),
)
did = res.data.did
did = data.did
}
logger.debug('pds-detection: resolved identifier to DID', {
identifier: norm,