From 590a89fd6692452fc546edd7acb5cdfad288bc4d Mon Sep 17 00:00:00 2001 From: smog-root Date: Wed, 16 Oct 2024 17:18:37 +0530 Subject: [PATCH] Updated_trusted_mail_services --- frontend/src/components/Signup/Signup.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/Signup/Signup.js b/frontend/src/components/Signup/Signup.js index 04b58a9..3243aeb 100644 --- a/frontend/src/components/Signup/Signup.js +++ b/frontend/src/components/Signup/Signup.js @@ -2,16 +2,13 @@ import React, { useEffect, useState } from "react"; import { useCreateUserWithEmailAndPassword } from "react-firebase-hooks/auth"; import { useNavigate } from "react-router-dom"; import { registerValidation } from "../../validations/validation"; - import { auth, signInWithGoogle } from "../Firebase/firebase"; // Import Firebase auth and Google sign-in import GoogleButton from '../GoogleButton/GoogleButton'; - import toast from "react-hot-toast"; import Footer from "../Footer/Footer.js"; - - function Signup() { + const trustedDomains = ["gmail.com", "yahoo.com", "outlook.com", "icloud.com", "hotmail.com"]; const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); @@ -21,6 +18,7 @@ function Signup() { const [showPassword, setShowPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false); const [errors, setErrors] = useState({}); + const [emailError, setEmailError] = useState(""); // State for email validation feedback const navigate = useNavigate(); const [createUserWithEmailAndPassword, user, loading, firebaseError] = @@ -46,11 +44,21 @@ function Signup() { const handleSignup = async (e) => { e.preventDefault(); + // Check email format if (!regex.test(email)) { toast.error("Invalid email"); return; } + // Check email domain + const emailDomain = email.split("@")[1]; + if (!trustedDomains.includes(emailDomain)) { + setEmailError("Please use a trusted email provider (Gmail, Yahoo, Outlook, iCloud, Hotmail)."); + return; + } else { + setEmailError(""); // Clear error if valid + } + try { await registerValidation.validate( { email, password, confirmPassword }, @@ -102,6 +110,7 @@ function Signup() { {successMessage && (
{successMessage}
)} + {emailError &&
{emailError}
} {/* Email error message */}
@@ -111,7 +120,10 @@ function Signup() { className="form-control" placeholder="Enter your email" value={email} - onChange={(e) => setEmail(e.target.value)} + onChange={(e) => { + setEmail(e.target.value); + setEmailError(""); // Clear email error on change + }} /> {errors.email &&
{errors.email}
}