Skip to content

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

feat(ui): render errors on sign in page and log unknown to sentry (#1767)

Marc Klingen862a1395d523
diff --git a/web/src/pages/auth/sign-in.tsx b/web/src/pages/auth/sign-in.tsx
index b0af3cc679..508bb32fa3 100644
--- a/web/src/pages/auth/sign-in.tsx
+++ b/web/src/pages/auth/sign-in.tsx
@@ -19,7 +19,7 @@ import { TbBrandAzure } from "react-icons/tb";
import { signIn } from "next-auth/react";
import Head from "next/head";
import Link from "next/link";
-import { useState } from "react";
+import { useState, useEffect } from "react";
import { useForm } from "react-hook-form";
import * as z from "zod";
import { usePostHog } from "posthog-js/react";
@@ -30,6 +30,8 @@ import { PasswordInput } from "@/src/components/ui/password-input";
import { Turnstile } from "@marsidev/react-turnstile";
import { isAnySsoConfigured } from "@langfuse/ee/sso";
import { Shield } from "lucide-react";
+import { useRouter } from "next/router";
+import { captureException } from "@sentry/nextjs";
const credentialAuthForm = z.object({
email: z.string().email(),
@@ -169,10 +171,35 @@ export function SSOButtons({
);
}
+const signInErrors = [
+ {
+ code: "OAuthAccountNotLinked",
+ description:
+ "Please sign in with the same provider that you used to create this account.",
+ },
+];
+
export default function SignIn({ authProviders, signUpDisabled }: PageProps) {
+ const router = useRouter();
+
+ // handle NextAuth error codes: https://next-auth.js.org/configuration/pages#sign-in-page
+ const nextAuthError =
+ typeof router.query.error === "string"
+ ? decodeURIComponent(router.query.error)
+ : null;
+ const nextAuthErrorDescription = signInErrors.find(
+ (e) => e.code === nextAuthError,
+ )?.description;
+ useEffect(() => {
+ // log unexpected sign in errors to Sentry
+ if (nextAuthError && !nextAuthErrorDescription) {
+ captureException(new Error(`Sign in error: ${nextAuthError}`));
+ }
+ }, [nextAuthError, nextAuthErrorDescription]);
+
const [credentialsFormError, setCredentialsFormError] = useState<
string | null
- >(null);
+ >(nextAuthErrorDescription ?? nextAuthError);
const [ssoLoading, setSsoLoading] = useState<boolean>(false);
const posthog = usePostHog();