From 32d0800c7e533e7c8d72e96d7c98e5dbf2e4a04d Mon Sep 17 00:00:00 2001
From: Marco Beretta <81851188+berry-13@users.noreply.github.com>
Date: Mon, 2 Nov 2026 22:12:29 +0100
Subject: [PATCH] =?UTF-8?q?=F0=9F=94=90=20style:=20Restyle=20the=20OAuth?=
=?UTF-8?q?=20Success=20and=20Error=20Pages=20(#17729)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* style: Restyle OAuth Success and Error Pages
* style: Render the OAuth Connected Server Badge With Chip
* test: Cover the OAuth Popup Pages With Playwright Scenarios
* test: Settle the OAuth Popup Close Race and Render the Error Page Shell
---
client/src/components/OAuth/OAuthError.tsx | 61 ++--------
client/src/components/OAuth/OAuthSuccess.tsx | 35 +++---
client/src/components/OAuth/Shell.tsx | 53 +++++++++
.../OAuth/__tests__/OAuthError.spec.tsx | 8 +-
.../OAuth/__tests__/OAuthSuccess.spec.tsx | 16 ++-
e2e/specs/mock/scenarios/oauth-pages.spec.ts | 112 ++++++++++++++++++
6 files changed, 213 insertions(+), 72 deletions(-)
create mode 100644 client/src/components/OAuth/Shell.tsx
create mode 100644 e2e/specs/mock/scenarios/oauth-pages.spec.ts
diff --git a/client/src/components/OAuth/OAuthError.tsx b/client/src/components/OAuth/OAuthError.tsx
index 6d00e4f805..4d76e0d52f 100644
--- a/client/src/components/OAuth/OAuthError.tsx
+++ b/client/src/components/OAuth/OAuthError.tsx
@@ -1,8 +1,9 @@
import React, { useEffect } from 'react';
-import { Button } from '@librechat/client';
+import { CircleX } from 'lucide-react';
import { useSearchParams } from 'react-router-dom';
import { announceOAuthSettled } from '~/data-provider';
import { useLocalize } from '~/hooks';
+import Shell from './Shell';
export default function OAuthError() {
const localize = useLocalize();
@@ -18,63 +19,21 @@ export default function OAuthError() {
const getErrorMessage = (error: string): string => {
switch (error) {
case 'missing_code':
- return (
- localize('com_ui_oauth_error_missing_code') ||
- 'Authorization code is missing. Please try again.'
- );
+ return localize('com_ui_oauth_error_missing_code');
case 'missing_state':
- return (
- localize('com_ui_oauth_error_missing_state') ||
- 'State parameter is missing. Please try again.'
- );
+ return localize('com_ui_oauth_error_missing_state');
case 'invalid_state':
- return (
- localize('com_ui_oauth_error_invalid_state') ||
- 'Invalid state parameter. Please try again.'
- );
+ return localize('com_ui_oauth_error_invalid_state');
case 'callback_failed':
- return (
- localize('com_ui_oauth_error_callback_failed') ||
- 'Authentication callback failed. Please try again.'
- );
+ return localize('com_ui_oauth_error_callback_failed');
default:
- return localize('com_ui_oauth_error_generic') || error.replace(/_/g, ' ');
+ return localize('com_ui_oauth_error_generic');
}
};
return (
-
-
-
-
- {localize('com_ui_oauth_error_title') || 'Authentication Failed'}
-
-
{getErrorMessage(error)}
-
-
-
+
+ {getErrorMessage(error)}
+
);
}
diff --git a/client/src/components/OAuth/OAuthSuccess.tsx b/client/src/components/OAuth/OAuthSuccess.tsx
index c1d19fd7ca..759f1791f2 100644
--- a/client/src/components/OAuth/OAuthSuccess.tsx
+++ b/client/src/components/OAuth/OAuthSuccess.tsx
@@ -1,7 +1,10 @@
import React, { useEffect, useState } from 'react';
+import { Chip } from '@librechat/client';
+import { CircleCheck } from 'lucide-react';
import { useSearchParams } from 'react-router-dom';
import { announceOAuthSettled } from '~/data-provider';
import { useLocalize } from '~/hooks';
+import Shell from './Shell';
export default function OAuthSuccess() {
const localize = useLocalize();
@@ -31,24 +34,18 @@ export default function OAuthSuccess() {
}, []);
return (
-
-
-
- {localize('com_ui_oauth_success_title') || 'Authentication Successful'}
-
-
- {localize('com_ui_oauth_success_description') ||
- 'Your authentication was successful. This window will close in'}{' '}
- {secondsLeft}{' '}
- {localize('com_ui_seconds') || 'seconds'}.
-
- {serverName && (
-
- {localize('com_ui_oauth_connected_to') || 'Connected to'}:{' '}
- {serverName}
-
- )}
-
-
+
+ {serverName && (
+
+ {localize('com_ui_oauth_connected_to')}{' '}
+ {serverName}
+
+ )}
+
+ {localize('com_ui_oauth_success_description')}{' '}
+ {secondsLeft}{' '}
+ {localize('com_ui_seconds')}.
+
+
);
}
diff --git a/client/src/components/OAuth/Shell.tsx b/client/src/components/OAuth/Shell.tsx
new file mode 100644
index 0000000000..cf6ae1e953
--- /dev/null
+++ b/client/src/components/OAuth/Shell.tsx
@@ -0,0 +1,53 @@
+import React, { useId } from 'react';
+import { Button } from '@librechat/client';
+import type { LucideIcon } from 'lucide-react';
+import { useLocalize } from '~/hooks';
+import { cn } from '~/utils';
+
+type ShellProps = {
+ icon: LucideIcon;
+ tone: 'success' | 'error';
+ title: string;
+ children: React.ReactNode;
+};
+
+export default function Shell({ icon: Icon, tone, title, children }: ShellProps) {
+ const localize = useLocalize();
+ const titleId = useId();
+
+ return (
+
+
+
+
+
+
+
+
+
+
+ {title}
+
+ {children}
+
+
+
+
+ );
+}
diff --git a/client/src/components/OAuth/__tests__/OAuthError.spec.tsx b/client/src/components/OAuth/__tests__/OAuthError.spec.tsx
index 74620c1981..0440521414 100644
--- a/client/src/components/OAuth/__tests__/OAuthError.spec.tsx
+++ b/client/src/components/OAuth/__tests__/OAuthError.spec.tsx
@@ -1,6 +1,6 @@
import React from 'react';
-import { render } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
+import { render, screen } from '@testing-library/react';
import OAuthError from '../OAuthError';
const mockAnnounce = jest.fn();
@@ -33,4 +33,10 @@ describe('OAuthError', () => {
renderAt('/oauth/error?error=invalid_state');
expect(mockAnnounce).toHaveBeenCalledWith({ outcome: 'failed', flowId: undefined });
});
+
+ it('maps a known error code to its message', () => {
+ renderAt('/oauth/error?error=invalid_state');
+ expect(screen.getByRole('heading', { name: 'com_ui_oauth_error_title' })).toBeInTheDocument();
+ expect(screen.getByText('com_ui_oauth_error_invalid_state')).toBeInTheDocument();
+ });
});
diff --git a/client/src/components/OAuth/__tests__/OAuthSuccess.spec.tsx b/client/src/components/OAuth/__tests__/OAuthSuccess.spec.tsx
index 0e99b90412..e92fc3a910 100644
--- a/client/src/components/OAuth/__tests__/OAuthSuccess.spec.tsx
+++ b/client/src/components/OAuth/__tests__/OAuthSuccess.spec.tsx
@@ -1,6 +1,6 @@
import React from 'react';
-import { render } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
+import { render, screen, fireEvent } from '@testing-library/react';
import OAuthSuccess from '../OAuthSuccess';
const mockAnnounce = jest.fn();
@@ -28,4 +28,18 @@ describe('OAuthSuccess', () => {
expect(mockAnnounce).toHaveBeenCalledTimes(1);
expect(mockAnnounce).toHaveBeenCalledWith({ outcome: 'succeeded', flowId: 'flow-a' });
});
+
+ it('names the connected server and closes the window on demand', () => {
+ const close = jest.spyOn(window, 'close').mockImplementation(() => undefined);
+ render(
+
+
+ ,
+ );
+ expect(screen.getByRole('heading', { name: 'com_ui_oauth_success_title' })).toBeInTheDocument();
+ expect(screen.getByText('GitHub')).toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: 'com_ui_close_window' }));
+ expect(close).toHaveBeenCalledTimes(1);
+ close.mockRestore();
+ });
});
diff --git a/e2e/specs/mock/scenarios/oauth-pages.spec.ts b/e2e/specs/mock/scenarios/oauth-pages.spec.ts
new file mode 100644
index 0000000000..c27719d631
--- /dev/null
+++ b/e2e/specs/mock/scenarios/oauth-pages.spec.ts
@@ -0,0 +1,112 @@
+import { expect, test } from '@playwright/test';
+import type { Page } from '@playwright/test';
+
+/**
+ * The pages an OAuth popup lands on after an MCP, action or pull request sign-in. The success
+ * page counts down and closes itself, so the clock is frozen wherever a test needs the page to
+ * stay open.
+ */
+
+/** Opens a page the way a sign-in does: as a popup of the app window, so `window.close` works. */
+async function openPopup(page: Page, path: string) {
+ await page.goto('/login', { timeout: 15000 });
+ const [popup] = await Promise.all([
+ page.waitForEvent('popup'),
+ page.evaluate((url) => window.open(url, '_blank', 'width=600,height=700'), path),
+ ]);
+ await popup.waitForLoadState('domcontentloaded');
+ return popup;
+}
+
+/**
+ * Activates a control that closes its own window. The window can be gone before the input call
+ * settles, so that call's rejection counts only while the window is still open.
+ */
+async function closeWith(popup: Page, activate: () => Promise) {
+ const closed = popup.waitForEvent('close');
+ await activate().catch((error) => {
+ if (!popup.isClosed()) {
+ throw error;
+ }
+ });
+ await closed;
+}
+
+/**
+ * A full navigation to /oauth/error is answered by the server's social-login failure route
+ * (api/server/routes/oauth.js), which redirects to /login before the app loads. These tests
+ * cover the page the app renders for that path, so its document is served the app shell.
+ */
+async function serveErrorPageShell(page: Page) {
+ await page.context().route(/\/oauth\/error(\?|$)/, async (route) => {
+ if (route.request().resourceType() !== 'document') {
+ return route.fallback();
+ }
+ const shell = await route.fetch({ url: new URL('/', route.request().url()).toString() });
+ await route.fulfill({ response: shell });
+ });
+}
+
+test('the success page names the server and its Close button closes the popup @scenario:oauth-success-close', async ({
+ page,
+ context,
+}) => {
+ await context.clock.install();
+ const popup = await openPopup(page, '/oauth/success?serverName=GitHub&flow=flow-a');
+
+ await expect(popup.getByRole('heading', { level: 1 })).toBeVisible();
+ await expect(popup.getByText('GitHub', { exact: true })).toBeVisible();
+ await expect(popup.getByText('3', { exact: true })).toBeVisible();
+ const logoLoaded = await popup
+ .locator('header img')
+ .evaluate((img: HTMLImageElement) => img.complete && img.naturalWidth > 0);
+ expect(logoLoaded).toBe(true);
+
+ const close = popup.getByRole('button', { name: 'Close Window' });
+ await close.focus();
+ await expect(close).toBeFocused();
+ await closeWith(popup, () => close.press('Enter'));
+});
+
+test('the success page shows no server badge when the redirect names none @scenario:oauth-success-no-server', async ({
+ page,
+ context,
+}) => {
+ await context.clock.install();
+ const popup = await openPopup(page, '/oauth/success?flow=flow-a');
+
+ await expect(popup.getByRole('heading', { level: 1 })).toBeVisible();
+ await expect(popup.getByText('Connected to')).toHaveCount(0);
+ await expect(popup.getByRole('button', { name: 'Close Window' })).toBeVisible();
+});
+
+test('a long server name stays inside the page @scenario:oauth-success-long-name', async ({
+ page,
+ context,
+}) => {
+ await context.clock.install();
+ const name = `Ünïcödé 服务器 ${'very-long-action-name-'.repeat(8)}`;
+ const popup = await openPopup(page, `/oauth/success?serverName=${encodeURIComponent(name)}`);
+
+ await expect(popup.getByRole('heading', { level: 1 })).toBeVisible();
+ await expect(popup.getByText(name)).toBeAttached();
+ const overflow = await popup.evaluate(
+ () => document.documentElement.scrollWidth - document.documentElement.clientWidth,
+ );
+ expect(overflow).toBeLessThanOrEqual(0);
+});
+
+test('the error page explains a known code and falls back for an unknown one @scenario:oauth-error-message', async ({
+ page,
+}) => {
+ await serveErrorPageShell(page);
+ const known = await openPopup(page, '/oauth/error?error=invalid_state&flow=flow-a');
+ await expect(known.getByRole('heading', { name: 'Authentication Failed' })).toBeVisible();
+ await expect(known.getByText('Invalid state parameter. Please try again.')).toBeVisible();
+ await known.close();
+
+ const unknown = await openPopup(page, '/oauth/error?error=access_denied');
+ await expect(unknown.getByText('Authentication failed. Please try again.')).toBeVisible();
+ await expect(unknown.getByText('access_denied')).toHaveCount(0);
+ await closeWith(unknown, () => unknown.getByRole('button', { name: 'Close Window' }).click());
+});