blob: 3e341cd7380b50e7ad7a49ef7bfd5914999cb22d (
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
import React from 'react'
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {useAgent, useSession} from '#/state/session'
import {useDialogControl} from '#/components/Dialog'
import {ChangeEmailDialog} from '#/components/dialogs/ChangeEmailDialog'
import {VerifyEmailDialog} from '#/components/dialogs/VerifyEmailDialog'
import * as Prompt from '#/components/Prompt'
import {DisableEmail2FADialog} from './DisableEmail2FADialog'
import * as SettingsList from './SettingsList'
export function Email2FAToggle() {
const {_} = useLingui()
const {currentAccount} = useSession()
const disableDialogControl = useDialogControl()
const enableDialogControl = useDialogControl()
const verifyEmailDialogControl = useDialogControl()
const changeEmailDialogControl = useDialogControl()
const agent = useAgent()
const enableEmailAuthFactor = React.useCallback(async () => {
if (currentAccount?.email) {
await agent.com.atproto.server.updateEmail({
email: currentAccount.email,
emailAuthFactor: true,
})
await agent.resumeSession(agent.session!)
}
}, [currentAccount, agent])
const onToggle = React.useCallback(() => {
if (!currentAccount) {
return
}
if (currentAccount.emailAuthFactor) {
disableDialogControl.open()
} else {
if (!currentAccount.emailConfirmed) {
verifyEmailDialogControl.open()
return
}
enableDialogControl.open()
}
}, [
currentAccount,
enableDialogControl,
verifyEmailDialogControl,
disableDialogControl,
])
return (
<>
<DisableEmail2FADialog control={disableDialogControl} />
<Prompt.Basic
control={enableDialogControl}
title={_(msg`Enable Email 2FA`)}
description={_(msg`Require an email code to sign in to your account.`)}
onConfirm={enableEmailAuthFactor}
confirmButtonCta={_(msg`Enable`)}
/>
<VerifyEmailDialog
control={verifyEmailDialogControl}
changeEmailControl={changeEmailDialogControl}
onCloseAfterVerifying={enableDialogControl.open}
reasonText={_(
msg`You need to verify your email address before you can enable email 2FA.`,
)}
/>
<ChangeEmailDialog
control={changeEmailDialogControl}
verifyEmailControl={verifyEmailDialogControl}
/>
<SettingsList.BadgeButton
label={
currentAccount?.emailAuthFactor ? _(msg`Change`) : _(msg`Enable`)
}
onPress={onToggle}
/>
</>
)
}
|