-
-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Filter genuine email added #351
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
Comment on lines
+66
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification The
Consider adding user feedback to inform the user why the registration process is halted. Analysis chainVerify the logic flow in The current implementation returns immediately if the email is not genuine, without providing any feedback to the user. It might be beneficial to inform the user why the registration process is halted. Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify the user feedback mechanism when an email is not genuine.
# Test: Search for user feedback related code. Expect: User feedback implementation when email is not genuine.
rg --type typescript $'if \(!isGenuineEmail\) return;'
Length of output: 90 Script: #!/bin/bash
# Description: Verify the user feedback mechanism when an email is not genuine.
# Test: Search for user feedback related code. Expect: User feedback implementation when email is not genuine.
rg --type ts $'if (!isGenuineEmail) return;'
Length of output: 45 Script: #!/bin/bash
# Description: Locate the `submitHandler` function and inspect its implementation for user feedback mechanisms.
# Step 1: Locate the `submitHandler` function in the codebase.
ast-grep --lang typescript --pattern 'function submitHandler($_) { $$$ }' --json
Length of output: 85 Script: #!/bin/bash
# Description: Search for the `submitHandler` function definition and its usage in the codebase.
# Step 1: Search for the `submitHandler` function definition.
rg 'function submitHandler' --type ts
# Step 2: Search for the `submitHandler` function usage.
rg 'submitHandler' --type ts
Length of output: 407 Script: #!/bin/bash
# Description: Extract the implementation of the `submitHandler` function from `src/components/pages/auth/register/index.tsx`.
# Step 1: Extract the `submitHandler` function implementation.
ast-grep --lang typescript --pattern 'async function submitHandler($_) { $$$ }' src/components/pages/auth/register/index.tsx
Length of output: 4656 |
||
|
||
try { | ||
setIsLoading(true); | ||
|
||
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor error messages for better clarity and consistency. The error messages thrown in the - throw new Error("Password and Confirm Password do not match");
+ throw new Error("The passwords entered do not match. Please try again.");
- throw new Error("Password format not matched");
+ throw new Error("Password format is incorrect. Ensure it includes a character, a number, and a special character."); Also applies to: 89-89
|
||
} | ||
|
||
if (data.password.length < 6 || data.password.length > 24) { | ||
|
@@ -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); | ||
|
@@ -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 }} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement error handling improvements in
checkEmail
.The
checkEmail
function currently uses a generic alert for error handling which might not be the best user experience. Consider using a more user-friendly approach, such as displaying the error message within the UI instead of using browser alerts. Additionally, the error logging could be more descriptive.