mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at samuel/exp-cli 29 lines 948 B view raw
1import {useMutation} from '@tanstack/react-query' 2 3import {useAgent, useSession} from '#/state/session' 4import {useUpdateAccountEmailStateQueryCache} from '#/components/dialogs/EmailDialog/data/useAccountEmailState' 5 6export function useConfirmEmail() { 7 const agent = useAgent() 8 const {currentAccount} = useSession() 9 const updateAccountEmailStateQueryCache = 10 useUpdateAccountEmailStateQueryCache() 11 12 return useMutation({ 13 mutationFn: async ({token}: {token: string}) => { 14 if (!currentAccount?.email) { 15 throw new Error('No email found for the current account') 16 } 17 18 await agent.com.atproto.server.confirmEmail({ 19 email: currentAccount.email, 20 token: token.trim(), 21 }) 22 const {data} = await agent.resumeSession(agent.session!) 23 updateAccountEmailStateQueryCache({ 24 isEmailVerified: !!data.emailConfirmed, 25 email2FAEnabled: !!data.emailAuthFactor, 26 }) 27 }, 28 }) 29}