Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -56,7 +64,6 @@ export default function Login() {
setLoading(false);
}
};

const handleGoogleLogin = async () => {
const provider = new GoogleAuthProvider();
setLoading(true);
Expand Down
24 changes: 19 additions & 5 deletions src/components/Register.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
};
Expand All @@ -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;
Expand All @@ -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 (
<div className="min-h-screen bg-white grid grid-cols-1 lg:grid-cols-[auto,1fr] justify-items-center items-center p-6 md:p-12 lg:p-0 lg:max-w-screen-lg mx-auto">
<motion.form
Expand Down