import { FunctionComponent } from 'preact'; import { Title, Text, PreferencesGroup, PreferencesSegment, } from '../components'; import { Switch } from '../../components/Switch'; import { observer } from 'mobx-react-lite'; import { DecoratedInput } from '../../components/DecoratedInput'; import { IconButton } from '../../components/IconButton'; import { TwoFactorAuth } from '../models'; // Temporary implementation until integration function downloadSecretKey(text: string) { const link = document.createElement('a'); const blob = new Blob([text], { type: 'text/plain;charset=utf-8', }); link.href = window.URL.createObjectURL(blob); link.setAttribute('download', 'secret_key.txt'); document.body.appendChild(link); link.click(); link.remove(); window.URL.revokeObjectURL(link.href); } export const TwoFactorAuthComponent: FunctionComponent<{ tfAuth: TwoFactorAuth; }> = observer(({ tfAuth }) => { return (
Two-factor authentication An extra layer of security when logging in to your account.
tfAuth.toggle2FA()} />
{tfAuth.twoFactorStatus === 'enabled' && tfAuth.twoFactorData != null ? ( ) : ( )}
); }); const TwoFactorEnabled: FunctionComponent<{ tfAuth: TwoFactorAuth }> = observer( ({ tfAuth }) => { const state = tfAuth.twoFactorData!; const download = ( { downloadSecretKey(state.secretKey); }} /> ); const copy = ( { navigator?.clipboard?.writeText(state.secretKey); }} /> ); const spinner =
; return (
Secret Key
Authentication Code
); } ); const TwoFactorDisabled: FunctionComponent = () => ( Enabling two-factor authentication will sign you out of all other sessions.{' '} Learn more );