Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

Sign-up errors: UI and logs (#97)

Marc Klingena5ab24fa4fa2
diff --git a/src/features/auth/lib/emailPassword.ts b/src/features/auth/lib/emailPassword.ts
index 280f16980b..21f3dc884b 100644
--- a/src/features/auth/lib/emailPassword.ts
+++ b/src/features/auth/lib/emailPassword.ts
@@ -16,7 +16,8 @@ export async function createUserEmailPassword(
password: string,
name: string
) {
- if (!isValidPassword(password)) throw new Error("Invalid password");
+ if (!isValidPassword(password))
+ throw new Error("Password needs to be at least 8 characters long.");
const hashedPassword = await hashPassword(password);
// check that no user exists with this email
@@ -26,7 +27,7 @@ export async function createUserEmailPassword(
},
});
if (user !== null) {
- throw new Error("User already exists");
+ throw new Error("User with email already exists. Please sign in.");
}
// set demoProjectId if env exists and project exists in db
diff --git a/src/pages/api/auth/signup.ts b/src/pages/api/auth/signup.ts
index d1f1ea77a9..96af540873 100644
--- a/src/pages/api/auth/signup.ts
+++ b/src/pages/api/auth/signup.ts
@@ -11,6 +11,7 @@ export default async function handler(
// parse and type check the request body with zod
const validBody = signupSchema.safeParse(req.body);
if (!validBody.success) {
+ console.log("Signup: Invalid body", validBody.error);
res.status(422).json({ message: validBody.error });
return;
}
@@ -21,8 +22,15 @@ export default async function handler(
try {
await createUserEmailPassword(body.email, body.password, body.name);
} catch (error) {
- if (error instanceof Error)
+ if (error instanceof Error) {
+ console.log(
+ "Signup: Error creating user",
+ error.message,
+ body.email,
+ body.name
+ );
res.status(422).json({ message: error.message });
+ }
return;
}
diff --git a/src/pages/auth/sign-up.tsx b/src/pages/auth/sign-up.tsx
index c76e051286..358e332ed6 100644
--- a/src/pages/auth/sign-up.tsx
+++ b/src/pages/auth/sign-up.tsx
@@ -16,8 +16,10 @@ import Link from "next/link";
import { useForm } from "react-hook-form";
import type * as z from "zod";
import { env } from "@/src/env.mjs";
+import { useState } from "react";
export default function SignIn() {
+ const [formError, setFormError] = useState<string | null>(null);
const form = useForm<z.infer<typeof signupSchema>>({
resolver: zodResolver(signupSchema),
defaultValues: {
@@ -29,6 +31,7 @@ export default function SignIn() {
async function onSubmit(values: z.infer<typeof signupSchema>) {
try {
+ setFormError(null);
const res = await fetch("/api/auth/signup", {
method: "POST",
headers: { "Content-Type": "application/json" },
@@ -37,7 +40,8 @@ export default function SignIn() {
if (!res.ok) {
const payload = (await res.json()) as { message: string };
- throw new Error(payload.message);
+ setFormError(payload.message);
+ return;
}
await signIn<"credentials">("credentials", {
@@ -46,9 +50,7 @@ export default function SignIn() {
callbackUrl: "/?getStarted=1",
});
} catch (err) {
- form.setError("root", {
- message: (err as { message: string }).message,
- });
+ setFormError("An error occurred. Please try again.");
}
}
@@ -131,6 +133,11 @@ export default function SignIn() {
>
Sign up
</Button>
+ {formError ? (
+ <div className="text-center text-sm text-red-500">
+ {formError}
+ </div>
+ ) : null}
</form>
</Form>
{env.NEXT_PUBLIC_HOSTNAME === "cloud.langfuse.com" ? (