migrate the app password and update handle mutations to the pds client

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-03 20:32:56 +03:00
parent 1d5c0ff4af
commit 09ca1307bc
4 changed files with 26 additions and 22 deletions
+13 -15
View File
@@ -1,39 +1,37 @@
import {type ComAtprotoServerCreateAppPassword} from '@atproto/api'
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
import {STALE} from '#/state/queries'
import {useAgent} from '../session'
import {com} from '#/lexicons'
import {usePdsClient} from '../session'
const RQKEY_ROOT = 'app-passwords'
export const RQKEY = () => [RQKEY_ROOT]
export function useAppPasswordsQuery() {
const agent = useAgent()
const client = usePdsClient()
return useQuery({
staleTime: STALE.MINUTES.FIVE,
queryKey: RQKEY(),
queryFn: async () => {
const res = await agent.com.atproto.server.listAppPasswords({})
return res.data.passwords
const data = await client.call(com.atproto.server.listAppPasswords)
return data.passwords
},
})
}
export function useAppPasswordCreateMutation() {
const queryClient = useQueryClient()
const agent = useAgent()
const client = usePdsClient()
return useMutation<
ComAtprotoServerCreateAppPassword.OutputSchema,
com.atproto.server.createAppPassword.$OutputBody,
Error,
{name: string; privileged: boolean}
>({
mutationFn: async ({name, privileged}) => {
return (
await agent.com.atproto.server.createAppPassword({
name,
privileged,
})
).data
return await client.call(com.atproto.server.createAppPassword, {
name,
privileged,
})
},
onSuccess() {
queryClient.invalidateQueries({
@@ -45,10 +43,10 @@ export function useAppPasswordCreateMutation() {
export function useAppPasswordDeleteMutation() {
const queryClient = useQueryClient()
const agent = useAgent()
const client = usePdsClient()
return useMutation<void, Error, {name: string}>({
mutationFn: async ({name}) => {
await agent.com.atproto.server.revokeAppPassword({
await client.call(com.atproto.server.revokeAppPassword, {
name,
})
},
+9 -3
View File
@@ -1,8 +1,10 @@
import {useCallback} from 'react'
import {type HandleString} from '@atproto/syntax'
import {useMutation, useQueryClient} from '@tanstack/react-query'
import {STALE} from '#/state/queries'
import {useAgent} from '#/state/session'
import {useAgent, usePdsClient} from '#/state/session'
import {com} from '#/lexicons'
const handleQueryKeyRoot = 'handle'
const fetchHandleQueryKey = (handleOrDid: string) => [
@@ -36,11 +38,15 @@ export function useUpdateHandleMutation(opts?: {
onSuccess?: (handle: string) => void
}) {
const queryClient = useQueryClient()
const agent = useAgent()
const client = usePdsClient()
return useMutation({
mutationFn: async ({handle}: {handle: string}) => {
await agent.updateHandle({handle})
// `agent.updateHandle` was a pure alias for this method
await client.call(com.atproto.identity.updateHandle, {
// callers validate the handle before submitting
handle: handle as HandleString,
})
},
onSuccess(_data, variables) {
opts?.onSuccess?.(variables.handle)