fix bug with checkHandleAvailability

This commit is contained in:
Samuel Newman
2025-08-05 11:57:06 +03:00
parent 94d7236407
commit 2917baa12e
2 changed files with 9 additions and 16 deletions
+6 -6
View File
@@ -22,7 +22,6 @@ import {
checkHandleAvailability,
useHandleAvailabilityQuery,
} from '#/state/queries/handle-availability'
import {useAgent} from '#/state/session'
import {ScreenTransition} from '#/screens/Login/ScreenTransition'
import {useSignupContext} from '#/screens/Signup/state'
import {atoms as a, native, useTheme} from '#/alf'
@@ -39,7 +38,6 @@ export function StepHandle() {
const {_} = useLingui()
const t = useTheme()
const {state, dispatch} = useSignupContext()
const agent = useAgent()
const [draftValue, setDraftValue] = useState(state.handle)
const isNextLoading = useThrottledValue(state.isLoading, 500)
@@ -58,8 +56,6 @@ export function StepHandle() {
})
const onNextPress = async () => {
if (!isHandleAvailable?.available) return
const handle = draftValue.trim()
dispatch({
type: 'setHandle',
@@ -74,8 +70,7 @@ export function StepHandle() {
try {
const {available: handleAvailable} = await checkHandleAvailability(
agent,
handle,
createFullHandle(handle, state.userDomain),
state.serviceDescription?.did ?? 'UNKNOWN',
{typeahead: false},
)
@@ -88,6 +83,11 @@ export function StepHandle() {
})
return
}
} catch (error) {
logger.error('Failed to check handle availability on next press', {
safeMessage: error,
})
// do nothing on error, let them pass
} finally {
dispatch({type: 'setIsLoading', value: false})
}
+3 -10
View File
@@ -1,4 +1,3 @@
import {useMemo} from 'react'
import {Agent, ComAtprotoTempCheckHandleAvailability} from '@atproto/api'
import {useQuery} from '@tanstack/react-query'
@@ -38,13 +37,6 @@ export function useHandleAvailabilityQuery(
) {
const name = username.trim()
const debouncedHandle = useDebouncedValue(name, debounceDelayMs)
const agent = useMemo(() => {
if (serviceDid === BSKY_SERVICE_DID) {
return new Agent({service: BSKY_SERVICE})
} else {
return new Agent({service: PUBLIC_BSKY_SERVICE})
}
}, [serviceDid])
return {
enabled: enabled && name === debouncedHandle,
@@ -57,7 +49,7 @@ export function useHandleAvailabilityQuery(
),
queryFn: async () => {
const handle = createFullHandle(name, serviceDomain)
return await checkHandleAvailability(agent, handle, serviceDid, {
return await checkHandleAvailability(handle, serviceDid, {
email,
birthDate,
typeahead: true,
@@ -68,7 +60,6 @@ export function useHandleAvailabilityQuery(
}
export async function checkHandleAvailability(
agent: Agent,
handle: string,
serviceDid: string,
{
@@ -82,6 +73,7 @@ export async function checkHandleAvailability(
},
) {
if (serviceDid === BSKY_SERVICE_DID) {
const agent = new Agent({service: BSKY_SERVICE})
// entryway has a special API for handle availability
const {data} = await agent.com.atproto.temp.checkHandleAvailability({
handle,
@@ -116,6 +108,7 @@ export async function checkHandleAvailability(
}
} else {
// 3rd party PDSes won't have this API so just try and resolve the handle
const agent = new Agent({service: PUBLIC_BSKY_SERVICE})
try {
const res = await agent.resolveHandle({
handle,