migrate pds detection handle resolution to the public appview client
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,15 @@
|
|||||||
import {useState} from 'react'
|
import {useState} from 'react'
|
||||||
import {type DidDocument, getPdsEndpoint} from '@atproto/common-web'
|
import {type DidDocument, getPdsEndpoint} from '@atproto/common-web'
|
||||||
|
import {type HandleString} from '@atproto/syntax'
|
||||||
import {useQuery, useQueryClient} from '@tanstack/react-query'
|
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 {useDebouncedValue} from '#/lib/hooks/useDebouncedValue'
|
||||||
import {isNetworkError} from '#/lib/strings/errors'
|
import {isNetworkError} from '#/lib/strings/errors'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {STALE} from '#/state/queries'
|
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'
|
const RQKEY_ROOT = 'pds-detection'
|
||||||
export const RQKEY = (identifier: string) => [RQKEY_ROOT, identifier]
|
export const RQKEY = (identifier: string) => [RQKEY_ROOT, identifier]
|
||||||
@@ -147,16 +149,25 @@ export async function resolvePdsForIdentifier(
|
|||||||
identifier: string,
|
identifier: string,
|
||||||
): Promise<{did: string; pdsUrl: string | null} | null> {
|
): Promise<{did: string; pdsUrl: string | null} | null> {
|
||||||
const norm = normalizeIdentifier(identifier)
|
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 {
|
try {
|
||||||
let did: string
|
let did: string
|
||||||
if (norm.startsWith('did:')) {
|
if (norm.startsWith('did:')) {
|
||||||
did = norm
|
did = norm
|
||||||
} else {
|
} else {
|
||||||
const res = await withResolveTimeout(signal =>
|
const data = await withResolveTimeout(signal =>
|
||||||
agent.resolveHandle({handle: norm}, {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', {
|
logger.debug('pds-detection: resolved identifier to DID', {
|
||||||
identifier: norm,
|
identifier: norm,
|
||||||
|
|||||||
Reference in New Issue
Block a user