1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
import {ComAtprotoServerCreateAppPassword} from '@atproto/api'
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
import {STALE} from '#/state/queries'
import {useAgent} from '../session'
const RQKEY_ROOT = 'app-passwords'
export const RQKEY = () => [RQKEY_ROOT]
export function useAppPasswordsQuery() {
const agent = useAgent()
return useQuery({
staleTime: STALE.MINUTES.FIVE,
queryKey: RQKEY(),
queryFn: async () => {
const res = await agent.com.atproto.server.listAppPasswords({})
return res.data.passwords
},
})
}
export function useAppPasswordCreateMutation() {
const queryClient = useQueryClient()
const agent = useAgent()
return useMutation<
ComAtprotoServerCreateAppPassword.OutputSchema,
Error,
{name: string; privileged: boolean}
>({
mutationFn: async ({name, privileged}) => {
return (
await agent.com.atproto.server.createAppPassword({
name,
privileged,
})
).data
},
onSuccess() {
queryClient.invalidateQueries({
queryKey: RQKEY(),
})
},
})
}
export function useAppPasswordDeleteMutation() {
const queryClient = useQueryClient()
const agent = useAgent()
return useMutation<void, Error, {name: string}>({
mutationFn: async ({name}) => {
await agent.com.atproto.server.revokeAppPassword({
name,
})
},
onSuccess() {
queryClient.invalidateQueries({
queryKey: RQKEY(),
})
},
})
}
|