import { useState } from 'react'; import { useApp } from '../context/AppContext.js'; import { themeVars } from '../components/reader/readerThemes.js'; import { loginUser, registerUser, verifyMfaLogin, logoutUser } from '../syncService.js'; export default function AuthPage() { const { signIn, readerTheme } = useApp(); const shell = { style: themeVars(readerTheme) }; const [authMode, setAuthMode] = useState('login'); // 'login' | 'register' const [authForm, setAuthForm] = useState({ email: '', password: '' }); const [authError, setAuthError] = useState(''); const [authBusy, setAuthBusy] = useState(false); const [authMfaPending, setAuthMfaPending] = useState(false); // password ok, waiting on TOTP/backup code const [authMfaCode, setAuthMfaCode] = useState(''); const [authMfaUseBackup, setAuthMfaUseBackup] = useState(false); const submitAuth = async (e) => { e.preventDefault(); setAuthError(''); setAuthBusy(true); const action = authMode === 'login' ? loginUser : registerUser; const result = await action(authForm.email.trim(), authForm.password); setAuthBusy(false); if (!result.ok) { setAuthError(result.error ?? 'Something went wrong.'); return; } if (result.data?.mfaRequired) { setAuthMfaPending(true); return; } signIn(result.data); }; const submitMfa = async (e) => { e.preventDefault(); setAuthError(''); setAuthBusy(true); const result = await verifyMfaLogin( authMfaUseBackup ? { backupCode: authMfaCode.trim() } : { token: authMfaCode.trim() }, ); setAuthBusy(false); if (!result.ok) { setAuthError(result.error ?? 'Invalid code.'); return; } setAuthMfaPending(false); setAuthMfaCode(''); signIn(result.data); }; if (authMfaPending) { return (
Bible Study Project
{authMfaUseBackup ? 'Enter one of your saved backup codes.' : 'Enter the 6-digit code from your authenticator app.'}
Bible Study Project
Read Scripture in six translations, follow a reading plan into the text, and study a passage one chunk at a time with commentary, word studies, and cross-references beside it.
"Make every effort to present yourself approved to God, an unashamed workman who accurately handles the word of truth."
Bible Study Project