Skip to content

Commit

Permalink
Filter genuine email added
Browse files Browse the repository at this point in the history
  • Loading branch information
pankaj-bind committed Jun 2, 2024
1 parent 49276ec commit a5c7418
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/components/pages/auth/register/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,29 @@ export default function RegisterComponent() {
});
}

async function submitHander(event: React.FormEvent<HTMLFormElement>) {
async function checkEmail(email: string): Promise<boolean> {
try {
const response = await fetch(`https://disposable.debounce.io/?email=${email}`);
const data = await response.json();
if (data.disposable === "true") {
alert("Disposable email");
return false;
}
alert("Email is genuine");
return true;
} catch (error) {
console.error('Error:', error);
alert("An error occurred while checking the email.");
return false;
}
}

async function submitHandler(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();

const isGenuineEmail = await checkEmail(data.email);
if (!isGenuineEmail) return;

try {
setIsLoading(true);

Expand All @@ -54,7 +74,7 @@ export default function RegisterComponent() {
}

if (data.password !== data.confirmpassword) {
throw new Error("Password and Confirm Password does not match");
throw new Error("Password and Confirm Password do not match");
}

if (data.password.length < 6 || data.password.length > 24) {
Expand All @@ -66,7 +86,7 @@ export default function RegisterComponent() {
}

if (!passwordRegex.test(data.password)) {
throw new Error("password format not matched");
throw new Error("Password format not matched");
}

const resp: Models.Document = await register(data);
Expand Down Expand Up @@ -134,7 +154,7 @@ export default function RegisterComponent() {
</motion.p>
</article>

<form method="POST" onSubmit={submitHander}>
<form method="POST" onSubmit={submitHandler}>
<motion.div
initial={{ opacity: 0, x: -50 }}
whileInView={{ opacity: 1, x: 0 }}
Expand Down

0 comments on commit a5c7418

Please sign in to comment.