import React, { useState } from 'react'; import { Button } from './Button'; import { Input } from './Input'; import { useAuth } from '../../contexts/AuthContext'; import { Loader2, Mail, Lock, AlertCircle } from 'lucide-react'; import { Modal } from './Modal'; export const AuthModal = ({ isOpen, onClose, onSuccess }) => { const [isSignIn, setIsSignIn] = useState(true); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [showSuccess, setShowSuccess] = useState(false); const { signIn, signUp, signInWithGoogle } = useAuth(); const handleSubmit = async (e) => { e.preventDefault(); setLoading(true); setError(null); try { const result = isSignIn ? await signIn(email, password) : await signUp(email, password); if (result.error) throw new Error(result.error.message || 'Authentication failed'); // Success handling if (isSignIn) { if (onSuccess) onSuccess(); onClose(); } else { setShowSuccess(true); } } catch (err) { console.error('Auth error:', err); setError(err.message); } finally { setLoading(false); } }; const handleGoogleSignIn = async () => { try { const result = await signInWithGoogle(); if (result?.error) throw new Error(result.error.message || 'Google sign-in failed'); } catch (err) { console.error('Google Auth error:', err); setError(err.message); } }; if (showSuccess) { return ( Verification Link Sent We sent a confirmation link to {email}. Click it to activate your account and start roasting! Check your spam folder if you don't see it. Got it! ); } return ( {error && ( {error} )} {/* Google Login */} Continue with Google Or with Email Email setEmail(e.target.value)} placeholder="you@example.com" className="pl-10" required /> Password setPassword(e.target.value)} placeholder="••••••••" className="pl-10" required /> {loading ? : (isSignIn ? 'Sign In' : 'Sign Up')} {isSignIn ? "Don't have an account? " : "Already have an account? "} setIsSignIn(!isSignIn)} className="font-bold underline hover:text-brutalist-red" > {isSignIn ? 'Sign Up' : 'Sign In'} ); };
Verification Link Sent
We sent a confirmation link to {email}. Click it to activate your account and start roasting!
Check your spam folder if you don't see it.