'use client'; import { useState, FormEvent } from 'react'; import Link from 'next/link'; import { useAuth } from '@/lib/auth'; export default function RegisterPage() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(false); const { signUp, signInWithGoogle } = useAuth(); // Handle registration form submission const handleSubmit = async (e: FormEvent) => { e.preventDefault(); setError(null); // Validate passwords if (password !== confirmPassword) { setError('Passwords do not match'); return; } // Password strength validation if (password.length < 6) { setError('Password must be at least 6 characters'); return; } setIsLoading(true); try { await signUp(email, password); // After successful registration, redirect to login page with email verification prompt } catch (error) { console.error('Registration error:', error); setError('Registration failed. Please try again later or use a different email'); } finally { setIsLoading(false); } }; // Handle Google registration/login const handleGoogleSignIn = async () => { setError(null); try { await signInWithGoogle(); // Login flow will redirect to Google and then back to the application } catch (error) { console.error('Google sign in error:', error); setError('Google login failed. Please try again later'); } }; return (

Register

Create your account to access the analytics dashboard

{/* Error message */} {error && (
{error}
)}
setEmail(e.target.value)} className="mt-1 block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm placeholder-gray-400 dark:placeholder-gray-500 dark:bg-gray-700 dark:text-white focus:outline-none focus:ring-blue-500 focus:border-blue-500" placeholder="your@email.com" />
setPassword(e.target.value)} className="mt-1 block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm placeholder-gray-400 dark:placeholder-gray-500 dark:bg-gray-700 dark:text-white focus:outline-none focus:ring-blue-500 focus:border-blue-500" placeholder="********" />
setConfirmPassword(e.target.value)} className="mt-1 block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm placeholder-gray-400 dark:placeholder-gray-500 dark:bg-gray-700 dark:text-white focus:outline-none focus:ring-blue-500 focus:border-blue-500" placeholder="********" />
or

Already have an account?{' '} Log in

); }