import { useState } from 'react' import { Link, useNavigate } from 'react-router-dom' import { authClient } from '../lib/auth-client.ts' import { useAuthStore } from '../stores/auth.ts' export function Login() { const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const navigate = useNavigate() const setAuthenticated = useAuthStore((s) => s.setAuthenticated) async function handleSubmit(e: React.FormEvent) { e.preventDefault() setError('') if (!email || !password) { setError('Please fill in all fields.') return } setLoading(true) try { const { error: authError } = await authClient.signIn.email({ email, password, }) if (authError) { throw new Error(authError.message ?? 'Sign in failed') } setAuthenticated(true) navigate('/') } catch { if (import.meta.env.VITE_MOCK_AUTH === 'true') { setAuthenticated(true) navigate('/') } else { setError('Invalid email or password. Please try again.') } } finally { setLoading(false) } } return (
Track prices. Save money.
{error && (Don't have an account?{' '} Sign up