🔐 style: Restyle the OAuth Success and Error Pages (#17729)
Some checks are pending
Codegraph E2E Vote Gate / Gate (push) Waiting to run
Codegraph E2E Votes / vote (shard 1/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 10/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 2/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 3/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 4/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 5/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 6/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 7/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 8/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 9/10) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/chat (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions

* 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
This commit is contained in:
Marco Beretta 2026-11-02 22:12:29 +01:00 • committed by GitHub
parent d452d1e636
commit 32d0800c7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 213 additions and 72 deletions

View file

@ -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 (
<div className="bg-surface-secondary flex min-h-screen items-center justify-center p-8">
<div className="bg-surface-primary w-full max-w-md rounded-lg p-8 text-center shadow-lg">
<div className="mb-4 flex justify-center">
<div className="bg-status-error-subtle flex h-12 w-12 items-center justify-center rounded-full">
<svg
className="text-status-error h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
aria-hidden="true"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</div>
</div>
<h1 className="text-text-primary mb-4 text-3xl font-bold">
{localize('com_ui_oauth_error_title') || 'Authentication Failed'}
</h1>
<p className="text-text-secondary mb-6 text-sm">{getErrorMessage(error)}</p>
<Button
variant="default"
onClick={() => window.close()}
aria-label={localize('com_ui_close_window')}
>
{localize('com_ui_close_window')}
</Button>
</div>
</div>
<Shell icon={CircleX} tone="error" title={localize('com_ui_oauth_error_title')}>
<p className="text-text-secondary text-sm">{getErrorMessage(error)}</p>
</Shell>
);
}

View file

@ -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 (
<div className="bg-surface-secondary flex min-h-screen items-center justify-center p-8">
<div className="bg-surface-primary w-full max-w-md rounded-xl p-8 text-center shadow-lg">
<h1 className="text-text-primary mb-4 text-3xl font-bold">
{localize('com_ui_oauth_success_title') || 'Authentication Successful'}
</h1>
<p className="text-text-secondary mb-2 text-sm">
{localize('com_ui_oauth_success_description') ||
'Your authentication was successful. This window will close in'}{' '}
<span className="text-accent-primary font-medium">{secondsLeft}</span>{' '}
{localize('com_ui_seconds') || 'seconds'}.
</p>
{serverName && (
<p className="text-text-tertiary mt-4 text-xs">
{localize('com_ui_oauth_connected_to') || 'Connected to'}:{' '}
<span className="font-medium">{serverName}</span>
</p>
)}
</div>
</div>
<Shell icon={CircleCheck} tone="success" title={localize('com_ui_oauth_success_title')}>
{serverName && (
<Chip tone="surface" className="mb-3">
{localize('com_ui_oauth_connected_to')}{' '}
<span className="text-text-primary">{serverName}</span>
</Chip>
)}
<p className="text-text-secondary text-sm">
{localize('com_ui_oauth_success_description')}{' '}
<span className="text-text-primary font-medium tabular-nums">{secondsLeft}</span>{' '}
{localize('com_ui_seconds')}.
</p>
</Shell>
);
}

View file

@ -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 (
<div className="bg-surface-primary flex min-h-screen flex-col">
<header className="mt-6 h-10 w-full">
<img src="assets/logo.svg" className="h-full w-full object-contain" alt="" />
</header>
<main className="flex grow items-center justify-center p-6">
<section
aria-labelledby={titleId}
className="flex w-full max-w-sm flex-col items-center px-6 py-8 text-center"
>
<div
className={cn(
'mb-5 flex size-12 items-center justify-center rounded-full',
tone === 'success' ? 'bg-status-success-subtle' : 'bg-status-error-subtle',
)}
>
<Icon
aria-hidden="true"
className={cn(
'size-6',
tone === 'success' ? 'text-status-success' : 'text-status-error',
)}
/>
</div>
<h1 id={titleId} className="text-text-primary mb-2 text-2xl font-semibold">
{title}
</h1>
{children}
<Button variant="outline" className="mt-6 w-full" onClick={() => window.close()}>
{localize('com_ui_close_window')}
</Button>
</section>
</main>
</div>
);
}

View file

@ -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();
});
});

View file

@ -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(
<MemoryRouter initialEntries={['/oauth/success?serverName=GitHub&flow=flow-a']}>
<OAuthSuccess />
</MemoryRouter>,
);
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();
});
});

View file

@ -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<void>) {
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());
});