Skip to content

Commit fe287dc

Browse files
committed
Show error on duplicate user registration
1 parent 2eb49fe commit fe287dc

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

peerprep/app/actions/server_actions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ export async function signup(state: FormState, formData: FormData) {
3636
redirect("/auth/login");
3737
} else {
3838
// TODO: handle failure codes: 400, 409, 500.
39-
console.log(`${json.status}: ${json.error}`);
39+
console.log(`Error in signup: ${json.status}: ${json.error}`);
40+
return {
41+
errors: {
42+
username: ["Username is already in use."],
43+
email: ["Email is already in use."],
44+
},
45+
};
4046
}
4147
}
4248

peerprep/app/auth/register/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ function RegisterPage() {
2020
)}
2121
<FormTextInput required label="Email:" name="email" />
2222
{state?.errors?.email && (
23-
<p className={style.error}>{state.errors.email}</p>
23+
<p className={style.error}>
24+
{state.errors.email.map((item) => (
25+
<div key={item}>{item}</div>
26+
))}
27+
</p>
2428
)}
2529
<FormTextInput
2630
required

0 commit comments

Comments
 (0)