🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(ui): improve password-reset UX (#2350)
Marc Klingen42e446ed550f
diff --git a/web/src/components/error-page.tsx b/web/src/components/error-page.tsxindex f42721f715..1162f33364 100644--- a/web/src/components/error-page.tsx+++ b/web/src/components/error-page.tsx@@ -4,13 +4,19 @@ import { useSession } from "next-auth/react";import { useRouter } from "next/router";import { captureException } from "@sentry/nextjs";import { useEffect } from "react";+import Link from "next/link";export const ErrorPage = ({title = "Error",message,+ additionalButton,}: {title?: string;message: string;+ additionalButton?: {+ label: string;+ href: string;+ };}) => {const session = useSession();const router = useRouter();@@ -18,20 +24,27 @@ export const ErrorPage = ({return (<div className="flex h-screen flex-col items-center justify-center">- <AlertCircle className="text-dark-red mb-4 h-12 w-12" />+ <AlertCircle className="mb-4 h-12 w-12 text-dark-red" /><h1 className="mb-4 text-xl font-bold">{title}</h1>- <p className="mb-8 text-center">{message}</p>- {session.status === "unauthenticated" ? (- <Button- onClick={() =>- void router.push(- `/auth/sign-in?targetPath=${encodeURIComponent(newTargetPath)}`,- )- }- >- Sign In- </Button>- ) : null}+ <p className="mb-6 text-center">{message}</p>+ <div className="flex gap-3">+ {session.status === "unauthenticated" ? (+ <Button+ onClick={() =>+ void router.push(+ `/auth/sign-in?targetPath=${encodeURIComponent(newTargetPath)}`,+ )+ }+ >+ Sign In+ </Button>+ ) : null}+ {additionalButton ? (+ <Button variant="secondary" asChild>+ <Link href={additionalButton.href}>{additionalButton.label}</Link>+ </Button>+ ) : null}+ </div></div>);};diff --git a/web/src/components/layouts/layout.tsx b/web/src/components/layouts/layout.tsxindex 06de845eef..a622babf8a 100644--- a/web/src/components/layouts/layout.tsx+++ b/web/src/components/layouts/layout.tsx@@ -64,9 +64,11 @@ const unauthenticatedPaths: string[] = ["/auth/sign-up","/auth/error",];+// auth or unauthedconst publishablePaths: string[] = ["/project/[projectId]/sessions/[sessionId]","/project/[projectId]/traces/[traceId]",+ "/auth/reset-password",];export default function Layout(props: PropsWithChildren) {diff --git a/web/src/features/auth-credentials/components/ResetPasswordButton.tsx b/web/src/features/auth-credentials/components/ResetPasswordButton.tsxindex 3d0ac002e5..a084dc7d1f 100644--- a/web/src/features/auth-credentials/components/ResetPasswordButton.tsx+++ b/web/src/features/auth-credentials/components/ResetPasswordButton.tsx@@ -1,6 +1,8 @@import { signIn, useSession } from "next-auth/react";import { Button } from "@/src/components/ui/button";-import { useState } from "react";+import { useEffect, useState } from "react";+import { z } from "zod";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";export function RequestResetPasswordEmailButton({email,@@ -13,9 +15,18 @@ export function RequestResetPasswordEmailButton({}) {const [isEmailSent, setIsEmailSent] = useState(false);const [isLoading, setIsLoading] = useState(false);+ const [isValidEmail, setIsValidEmail] = useState(false);const session = useSession();+ const capture = usePostHogClientCapture();++ useEffect(() => {+ const isValidEmail = z.string().email().safeParse(email).success;+ setIsValidEmail(isValidEmail);+ }, [email]);const handleResetPassword = async () => {+ if (!isValidEmail) return;+ capture("auth:reset_password_email_requested");setIsLoading(true);try {await signIn("email", {@@ -36,7 +47,7 @@ export function RequestResetPasswordEmailButton({onClick={handleResetPassword}className={className}loading={isLoading}- disabled={isEmailSent}+ disabled={isEmailSent || !isValidEmail}variant={variant}>{isEmailSentdiff --git a/web/src/features/auth-credentials/components/ResetPasswordPage.tsx b/web/src/features/auth-credentials/components/ResetPasswordPage.tsxindex 723401c5f3..8cd09acbdd 100644--- a/web/src/features/auth-credentials/components/ResetPasswordPage.tsx+++ b/web/src/features/auth-credentials/components/ResetPasswordPage.tsx@@ -22,6 +22,9 @@ import { useRouter } from "next/router";import { RequestResetPasswordEmailButton } from "@/src/features/auth-credentials/components/ResetPasswordButton";import { TRPCClientError } from "@trpc/client";import { isEmailVerifiedWithinCutoff } from "@/src/features/auth-credentials/lib/credentialsUtils";+import Link from "next/link";+import { ErrorPage } from "@/src/components/error-page";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";const resetPasswordSchema = z.object({@@ -38,7 +41,11 @@ const resetPasswordSchema = zpath: ["confirmPassword"],});-export function ResetPasswordPage() {+export function ResetPasswordPage({+ passwordResetAvailable,+}: {+ passwordResetAvailable: boolean;+}) {const session = useSession();const router = useRouter();const [formError, setFormError] = useState<string | null>(null);@@ -46,6 +53,8 @@ export function ResetPasswordPage() {const [showResetPasswordEmailButton, setShowResetPasswordEmailButton] =useState(false);+ const capture = usePostHogClientCapture();+const mutResetPassword = api.credentials.resetPassword.useMutation();const emailVerified = isEmailVerifiedWithinCutoff(session.data?.user?.emailVerified,@@ -64,6 +73,7 @@ export function ResetPasswordPage() {setFormError(null);setShowResetPasswordEmailButton(false);setIsSuccess(false);+ capture("auth:update_password_form_submit");await mutResetPassword.mutateAsync({ password: values.password }).then(() => {@@ -87,6 +97,18 @@ export function ResetPasswordPage() {});}+ if (!passwordResetAvailable)+ return (+ <ErrorPage+ title="Not available"+ message="Password reset is not configured on this instance"+ additionalButton={{+ label: "Setup instructions",+ href: "https://langfuse.com/docs/deployment/self-host#emailpassword",+ }}+ />+ );+return (<><Head>@@ -94,7 +116,9 @@ export function ResetPasswordPage() {</Head><div className="flex flex-1 flex-col py-6 sm:min-h-full sm:justify-center sm:px-6 sm:py-12 lg:px-8"><div className="sm:mx-auto sm:w-full sm:max-w-md">- <LangfuseIcon className="mx-auto" />+ <Link href="/">+ <LangfuseIcon className="mx-auto" />+ </Link><h2 className="mt-4 text-center text-2xl font-bold leading-9 tracking-tight text-primary">Reset your password</h2>@@ -118,7 +142,7 @@ export function ResetPasswordPage() {<div className="relative"><Inputplaceholder="[email protected]"- disabled+ disabled={session.status === "authenticated"}{...field}/>{emailVerified.verified && (@@ -177,7 +201,7 @@ export function ResetPasswordPage() {</Button>) : (<RequestResetPasswordEmailButton- email={form.getValues("email")}+ email={form.watch("email")}className="w-full"/>)}@@ -202,6 +226,17 @@ export function ResetPasswordPage() {)}</div></div>+ {session.status !== "authenticated" && (+ <div className="mx-auto mt-10 max-w-lg text-center text-xs text-muted-foreground">+ You will only receive an email if an account with this email exists+ and you have signed up with email and password. If you used an+ authentication provider like Google, Okta, or GitHub, please{" "}+ <Link href="/auth/sign-in" className="underline">+ sign in+ </Link>+ .+ </div>+ )}</div></>);diff --git a/web/src/features/auth/components/AuthCloudRegionSwitch.tsx b/web/src/features/auth/components/AuthCloudRegionSwitch.tsxindex be5dffd06e..a3eb51fd69 100644--- a/web/src/features/auth/components/AuthCloudRegionSwitch.tsx+++ b/web/src/features/auth/components/AuthCloudRegionSwitch.tsx@@ -60,7 +60,7 @@ export function CloudRegionSwitch({return (<div>- <div className="mb-6 flex w-full flex-col gap-3">+ <div className="mb-6 flex w-full flex-col gap-2"><div><span className="text-sm font-medium leading-none">Data Region@@ -113,7 +113,7 @@ const DataRegionInfo = () => (<DialogTrigger asChild><ahref="#"- className="hover:text-hover-primary-accent ml-1 text-xs text-primary-accent"+ className="ml-1 text-xs text-primary-accent hover:text-hover-primary-accent"title="What is this?">(what is this?)diff --git a/web/src/features/posthog-analytics/usePostHogClientCapture.ts b/web/src/features/posthog-analytics/usePostHogClientCapture.tsindex 11164066e9..083a850d27 100644--- a/web/src/features/posthog-analytics/usePostHogClientCapture.ts+++ b/web/src/features/posthog-analytics/usePostHogClientCapture.ts@@ -68,6 +68,7 @@ const events = {],integrations: ["posthog_form_submitted"],sign_in: ["cloud_region_switch", "button_click"],+ auth: ["reset_password_email_requested", "update_password_form_submit"],playground: ["execute_button_click","save_to_new_prompt_button_click",diff --git a/web/src/pages/auth/reset-password.tsx b/web/src/pages/auth/reset-password.tsxindex c525829556..e265c5e985 100644--- a/web/src/pages/auth/reset-password.tsx+++ b/web/src/pages/auth/reset-password.tsx@@ -1,3 +1,23 @@+import { env } from "@/src/env.mjs";import { ResetPasswordPage } from "@/src/features/auth-credentials/components/ResetPasswordPage";+import { type GetServerSideProps } from "next";-export default ResetPasswordPage;+type PageProps = {+ passwordResetAvailable: boolean;+};++export const getServerSideProps: GetServerSideProps<PageProps> = async () => {+ return {+ props: {+ passwordResetAvailable:+ env.SMTP_CONNECTION_URL !== undefined &&+ env.EMAIL_FROM_ADDRESS !== undefined,+ },+ };+};++const Page = ({ passwordResetAvailable }: PageProps) => {+ return <ResetPasswordPage passwordResetAvailable={passwordResetAvailable} />;+};++export default Page;diff --git a/web/src/pages/auth/sign-in.tsx b/web/src/pages/auth/sign-in.tsxindex 7cb109f1da..af47ac73b6 100644--- a/web/src/pages/auth/sign-in.tsx+++ b/web/src/pages/auth/sign-in.tsx@@ -32,7 +32,6 @@ import { Shield } from "lucide-react";import { useRouter } from "next/router";import { captureException } from "@sentry/nextjs";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";-import { RequestResetPasswordEmailButton } from "@/src/features/auth-credentials/components/ResetPasswordButton";const credentialAuthForm = z.object({email: z.string().email(),@@ -59,7 +58,6 @@ export type PageProps = {sso: boolean;};signUpDisabled: boolean;- passwordResetAvailable: boolean;};// Also used in src/pages/auth/sign-up.tsx@@ -102,9 +100,6 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async () => {sso,},signUpDisabled: env.AUTH_DISABLE_SIGNUP === "true",- passwordResetAvailable:- env.SMTP_CONNECTION_URL !== undefined &&- env.EMAIL_FROM_ADDRESS !== undefined,},};};@@ -229,11 +224,7 @@ const signInErrors = [},];-export default function SignIn({- authProviders,- signUpDisabled,- passwordResetAvailable,-}: PageProps) {+export default function SignIn({ authProviders, signUpDisabled }: PageProps) {const router = useRouter();// handle NextAuth error codes: https://next-auth.js.org/configuration/pages#sign-in-page@@ -385,7 +376,16 @@ export default function SignIn({name="password"render={({ field }) => (<FormItem>- <FormLabel>Password</FormLabel>+ <FormLabel>+ Password{" "}+ <Link+ href="/auth/reset-password"+ className="ml-1 text-xs text-primary-accent hover:text-hover-primary-accent"+ title="What is this?"+ >+ (forgot password?)+ </Link>+ </FormLabel><FormControl><PasswordInput {...field} /></FormControl>@@ -440,16 +440,9 @@ export default function SignIn({<div className="text-center text-sm font-medium text-destructive">{credentialsFormError}<br />- {credentialsFormError === "Invalid credentials" &&- passwordResetAvailable ? (- <RequestResetPasswordEmailButton- email={credentialsForm.getValues("email")}- className="mt-6 w-full"- variant="secondary"- />- ) : (- "Contact support if this error is unexpected."- )}+ Contact support if this error is unexpected.{" "}+ {env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION !== undefined &&+ "Make sure you are using the correct cloud data region."}</div>) : null}<SSOButtons authProviders={authProviders} />