import { useState } from 'react' import { Link, useNavigate, useLocation } from 'react-router-dom' import { useAuthStore } from '@/store/authStore' import { cn } from '@/lib/utils' export function LoginPage() { const navigate = useNavigate() const location = useLocation() const { login, isLoading, error, clearError } = useAuthStore() const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [localError, setLocalError] = useState('') const from = (location.state as { from?: { pathname: string } })?.from?.pathname || '/trees' const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setLocalError('') clearError() if (!email || !password) { setLocalError('Please enter both email and password') return } try { await login({ email, password }) navigate(from, { replace: true }) } catch { // Error is set in the store } } return (
Sign in to your account