diff --git a/src/components/Login.js b/src/components/Login.js index 8fd141f..00c06b9 100644 --- a/src/components/Login.js +++ b/src/components/Login.js @@ -40,14 +40,22 @@ export default function Login() { e.preventDefault(); setLoading(true); try { + // Sign in with email and password const userCredential = await signInWithEmailAndPassword(auth, email, password); const user = userCredential.user; setCurrentUser(user); - + + // Check if email is verified if (user.emailVerified) { navigate('/dashboard'); } else { + // Show modal to resend verification email setShowVerificationModal(true); + + // Send verification email + await sendEmailVerification(user); + console.log("Verification email sent"); + alert('Verification email sent! Please check your inbox.'); } } catch (error) { setError(error.message); @@ -56,7 +64,6 @@ export default function Login() { setLoading(false); } }; - const handleGoogleLogin = async () => { const provider = new GoogleAuthProvider(); setLoading(true); diff --git a/src/components/Register.js b/src/components/Register.js index cd513a4..0e7eefd 100644 --- a/src/components/Register.js +++ b/src/components/Register.js @@ -1,4 +1,5 @@ import { useState } from "react"; +import { sendEmailVerification } from "firebase/auth"; import { createUserWithEmailAndPassword } from "firebase/auth"; import { auth } from "../firebase"; import { useNavigate } from "react-router-dom"; @@ -44,7 +45,9 @@ export default function Register() { toast.error("Please enter a valid email address."); } }; - + + const handleSubmit = async (e) => { + e.preventDefault(); const togglePasswordVisibility = () => { setShowPassword((prev) => !prev); }; @@ -56,7 +59,6 @@ export default function Register() { toast.error("You must agree to the terms to register."); return; } - if (emailError || !validateEmail(email)) { toast.error("Please enter a valid email address."); return; @@ -65,14 +67,26 @@ export default function Register() { toast.error("Passwords do not match."); return; } + try { - await createUserWithEmailAndPassword(auth, email, password); - navigate("/dashboard"); + // Create a new user with email and password + const userCredential = await createUserWithEmailAndPassword(auth, email, password); + const user = userCredential.user; + + // Send email verification + await sendEmailVerification(user); + + // Display a success message for email verification + toast.success("Registration successful! Please check your email for verification."); + + // Navigate to the login page + navigate("/login"); + } catch (error) { + // Handle any errors during registration toast.error(error.message); } }; - return (