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 useManageEmail2FA() {
7 const agent = useAgent()
8 const {currentAccount} = useSession()
9
10 return useMutation({
11 mutationFn: async ({
12 enabled,
13 token,
14 }:
15 | {enabled: true; token?: undefined}
16 | {enabled: false; token: string}) => {
17 if (!currentAccount?.email) {
18 throw new Error('No email found for the current account')
19 }
20
21 await pdsAgent(agent).com.atproto.server.updateEmail({
22 email: currentAccount.email,
23 emailAuthFactor: enabled,
24 token,
25 })
26 // will update session state at root of app
27 await agent.resumeSession(agent.session!)
28 },
29 })
30}