Skip to content
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

Closed
wants to merge 1 commit into from
Closed
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
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;
}
}
Comment on lines +46 to +61
Copy link
Contributor

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.

- console.error('Error:', error);
+ console.error('checkEmail error:', error);

Committable suggestion was skipped due low confidence.


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

const isGenuineEmail = await checkEmail(data.email);
if (!isGenuineEmail) return;
Comment on lines +66 to +67
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The submitHandler function in src/components/pages/auth/register/index.tsx does not provide any user feedback when the email is not genuine. It simply returns without any notification to the user.

  • Lines 66-67: const isGenuineEmail = await checkEmail(data.email); if (!isGenuineEmail) return;

Consider adding user feedback to inform the user why the registration process is halted.

Analysis chain

Verify the logic flow in submitHandler.

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 executed

The 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);

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");
Copy link
Contributor

Choose a reason for hiding this comment

The 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 submitHandler function could be more descriptive and consistent. This will help users understand exactly what they need to correct in their input.

- 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

Committable suggestion was skipped due low confidence.

}

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
Loading