🪢 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
feat(auth): remember the last enterprise SSO email on the sign-in form (#18258)
Der Geräteadfff4d8d7b
diff --git a/web/src/__tests__/auth-sign-in-page.clienttest.tsx b/web/src/__tests__/auth-sign-in-page.clienttest.tsxindex 084e7f8dd9..66230d948b 100644--- a/web/src/__tests__/auth-sign-in-page.clienttest.tsx+++ b/web/src/__tests__/auth-sign-in-page.clienttest.tsx@@ -369,3 +369,156 @@ describe("sign-in page SSO check transport errors", () => {expect(addBreadcrumbMock).not.toHaveBeenCalled();});});++describe("sign-in page last used SSO email", () => {+ const STORAGE_KEY = "langfuse_last_used_sso_email";+ let warnSpy: ReturnType<typeof vi.spyOn>;++ const storedSsoEmail = () => {+ const raw = window.localStorage.getItem(STORAGE_KEY);+ return raw === null ? null : (JSON.parse(raw) as string);+ };++ const ssoCheckReturns = (providerId: string) =>+ vi.stubGlobal(+ "fetch",+ vi.fn().mockResolvedValue(+ new Response(JSON.stringify({ providerId }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ ),+ );++ const ssoCheckFailsWith = (status: number) =>+ vi.stubGlobal(+ "fetch",+ vi.fn().mockResolvedValue(+ new Response(JSON.stringify({ message: "nope" }), {+ status,+ headers: { "Content-Type": "application/json" },+ }),+ ),+ );++ const continueWithEmail = (email: string) => {+ fireEvent.change(screen.getByLabelText("Email"), {+ target: { value: email },+ });+ fireEvent.click(screen.getByTestId("submit-email-password-sign-in-form"));+ };++ const renderTwoStepSignIn = () =>+ renderSignIn({ authProviders: { ...authProviders, sso: true } });++ beforeEach(() => {+ captureExceptionMock.mockClear();+ addBreadcrumbMock.mockClear();+ signInMock.mockReset();+ routerState.query = {};+ window.localStorage.clear();+ warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});+ });++ afterEach(() => {+ warnSpy.mockRestore();+ vi.unstubAllGlobals();+ });++ it("pre-fills the email input with the remembered SSO address", async () => {+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify("[email protected]"));++ renderTwoStepSignIn();++ await waitFor(() => {+ expect(screen.getByLabelText("Email")).toHaveValue("[email protected]");+ });+ // Nothing else is revealed: the password step still waits on check-sso.+ expect(screen.queryByLabelText(/Password/)).not.toBeInTheDocument();+ });++ it("lets an email query param win over the remembered address", async () => {+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify("[email protected]"));+ routerState.query = { email: "[email protected]" };++ renderTwoStepSignIn();++ await waitFor(() => {+ expect(screen.getByLabelText("Email")).toHaveValue("[email protected]");+ });+ });++ it("remembers the address when check-sso redirects to an SSO provider", async () => {+ ssoCheckReturns("acme.com.okta");++ renderTwoStepSignIn();+ continueWithEmail("[email protected]");++ await waitFor(() => {+ expect(signInMock).toHaveBeenCalledWith("acme.com.okta", undefined);+ });+ expect(storedSsoEmail()).toBe("[email protected]");+ });++ it("forgets a remembered address once an email falls back to a password", async () => {+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify("[email protected]"));+ ssoCheckFailsWith(404);++ renderTwoStepSignIn();+ continueWithEmail("[email protected]");++ // The password step appearing is what marks the email as not SSO-backed.+ await waitFor(() => {+ expect(screen.getByLabelText(/Password/)).toBeInTheDocument();+ });+ expect(storedSsoEmail()).toBe("");+ expect(signInMock).not.toHaveBeenCalled();+ });++ // 404 is the only status that means "this domain has no SSO provider". A+ // server or proxy failure says nothing about the domain, so it must not cost+ // the user an address that was correctly remembered.+ it("keeps the remembered address when check-sso fails with a server error", async () => {+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify("[email protected]"));+ ssoCheckFailsWith(500);++ renderTwoStepSignIn();+ continueWithEmail("[email protected]");++ await waitFor(() => {+ expect(screen.getByLabelText(/Password/)).toBeInTheDocument();+ });+ expect(storedSsoEmail()).toBe("[email protected]");+ });++ // An instance that removes its last SSO config renders the one-step password+ // form, which never runs the lookup that would clear a remembered address.+ it("drops a remembered address when the instance has no SSO configured", async () => {+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify("[email protected]"));++ renderSignIn({ authProviders: { ...authProviders, sso: false } });++ // One-step form: password is visible immediately.+ expect(screen.getByLabelText(/Password/)).toBeInTheDocument();+ await waitFor(() => {+ expect(storedSsoEmail()).toBe("");+ });+ expect(screen.getByLabelText("Email")).toHaveValue("");+ });++ // The transport path (fetch rejects) is likewise not a verdict on the domain.+ it("keeps the remembered address when check-sso cannot be reached", async () => {+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify("[email protected]"));+ vi.stubGlobal("fetch", vi.fn().mockRejectedValue(new Error("offline")));++ renderTwoStepSignIn();+ continueWithEmail("[email protected]");++ await waitFor(() => {+ expect(+ screen.getByText(/Unable to check SSO configuration/),+ ).toBeInTheDocument();+ });+ expect(storedSsoEmail()).toBe("[email protected]");+ });+});diff --git a/web/src/features/auth/SignInPage.tsx b/web/src/features/auth/SignInPage.tsxindex adbd1e6771..6beedcbb53 100644--- a/web/src/features/auth/SignInPage.tsx+++ b/web/src/features/auth/SignInPage.tsx@@ -551,6 +551,14 @@ export default function SignInPage({"langfuse_last_used_auth_method",null,);+ // The enterprise SSO step redirects before a password field is ever shown,+ // so the browser password manager has no credential to offer and the address+ // has to be retyped on every sign-in. Holds the last address that resolved to+ // an enterprise SSO provider; empty for every other outcome.+ const [lastUsedSsoEmail, setLastUsedSsoEmail] = useLocalStorage<string>(+ "langfuse_last_used_sso_email",+ "",+ );const capture = usePostHogClientCapture();const { isLangfuseCloud } = useLangfuseCloudRegion();@@ -578,6 +586,31 @@ export default function SignInPage({password: "",},});++ // Restoring the remembered address is a browser-storage sync, not a render+ // derivation: the server render cannot see localStorage, and React skips+ // assigning `input.value` while hydrating, so a value folded into+ // `defaultValues` would leave the field looking empty. Only an untouched,+ // empty field is filled, which keeps `?email=` and anything already typed.+ useEffect(() => {+ if (!lastUsedSsoEmail) return;+ // An instance can drop its last SSO config after an address was+ // remembered. The resulting one-step form never runs the lookup that+ // would clear it, so discard it here instead of prefilling a sign-in+ // method the instance no longer offers.+ if (!authProviders.sso) {+ setLastUsedSsoEmail("");+ return;+ }+ if (credentialsForm.getValues("email")) return;+ credentialsForm.setValue("email", lastUsedSsoEmail);+ }, [+ authProviders.sso,+ credentialsForm,+ lastUsedSsoEmail,+ setLastUsedSsoEmail,+ ]);+async function onCredentialsSubmit(values: z.infer<typeof credentialAuthForm>,) {@@ -739,6 +772,7 @@ export default function SignInPage({// Store the SSO provider as the last used auth methodsetLastUsedAuthMethod(providerId as NextAuthProvider);+ setLastUsedSsoEmail(email.data);signIn(providerId,@@ -747,7 +781,12 @@ export default function SignInPage({return; // stop further execution – page redirect expected}- // No SSO – fall back to password step+ // No SSO – fall back to password step. 404 is the only answer that means+ // "this domain has no SSO provider"; any other failure status says+ // nothing about the domain, so it must not discard a remembered address.+ if (res.status === 404) {+ setLastUsedSsoEmail("");+ }setShowPasswordStep(true);// Auto-focus password input when password step becomes visible