'use client'; import React, { useState } from 'react'; import { app, auth } from '@/app/firebase/config'; import { signInWithEmailAndPassword, getAuth } from 'firebase/auth'; import GoogleSignInButton from '../firebase/components/GoogleSignInButton'; import { useRouter } from 'next/navigation'; import { LoginSologin } from '../sologin'; const SignIn = () => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(null); const router = useRouter(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); try { const userCredential = await signInWithEmailAndPassword(auth, email, password); console.log('User signed in:', userCredential.user); await LoginSologin(userCredential.user); onLoginSuccess(); setEmail(''); setPassword(''); setError(null); // Clear errors on successful login } catch (err: any) { // Set the error message based on Firebase error codes switch (err.code) { case 'auth/user-not-found': setError('User not found. Please check your email and try again.'); break; case 'auth/invalid-credential': setError('Incorrect password. Please try again.'); break; case 'auth/network-request-failed': setError('Unable to connect. Please check your internet connection.'); break; default: setError('An unexpected error occurred. Please try again.'); console.error(err.code); } } }; const onLoginSuccess = ()=>{ router.push('/'); } return (

Sign In

setEmail(e.target.value)} required />
setPassword(e.target.value)} required />

Don't have an account?{' '} Sign Up

{/* Error Dialog */} {error && (

Error

{error}

)}
); }; export default SignIn;