Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132import {useMutation} from '@tanstack/react-query'
import {checkAndFormatResetCode} from '#/lib/strings/password'import {usePdsClient, useSession, useSessionApi} from '#/state/session'import {com} from '#/lexicons'
export function useManageEmail2FA() { const pdsClient = usePdsClient() const {currentAccount} = useSession() const {refreshSession} = useSessionApi()
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 pdsClient.call(com.atproto.server.updateEmail, { email: currentAccount.email, emailAuthFactor: enabled, token: token ? checkAndFormatResetCode(token) || token : token, }) // will update session state at root of app await refreshSession() }, })}