about summary refs log tree commit diff
path: root/src/components/dialogs/EmailDialog/data/useConfirmEmail.ts
blob: 475a8cbfb603b9af607ca39f0a6c20307c371312 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import {useMutation} from '@tanstack/react-query'

import {useAgent, useSession} from '#/state/session'

export function useConfirmEmail() {
  const agent = useAgent()
  const {currentAccount} = useSession()

  return useMutation({
    mutationFn: async ({token}: {token: string}) => {
      if (!currentAccount?.email) {
        throw new Error('No email found for the current account')
      }

      await agent.com.atproto.server.confirmEmail({
        email: currentAccount.email,
        token: token.trim(),
      })
      // will update session state at root of app
      await agent.resumeSession(agent.session!)
    },
  })
}