// src/app/login/page.tsx // 'use client'; // import { useState } from 'react'; // import { useForm } from 'react-hook-form'; // import { zodResolver } from '@hookform/resolvers/zod'; // import * as z from 'zod'; // import Link from 'next/link'; // import { Mail, Lock } from 'lucide-react'; // import { useAuth } from '@/lib/hooks/useAuth'; // import { Button } from '@/components/ui/Button'; // import { Input } from '@/components/ui/Input'; // const loginSchema = z.object({ // email: z.string().email('Please enter a valid email address'), // password: z.string().min(1, 'Password is required'), // }); // type LoginForm = z.infer; // export default function LoginPage() { // const { login, isLoading } = useAuth(); // const [error, setError] = useState(null); // const { // register, // handleSubmit, // formState: { errors }, // } = useForm({ // resolver: zodResolver(loginSchema), // }); // const onSubmit = async (data: LoginForm) => { // try { // setError(null); // await login(data.email, data.password); // } catch (err: any) { // setError(err.message || 'Invalid email or password'); // } // }; // return ( //
//
// // DyoLink // //

// Sign in to your account //

//

// Or{' '} // // start your free trial // //

//
//
//
//
// } // /> // } // /> //
//
// // //
//
// // Forgot your password? // //
//
// {error && ( //
//

{error}

//
// )} // //
//
//
//
// ); // } 'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import * as z from 'zod'; import Link from 'next/link'; import { Mail, Lock } from 'lucide-react'; import { useAuth } from '@/lib/hooks/useAuth'; import { Button } from '@/components/ui/common/Button'; import { Input } from '@/components/ui/common/Input'; const loginSchema = z.object({ email: z.string().email('Please enter a valid email address'), password: z.string().min(1, 'Password is required'), }); type LoginForm = z.infer; export default function LoginPage() { const { login, isLoading, user, isAuthReady } = useAuth(); const router = useRouter(); const [error, setError] = useState(null); useEffect(() => { if (isAuthReady && user) { router.push('/today'); } }, [user, isAuthReady, router]); const { register, handleSubmit, formState: { errors }, } = useForm({ resolver: zodResolver(loginSchema), }); const onSubmit = async (data: LoginForm) => { try { setError(null); await login(data.email, data.password); } catch (err: any) { setError(err.message || 'Invalid email or password'); } }; if (!isAuthReady) { return (

Loading...

); } return (
DyoLink

Sign in to your account

Or{' '} start your free trial

} /> } />
Forgot your password?
{error && (

{error}

)}
); }