-
Notifications
You must be signed in to change notification settings - Fork 1
Fix account creation bug on login page #3
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
base: main
Are you sure you want to change the base?
Fix account creation bug on login page #3
Conversation
Co-authored-by: salwansandeep5 <[email protected]>
|
Cursor Agent can help with this pull request. Just |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Pull Request Overview
This PR fixes account creation bugs on the login page by implementing proper duplicate email validation and improving async error handling. The changes prevent users from creating duplicate accounts and provide better feedback during the registration process.
Key changes:
- Added server-side duplicate email validation with proper error responses
- Converted form submission to async/await pattern for better error handling
- Implemented specific error messages for different failure scenarios
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| app/api/register/route.ts | Added duplicate email checks and Prisma race condition handling |
| app/(site)/components/AuthForm.tsx | Converted to async form submission with improved error handling and user feedback |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
app/(site)/components/AuthForm.tsx
Outdated
| if (err?.response?.status === 409) { | ||
| toast.error("Email already registered"); | ||
| } else if (err?.response?.data) { | ||
| toast.error(typeof err.response.data === 'string' ? err.response.data : 'Registration failed'); |
Copilot
AI
Sep 17, 2025
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.
The error handling logic for err.response.data is overly complex. Consider simplifying this by either extracting the error message consistently or using a more straightforward fallback approach.
| toast.error(typeof err.response.data === 'string' ? err.response.data : 'Registration failed'); | |
| const errorMessage = | |
| typeof err.response.data === 'string' | |
| ? err.response.data | |
| : err.response.data.message | |
| ? err.response.data.message | |
| : 'Registration failed'; | |
| toast.error(errorMessage); |
app/(site)/components/AuthForm.tsx
Outdated
| const callback = await signIn("credentials", { | ||
| email: data.email, | ||
| password: data.password, | ||
| redirect: false, | ||
| }); | ||
|
|
||
| if (callback?.error) { | ||
| toast.error("Invalid credentials!"); | ||
| } | ||
| if (callback?.ok && !callback?.error) { | ||
| toast.success("Logged in!"); | ||
| router.push("/users"); | ||
| } | ||
| setIsLoading(false); |
Copilot
AI
Sep 17, 2025
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.
The setIsLoading(false) call is duplicated across both REGISTER and LOGIN branches. Consider moving this to a single location or using a try/finally block to ensure it's always called.
|
@cursoragent @cursor it doesn't work it just says error while creating user when I try making an account test driven development you check what's going on fix where's the error also |
|
I significantly enhanced the robustness of user authentication and registration. This involved improving client-side error message display, ensuring consistent loading state management, and implementing comprehensive server-side input validation and error handling for the registration API, including specific Prisma error detection and detailed logging. I also fixed a critical typo in the bcrypt import.
2 tasks completed
Learn more about Cursor Agents |
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.
This PR is being reviewed by Cursor Bugbot
Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| } | ||
| setIsLoading(false); | ||
| return; | ||
| } |
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.
Bug: Login Flow Fails to Reset Loading State
The LOGIN flow's signIn call lacks try-catch error handling. If signIn throws an exception, setIsLoading(false) isn't reached, leaving the form stuck in a loading state. This differs from the REGISTER flow, which correctly uses finally to reset the loading state.
Co-authored-by: salwansandeep5 <[email protected]>
|
@cursor it still says error while registering user when making an account fix |
|
I enhanced the application's database error handling to provide more specific diagnostics and hints for common issues like connection failures or unapplied migrations. I also updated the build process to ensure database migrations are always deployed before the application build.
Learn more about Cursor Agents |
Co-authored-by: salwansandeep5 <[email protected]>
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.
2 issues found across 2 files
Prompt for AI agents (all 2 issues)
Understand the root cause of the following 2 issues and fix them.
<file name="app/(site)/components/AuthForm.tsx">
<violation number="1" location="app/(site)/components/AuthForm.tsx:61">
Ensure the LOGIN signIn call is wrapped in a try/finally (or handles rejection) so setIsLoading(false) always runs; otherwise a thrown error will leave the form stuck in a loading state.</violation>
<violation number="2" location="app/(site)/components/AuthForm.tsx:77">
Avoid displaying raw server error messages to users; show a generic message instead to prevent leaking internal details.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
app/(site)/components/AuthForm.tsx
Outdated
| if (err?.response?.status === 409) { | ||
| toast.error("Email already registered"); | ||
| } else if (err?.response?.data) { | ||
| toast.error(typeof err.response.data === 'string' ? err.response.data : 'Registration failed'); |
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.
Avoid displaying raw server error messages to users; show a generic message instead to prevent leaking internal details.
Prompt for AI agents
Address the following comment on app/(site)/components/AuthForm.tsx at line 77:
<comment>Avoid displaying raw server error messages to users; show a generic message instead to prevent leaking internal details.</comment>
<file context>
@@ -56,33 +56,51 @@ const AuthForm = () => {
+ if (err?.response?.status === 409) {
+ toast.error("Email already registered");
+ } else if (err?.response?.data) {
+ toast.error(typeof err.response.data === 'string' ? err.response.data : 'Registration failed');
+ } else {
+ toast.error("Something went wrong!");
</file context>
| toast.error(typeof err.response.data === 'string' ? err.response.data : 'Registration failed'); | |
| toast.error("Registration failed"); |
| toast.error("Something went wrong!"); | ||
| try { | ||
| await axios.post("/api/register", data); | ||
| const callback = await signIn("credentials", { |
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.
Ensure the LOGIN signIn call is wrapped in a try/finally (or handles rejection) so setIsLoading(false) always runs; otherwise a thrown error will leave the form stuck in a loading state.
Prompt for AI agents
Address the following comment on app/(site)/components/AuthForm.tsx at line 61:
<comment>Ensure the LOGIN signIn call is wrapped in a try/finally (or handles rejection) so setIsLoading(false) always runs; otherwise a thrown error will leave the form stuck in a loading state.</comment>
<file context>
@@ -56,33 +56,51 @@ const AuthForm = () => {
- toast.error("Something went wrong!");
+ try {
+ await axios.post("/api/register", data);
+ const callback = await signIn("credentials", {
+ email: data.email,
+ password: data.password,
</file context>
Co-authored-by: salwansandeep5 <[email protected]>
|
@cursor (index):1 Unchecked runtime.lastError: The message port closed before a response was received.Understand this error (anonymous) @ content.06af5f40.js:9Understand this error |
|
I've analyzed the console errors you provided and here's a breakdown of what's happening and how to fix your registration issue: First, many of the errors you're seeing (like The critical errors are:
To fix this, I've outlined a step-by-step process:
If you're still stuck, you can provide me with your deployment URL and a sanitized Learn more about Cursor Agents |
Fix user registration by adding server-side duplicate email checks and improving client-side async handling and error feedback.
Summary by cubic
Fixes account creation on the login page by blocking duplicate emails on the server and improving the form’s async flow and error handling. Users now get clear feedback, and successful register/login redirects to /users without flaky states.