Skip to content

Commit

Permalink
Fix error handling signup page
Browse files Browse the repository at this point in the history
  • Loading branch information
atrincas authored and agnlez committed Nov 18, 2024
1 parent c67b6a3 commit 3158e8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions client/src/containers/auth/signup/form/action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use server";

import { headers } from "next/headers";

import { CreateUserSchema } from "@shared/schemas/users/create-user.schema";

import { client } from "@/lib/query-client";
Expand All @@ -24,9 +26,11 @@ export async function signUpAction(
}

try {
const headersList = headers();
const response = await client.auth.register.mutation({
extraHeaders: {
Authorization: `Bearer ${data.get("token")}`,
origin: headersList.get("host") || undefined,
},
body: {
name: parsed.data.name,
Expand All @@ -35,11 +39,12 @@ export async function signUpAction(
},
});

if (response.status === 401) {
if (response.status !== 201) {
return {
ok: false,
message:
response.body.errors?.map(({ title }) => title) ?? "unknown error",
response.body.errors?.map(({ title }) => title).join("\n") ??
"unknown error",
};
}
} catch (error: Error | unknown) {
Expand Down
3 changes: 3 additions & 0 deletions client/src/containers/auth/signup/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ const TokenSignUpForm: FC = () => {
)}
/>

{!status.ok && status.message && (
<div className="text-center text-destructive">{status.message}</div>
)}
<div className="flex justify-end gap-2">
<Button variant="outline" asChild>
<Link href="/auth/signin">Cancel</Link>
Expand Down

0 comments on commit 3158e8c

Please sign in to comment.