-
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?
Changes from 1 commit
41b17a1
db2cf0a
ce63710
2d5b6fc
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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -47,7 +47,7 @@ const AuthForm = () => { | |||||||||||||||||||||
| }, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const onSubmit: SubmitHandler<FieldValues> = (data) => { | ||||||||||||||||||||||
| const onSubmit: SubmitHandler<FieldValues> = async (data) => { | ||||||||||||||||||||||
| setIsLoading(true); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (!data) { | ||||||||||||||||||||||
|
|
@@ -56,33 +56,51 @@ const AuthForm = () => { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (variant === "REGISTER") { | ||||||||||||||||||||||
| axios | ||||||||||||||||||||||
| .post("/api/register", data) | ||||||||||||||||||||||
| .then(() => { | ||||||||||||||||||||||
| signIn("credentials", data); | ||||||||||||||||||||||
| }) | ||||||||||||||||||||||
| .catch((err) => { | ||||||||||||||||||||||
| console.log(err); | ||||||||||||||||||||||
| toast.error("Something went wrong!"); | ||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| await axios.post("/api/register", data); | ||||||||||||||||||||||
| const callback = await signIn("credentials", { | ||||||||||||||||||||||
| email: data.email, | ||||||||||||||||||||||
| password: data.password, | ||||||||||||||||||||||
| redirect: false, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (variant === "LOGIN") { | ||||||||||||||||||||||
| signIn("credentials", { | ||||||||||||||||||||||
| ...data, | ||||||||||||||||||||||
| redirect: false, | ||||||||||||||||||||||
| }).then((callback) => { | ||||||||||||||||||||||
| if (callback?.error) { | ||||||||||||||||||||||
| toast.error("Invalid credentials!"); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| if (callback?.ok && !callback?.error) { | ||||||||||||||||||||||
| toast.success("Logged in!"); | ||||||||||||||||||||||
| toast.error(callback.error || "Invalid credentials!"); | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| toast.success("Account created!"); | ||||||||||||||||||||||
| router.push("/users"); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| } catch (err: any) { | ||||||||||||||||||||||
| 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'); | ||||||||||||||||||||||
|
||||||||||||||||||||||
| 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); |
Outdated
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"); |
Outdated
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.
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.
Uh oh!
There was an error while loading. Please reload this page.
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