forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {useMutation} from '@tanstack/react-query'
2
3import {useAgent, useSession} from '#/state/session'
4import {pdsAgent} from '#/state/session/agent'
5
6export function useConfirmEmail({
7 onSuccess,
8 onError,
9}: {onSuccess?: () => void; onError?: () => void} = {}) {
10 const agent = useAgent()
11 const {currentAccount} = useSession()
12
13 return useMutation({
14 mutationFn: async ({token}: {token: string}) => {
15 if (!currentAccount?.email) {
16 throw new Error('No email found for the current account')
17 }
18
19 await pdsAgent(agent).com.atproto.server.confirmEmail({
20 email: currentAccount.email.trim(),
21 token: token.trim(),
22 })
23 // will update session state at root of app
24 await agent.resumeSession(agent.session!)
25 },
26 onSuccess,
27 onError,
28 })
29}