blob: 358bf8654446fcf8b56a301e8cb066f35b77085e (
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
24
25
26
27
28
29
|
import {useMutation} from '@tanstack/react-query'
import {useAgent, useSession} from '#/state/session'
export function useManageEmail2FA() {
const agent = useAgent()
const {currentAccount} = useSession()
return useMutation({
mutationFn: async ({
enabled,
token,
}:
| {enabled: true; token?: undefined}
| {enabled: false; token: string}) => {
if (!currentAccount?.email) {
throw new Error('No email found for the current account')
}
await agent.com.atproto.server.updateEmail({
email: currentAccount.email,
emailAuthFactor: enabled,
token,
})
// will update session state at root of app
await agent.resumeSession(agent.session!)
},
})
}
|