diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f95f237d..fc9c3e3e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - [EE] Fixed missing account-linking prompts during OAuth authorization and restored prompts when new optional providers are configured. [#1663](https://github.com/sourcebot-dev/sourcebot/pull/1663) - Prevented browser performance instrumentation from breaking code views when `performance.measure()` returns no value. [#1665](https://github.com/sourcebot-dev/sourcebot/pull/1665) +- Added specific authentication error messages and recovery guidance shared by the login form and error page. [#1669](https://github.com/sourcebot-dev/sourcebot/pull/1669) ## [5.1.13] - 2026-09-12 diff --git a/packages/web/src/app/login/components/loginForm.tsx b/packages/web/src/app/login/components/loginForm.tsx index 23d289520..e1d41ecf1 100644 --- a/packages/web/src/app/login/components/loginForm.tsx +++ b/packages/web/src/app/login/components/loginForm.tsx @@ -8,6 +8,7 @@ import useCaptureEvent from "@/hooks/useCaptureEvent"; import { useIdentityProviders } from "@/features/auth/useIdentityProviders"; import Link from "next/link"; import { LoginMessage } from "@/features/auth/components/loginMessage"; +import { getAuthErrorContent } from "@/features/auth/errorMessages"; interface LoginFormProps { callbackUrl?: string; @@ -31,19 +32,7 @@ export const LoginForm = ({ callbackUrl, error, context, isAnonymousAccessEnable return "/"; }, [callbackUrl]); - const errorMessage = useMemo(() => { - if (!error) { - return ""; - } - switch (error) { - case "CredentialsSignin": - return "Invalid email or password. Please try again."; - case "OAuthAccountNotLinked": - return "This email is already associated with a different sign-in method."; - default: - return "An error occurred during authentication. Please try again."; - } - }, [error]); + const errorMessage = getAuthErrorContent(error).description; // Helper function to get the correct analytics event name based on provider type. const getLoginEventName = (providerType: string) => { diff --git a/packages/web/src/app/login/error/page.tsx b/packages/web/src/app/login/error/page.tsx index 333c0c025..dbb9eec1f 100644 --- a/packages/web/src/app/login/error/page.tsx +++ b/packages/web/src/app/login/error/page.tsx @@ -9,35 +9,11 @@ import Link from "next/link" import { SourcebotLogo } from "@/app/components/sourcebotLogo" import { Footer } from "@/app/components/footer" import { SOURCEBOT_SUPPORT_EMAIL } from "@/lib/constants" - -// @see https://authjs.dev/guides/pages/error -const ERROR_CONTENT: Record = { - Configuration: { - title: "Server configuration error", - description: "There is a problem with the server's authentication configuration. Please contact your administrator.", - }, - AccessDenied: { - title: "Access denied", - description: "You do not have permission to sign in.", - }, - EmailRequired: { - title: "No email on your account", - description: "Your identity provider didn't share an email address, which Sourcebot requires to sign you in. Add or verify an email on your upstream account, then try again.", - }, - Verification: { - title: "This sign-in link has expired", - description: "The code or link you used is no longer valid - it may have expired or already been used. Request a new one and try again.", - }, - Default: { - title: "Unable to sign in", - description: "Something went wrong while signing you in. Please try again.", - }, -} +import { getAuthErrorContent } from "@/features/auth/errorMessages" function ErrorPageContent() { const searchParams = useSearchParams() - const error = searchParams.get("error") ?? "Default" - const { title, description } = ERROR_CONTENT[error] ?? ERROR_CONTENT.Default + const { title, description } = getAuthErrorContent(searchParams.get("error")) return (
diff --git a/packages/web/src/features/auth/errorMessages.ts b/packages/web/src/features/auth/errorMessages.ts new file mode 100644 index 000000000..6e2bf4c3d --- /dev/null +++ b/packages/web/src/features/auth/errorMessages.ts @@ -0,0 +1,49 @@ +const ERROR_CONTENT: Record = { + CredentialsSignin: { + title: "Unable to sign in", + description: "Invalid email or password. Please try again.", + }, + OAuthAccountNotLinked: { + title: "Different sign-in method required", + description: "This email is already associated with a different sign-in method.", + }, + OAuthCallbackError: { + title: "Provider sign-in failed", + description: "Sign-in with your identity provider was cancelled or could not be completed. Please try again. If this continues, contact your administrator.", + }, + MissingCSRF: { + title: "Sign-in security check failed", + description: "We couldn't verify your sign-in request. Refresh the page and try again.", + }, + AccountNotLinked: { + title: "Account not linked", + description: "This account isn't linked to your Sourcebot user. Sign in using your original method, then link the account in Settings.", + }, + WebAuthnVerificationError: { + title: "Passkey verification failed", + description: "We couldn't verify your passkey. Please try again or use another available sign-in method.", + }, + Configuration: { + title: "Server configuration error", + description: "There is a problem with the server's authentication configuration. Please contact your administrator.", + }, + AccessDenied: { + title: "Access denied", + description: "You do not have permission to sign in.", + }, + EmailRequired: { + title: "No email on your account", + description: "Your identity provider didn't share an email address, which Sourcebot requires to sign you in. Add or verify an email on your upstream account, then try again.", + }, + Verification: { + title: "This sign-in link has expired", + description: "The code or link you used is no longer valid - it may have expired or already been used. Request a new one and try again.", + }, + Default: { + title: "Unable to sign in", + description: "An error occurred during authentication. Please try again.", + }, +}; + +export const getAuthErrorContent = (error: string | null | undefined) => + error && Object.hasOwn(ERROR_CONTENT, error) ? ERROR_CONTENT[error] : ERROR_CONTENT.Default;