'use client'; import React, { useState } from 'react'; import { auth } from '@/app/firebase/config'; import { signInWithEmailAndPassword, createUserWithEmailAndPassword } from 'firebase/auth'; import GoogleSignInButton from '../firebase/components/GoogleSignInButton'; import { useRouter } from 'next/navigation'; import { LoginSologin, RegisterSologin } from '../sologin'; const AuthTabs = () => { const [activeTab, setActiveTab] = useState<'signin' | 'signup'>('signin'); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(null); const router = useRouter(); const onAuthSuccess = () => { router.push('/'); }; const handleAuth = async (e: React.FormEvent) => { e.preventDefault(); try { if (activeTab === 'signin') { const userCredential = await signInWithEmailAndPassword(auth, email, password); console.log('User signed in:', userCredential.user); await LoginSologin(userCredential.user); } else { const userCredential = await createUserWithEmailAndPassword(auth, email, password); console.log('User signed up:', userCredential.user); await RegisterSologin(userCredential.user); } onAuthSuccess(); setEmail(''); setPassword(''); setError(null); } catch (err: any) { const errorCode = err.code; switch (errorCode) { case 'auth/user-not-found': setError('User not found. Please check your email.'); break; case 'auth/email-already-in-use': setError('This email is already registered. Try signing in.'); break; case 'auth/wrong-password': setError('Incorrect email or password.'); break; default: setError('An unexpected error occurred. Please try again.'); } } }; return (
setEmail(e.target.value)} required />
setPassword(e.target.value)} required />
{/* Error Dialog */} {error && (

Error

{error}

)}
); }; export default AuthTabs;