import { useState } from 'react' import { Link, useNavigate, useLocation } from 'react-router-dom' import { useAuth } from '../contexts/AuthContext' const isLocalDev = import.meta.env['VITE_SUPABASE_URL']?.includes('localhost') ?? false export function Login() { const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [totpCode, setTotpCode] = useState('') const [error, setError] = useState(null) const [loading, setLoading] = useState(false) const [showMfaChallenge, setShowMfaChallenge] = useState(false) const { signInWithEmail, signInWithGoogle, signInWithDiscord, verifyMfa } = useAuth() const navigate = useNavigate() const location = useLocation() const from = (location.state as { from?: { pathname: string } })?.from?.pathname ?? '/' async function handleSubmit(e: React.FormEvent) { e.preventDefault() setError(null) setLoading(true) const { error, requiresMfa } = await signInWithEmail(email, password) setLoading(false) if (error) { setError(error.message) } else if (requiresMfa) { setShowMfaChallenge(true) } else { navigate(from, { replace: true }) } } async function handleMfaSubmit(e: React.FormEvent) { e.preventDefault() setError(null) setLoading(true) const { error } = await verifyMfa(totpCode) setLoading(false) if (error) { setError(error.message) setTotpCode('') } else { navigate(from, { replace: true }) } } async function handleGoogleLogin() { setError(null) const { error } = await signInWithGoogle() if (error) setError(error.message) } async function handleDiscordLogin() { setError(null) const { error } = await signInWithDiscord() if (error) setError(error.message) } if (showMfaChallenge) { return (

Two-Factor Authentication

Enter the code from your authenticator app

{error && (
{error}
)}
setTotpCode(e.target.value.replace(/\D/g, ''))} autoFocus className="w-full px-3 py-2 bg-surface-2 border border-border-default rounded-lg focus:outline-none focus:ring-2 focus:ring-accent-500 text-center text-lg tracking-widest font-mono" autoComplete="one-time-code" />
) } return (

Welcome back

Sign in to your account

{error && (
{error}
)}
setEmail(e.target.value)} required className="w-full px-3 py-2 bg-surface-2 border border-border-default rounded-lg focus:outline-none focus:ring-2 focus:ring-accent-500 focus:border-transparent" />
setPassword(e.target.value)} required className="w-full px-3 py-2 bg-surface-2 border border-border-default rounded-lg focus:outline-none focus:ring-2 focus:ring-accent-500 focus:border-transparent" />
Or continue with
{isLocalDev && (

OAuth providers are not available in local development. Use email/password instead.

)}

Don't have an account?{' '} Sign up

) }