import { useState } from 'react' import Head from 'next/head' import Link from 'next/link' import Layout from '@/components/layout' import { useAuth } from '@/lib/auth/useAuth' export default function VerifyEmail() { const { user, isAuthenticated } = useAuth() const [email, setEmail] = useState('') const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState(null) const [success, setSuccess] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setIsLoading(true) setError(null) const emailToVerify = isAuthenticated ? user?.email : email if (!emailToVerify) { setError('Email address is required') setIsLoading(false) return } try { const response = await fetch('/api/auth/verify-email', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: emailToVerify }), }) const data = await response.json() if (!response.ok) { setError(data.message || 'An error occurred') return } setSuccess(true) } catch (err) { setError('An unexpected error occurred') } finally { setIsLoading(false) } } if (success) { return ( Verification Email Sent | LocalGreenChain

Check Your Email

If an account exists with that email address, we've sent you a verification link.

Didn't receive the email? Check your spam folder or{' '}

Go to homepage
) } return ( Verify Email | LocalGreenChain

Verify your email

{isAuthenticated ? 'Click the button below to resend a verification email.' : 'Enter your email address to receive a verification link.'}

{error && (
{error}
)}
{isAuthenticated ? (

Logged in as: {user?.email}

) : (
setEmail(e.target.value)} className="mt-1 appearance-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-md focus:outline-none focus:ring-green-500 focus:border-green-500 sm:text-sm" placeholder="you@example.com" />
)}
) }