Skip to content

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

feat(auth): improve auth error messages and logging

Marc Klingenc2515f7e6a05
diff --git a/web/src/features/auth/lib/emailPassword.ts b/web/src/features/auth/lib/emailPassword.ts
index d10f9e384a..f66f055e2f 100644
--- a/web/src/features/auth/lib/emailPassword.ts
+++ b/web/src/features/auth/lib/emailPassword.ts
@@ -27,7 +27,11 @@ export async function createUserEmailPassword(
},
});
if (user !== null) {
- throw new Error("User with email already exists. Please sign in.");
+ throw new Error(
+ user.password !== null
+ ? "User with email already exists. Please sign in."
+ : "You have already signed up via an identity provider. Please sign in.",
+ );
}
const newUser = await prisma.user.create({
diff --git a/web/src/pages/auth/sign-in.tsx b/web/src/pages/auth/sign-in.tsx
index bb318d8c64..873bb514f4 100644
--- a/web/src/pages/auth/sign-in.tsx
+++ b/web/src/pages/auth/sign-in.tsx
@@ -234,19 +234,31 @@ export default function SignIn({ authProviders, signUpDisabled }: PageProps) {
redirect: false,
turnstileToken,
});
- if (result?.error) {
- setCredentialsFormError(result.error);
-
- // Refresh turnstile as the token can only be used once
- if (env.NEXT_PUBLIC_TURNSTILE_SITE_KEY && turnstileToken) {
- setTurnstileCData(new Date().getTime().toString());
- setTurnstileToken(undefined);
+ if (result === undefined) {
+ setCredentialsFormError("An unexpected error occurred.");
+ captureException(new Error("Sign in result is undefined"));
+ } else if (!result.ok) {
+ if (!result.error) {
+ captureException(
+ new Error(
+ `Sign in result error is falsy, result: ${JSON.stringify(result)}`,
+ ),
+ );
}
+ setCredentialsFormError(
+ result?.error ?? "An unexpected error occurred.",
+ );
}
} catch (error) {
captureException(error);
console.error(error);
setCredentialsFormError("An unexpected error occurred.");
+ } finally {
+ // Refresh turnstile as the token can only be used once
+ if (env.NEXT_PUBLIC_TURNSTILE_SITE_KEY && turnstileToken) {
+ setTurnstileCData(new Date().getTime().toString());
+ setTurnstileToken(undefined);
+ }
}
}
diff --git a/web/src/server/auth.ts b/web/src/server/auth.ts
index 64541b10b3..e08d19dab7 100644
--- a/web/src/server/auth.ts
+++ b/web/src/server/auth.ts
@@ -90,7 +90,10 @@ const staticProviders: Provider[] = [
});
if (!dbUser) throw new Error("Invalid credentials");
- if (dbUser.password === null) throw new Error("Invalid credentials");
+ if (dbUser.password === null)
+ throw new Error(
+ "Please sign in with the identity provider that is linked to your account.",
+ );
const isValidPassword = await verifyPassword(
credentials.password,