'use client'; import { useState } from 'react'; import { useRouter, useSearchParams } from 'next/navigation'; import { signIn } from 'next-auth/react'; import Link from 'next/link'; export default function LoginPage() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const router = useRouter(); const searchParams = useSearchParams(); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setLoading(true); setError(''); const res = await signIn('credentials', { redirect: false, email, password, callbackUrl: searchParams.get('callbackUrl') || '/', }); setLoading(false); if (res?.error) { setError('Invalid email or password'); } else if (res?.ok) { router.push(res.url || '/'); } } async function handleGoogle() { setLoading(true); await signIn('google', { callbackUrl: searchParams.get('callbackUrl') || '/' }); setLoading(false); } return (
Or{' '} Sign Up For Free