@shellui/core 0.7.0-alpha.1 → 0.7.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/package.json +2 -2
  2. package/schemas/shellui.config.schema.json +37 -4
  3. package/src/components/ContentView.tsx +19 -8
  4. package/src/components/ui/drawer.tsx +47 -30
  5. package/src/components/ui/sheet.tsx +18 -12
  6. package/src/components/ui/sidebar.tsx +25 -11
  7. package/src/components/ui/tooltip.tsx +4 -2
  8. package/src/features/admin/AdminView.tsx +9 -6
  9. package/src/features/auth/AuthProvider.tsx +25 -4
  10. package/src/features/auth/appBackend/appBackendSessions.spec.ts +134 -0
  11. package/src/features/auth/appBackend/appBackendSessions.ts +168 -17
  12. package/src/features/auth/appBackend/childFrames.spec.ts +328 -0
  13. package/src/features/auth/appBackend/childFrames.ts +180 -0
  14. package/src/features/auth/appBackend/frameAuth.ts +47 -10
  15. package/src/features/auth/appBackend/silentSignIn.spec.ts +18 -0
  16. package/src/features/auth/appBackend/silentSignIn.ts +15 -1
  17. package/src/features/auth/appBackend/tokenExchange.spec.ts +98 -0
  18. package/src/features/auth/appBackend/tokenExchange.ts +76 -0
  19. package/src/features/auth/components/LoginButton.spec.tsx +155 -0
  20. package/src/features/auth/components/LoginButton.tsx +52 -27
  21. package/src/features/auth/components/LoginButtonIcons.tsx +4 -8
  22. package/src/features/auth/components/OAuthCallbackView.tsx +7 -5
  23. package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +42 -1
  24. package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +23 -0
  25. package/src/features/auth/utils/canRestoreStoredSession.spec.ts +29 -0
  26. package/src/features/auth/utils/canRestoreStoredSession.ts +12 -0
  27. package/src/features/auth/utils/index.ts +7 -1
  28. package/src/features/auth/utils/resolveSdkLoginRedirectPath.spec.ts +41 -0
  29. package/src/features/auth/utils/resolveSdkLoginRedirectPath.ts +31 -0
  30. package/src/features/auth/utils/webPkce.spec.ts +23 -0
  31. package/src/features/auth/utils/webPkce.ts +23 -6
  32. package/src/features/chromeActions/ChromeActionsHost.tsx +5 -1
  33. package/src/features/chromeActions/computeActionInsets.ts +7 -4
  34. package/src/features/config/types.ts +30 -4
  35. package/src/features/layouts/OverlayShell.tsx +58 -40
  36. package/src/features/layouts/appbar/AppBarItemIcon.spec.tsx +45 -0
  37. package/src/features/layouts/appbar/AppBarItemIcon.tsx +19 -0
  38. package/src/features/layouts/appbar/AppBarLayout.tsx +115 -110
  39. package/src/features/layouts/appbar/appBarOverflow.spec.ts +27 -0
  40. package/src/features/layouts/appbar/appBarOverflow.ts +42 -0
  41. package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +13 -24
  42. package/src/features/layouts/chrome/ContentDragOverlay.tsx +5 -6
  43. package/src/features/layouts/chrome/DesktopChrome.tsx +37 -0
  44. package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +15 -4
  45. package/src/features/layouts/chrome/MacStrip.tsx +33 -0
  46. package/src/features/layouts/chrome/constants.ts +36 -8
  47. package/src/features/layouts/chrome/index.ts +8 -0
  48. package/src/features/layouts/chrome/stripDragMap.ts +35 -0
  49. package/src/features/layouts/chrome/stripNoDrag.spec.tsx +103 -0
  50. package/src/features/layouts/chrome/useScrollHideChrome.ts +3 -8
  51. package/src/features/layouts/chrome/viewport.ts +11 -4
  52. package/src/features/layouts/filterNavigationForAuthState.spec.ts +5 -3
  53. package/src/features/layouts/floating/FloatingBottomDock.tsx +263 -43
  54. package/src/features/layouts/floating/FloatingLayout.tsx +14 -8
  55. package/src/features/layouts/floating/FloatingSidebar.tsx +165 -73
  56. package/src/features/layouts/floating/computeFloatingInsets.ts +22 -4
  57. package/src/features/layouts/floating/moreSections.spec.ts +28 -0
  58. package/src/features/layouts/floating/moreSections.ts +31 -0
  59. package/src/features/layouts/floating/useFloatingChrome.ts +3 -1
  60. package/src/features/layouts/floating/useSoftKeyboard.spec.ts +39 -0
  61. package/src/features/layouts/floating/useSoftKeyboard.ts +82 -0
  62. package/src/features/layouts/fullscreen/FullscreenLayout.spec.tsx +68 -0
  63. package/src/features/layouts/fullscreen/FullscreenLayout.tsx +47 -10
  64. package/src/features/layouts/sidebar/NavigationContent.tsx +17 -9
  65. package/src/features/layouts/sidebar/SidebarIcons.tsx +70 -9
  66. package/src/features/layouts/sidebar/SidebarInner.spec.tsx +109 -0
  67. package/src/features/layouts/sidebar/SidebarInner.tsx +94 -43
  68. package/src/features/layouts/sidebar/SidebarLayout.tsx +24 -17
  69. package/src/features/layouts/utils.ts +4 -3
  70. package/src/features/layouts/windows/DesktopDots.tsx +76 -0
  71. package/src/features/layouts/windows/WindowsLayout.tsx +251 -161
  72. package/src/features/layouts/windows/deskDots.spec.ts +54 -0
  73. package/src/features/layouts/windows/deskDots.ts +314 -0
  74. package/src/features/overlays/ResponsiveModal.tsx +5 -3
  75. package/src/features/overlays/overlaySize.spec.ts +56 -16
  76. package/src/features/overlays/overlaySize.ts +114 -31
  77. package/src/features/overlays/phoneDrawerAnchoring.spec.ts +187 -0
  78. package/src/features/overlays/useOverlayReportedSize.ts +8 -3
  79. package/src/features/settings/SettingsProvider.tsx +158 -2
  80. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +8 -7
  81. package/src/features/settings/utils/buildSettingsForPropagation.ts +4 -6
  82. package/src/features/theme/applyTheme.ts +8 -0
  83. package/src/features/theme/navContrast.spec.ts +49 -0
  84. package/src/features/theme/navContrast.ts +108 -0
  85. package/src/features/transfers/transferQueue.spec.ts +6 -2
  86. package/src/i18n/translations/en/common.json +26 -0
  87. package/src/i18n/translations/fr/common.json +26 -0
  88. package/src/index.css +1145 -77
  89. package/src/index.ts +1 -0
  90. package/src/routes/hooks/useNavigationItems.ts +14 -3
  91. package/src/routes/hooks/withShellSearch.spec.ts +13 -0
  92. package/src/service-worker/devCaches.spec.ts +32 -0
  93. package/src/service-worker/devCaches.ts +27 -0
  94. package/src/service-worker/sw-dev.ts +23 -23
@@ -0,0 +1,98 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest';
2
+ import {
3
+ ACCESS_TOKEN_TYPE,
4
+ TOKEN_EXCHANGE_GRANT,
5
+ describeAppSessionFailure,
6
+ exchangeShellTokenForAppSession,
7
+ } from './tokenExchange';
8
+
9
+ const NOW = 1_800_000_000;
10
+
11
+ function jsonResponse(status: number, body: unknown): Response {
12
+ return new Response(JSON.stringify(body), {
13
+ status,
14
+ headers: { 'Content-Type': 'application/json' },
15
+ });
16
+ }
17
+
18
+ describe('exchangeShellTokenForAppSession', () => {
19
+ afterEach(() => {
20
+ vi.unstubAllGlobals();
21
+ });
22
+
23
+ it('posts an RFC 8693 request to the regional server and returns its session', async () => {
24
+ const fetchMock = vi.fn(async () =>
25
+ jsonResponse(200, {
26
+ access_token: 'regional-access',
27
+ refresh_token: 'regional-refresh',
28
+ token_type: 'Bearer',
29
+ issued_token_type: ACCESS_TOKEN_TYPE,
30
+ expires_in: 300,
31
+ expires_at: NOW + 300,
32
+ }),
33
+ );
34
+ vi.stubGlobal('fetch', fetchMock);
35
+
36
+ const outcome = await exchangeShellTokenForAppSession({
37
+ backendUrl: 'https://id.eu.example',
38
+ companyId: 5,
39
+ shellAccessToken: 'global-access',
40
+ nowSeconds: NOW,
41
+ });
42
+
43
+ expect(outcome.ok && outcome.session.accessToken).toBe('regional-access');
44
+ const [url, init] = fetchMock.mock.calls[0] as unknown as [string, RequestInit];
45
+ expect(url).toBe('https://id.eu.example/oauth/token');
46
+ expect(init.method).toBe('POST');
47
+ expect(init.credentials).toBe('omit');
48
+ const body = new URLSearchParams(String(init.body));
49
+ expect(body.get('grant_type')).toBe(TOKEN_EXCHANGE_GRANT);
50
+ expect(body.get('subject_token')).toBe('global-access');
51
+ expect(body.get('subject_token_type')).toBe(ACCESS_TOKEN_TYPE);
52
+ expect(body.get('company_id')).toBe('5');
53
+ expect(url).not.toContain('global-access');
54
+ });
55
+
56
+ it('refuses without a numeric company id and sends nothing', async () => {
57
+ const fetchMock = vi.fn();
58
+ vi.stubGlobal('fetch', fetchMock);
59
+ const outcome = await exchangeShellTokenForAppSession({
60
+ backendUrl: 'https://id.eu.example',
61
+ shellAccessToken: 'global-access',
62
+ nowSeconds: NOW,
63
+ });
64
+ expect(outcome).toEqual({ ok: false, reason: 'missing_company_id' });
65
+ expect(fetchMock).not.toHaveBeenCalled();
66
+ });
67
+
68
+ it('reports the server error without the token', async () => {
69
+ vi.stubGlobal(
70
+ 'fetch',
71
+ vi.fn(async () =>
72
+ jsonResponse(400, { error: 'invalid_grant', error_description: 'User is not a member.' }),
73
+ ),
74
+ );
75
+ const outcome = await exchangeShellTokenForAppSession({
76
+ backendUrl: 'https://id.eu.example',
77
+ companyId: '5',
78
+ shellAccessToken: 'global-access',
79
+ nowSeconds: NOW,
80
+ });
81
+ expect(outcome).toEqual({ ok: false, reason: 'invalid_grant: User is not a member.' });
82
+ expect(describeAppSessionFailure('invalid_grant: User is not a member.')).toBeTruthy();
83
+ });
84
+
85
+ it('reports a server without token exchange', async () => {
86
+ vi.stubGlobal(
87
+ 'fetch',
88
+ vi.fn(async () => jsonResponse(404, {})),
89
+ );
90
+ const outcome = await exchangeShellTokenForAppSession({
91
+ backendUrl: 'https://id.eu.example',
92
+ companyId: 5,
93
+ shellAccessToken: 'global-access',
94
+ nowSeconds: NOW,
95
+ });
96
+ expect(outcome).toEqual({ ok: false, reason: 'token_exchange_unavailable' });
97
+ });
98
+ });
@@ -0,0 +1,76 @@
1
+ import { buildSessionFromTokenPayload } from '../utils/buildSessionFromTokenPayload';
2
+ import type { AuthSession } from '../types';
3
+
4
+ export const TOKEN_EXCHANGE_GRANT = 'urn:ietf:params:oauth:grant-type:token-exchange';
5
+ export const ACCESS_TOKEN_TYPE = 'urn:ietf:params:oauth:token-type:access_token';
6
+
7
+ export type TokenExchangeOutcome =
8
+ | { ok: true; session: AuthSession }
9
+ | { ok: false; reason: string };
10
+
11
+ /**
12
+ * RFC 8693 token exchange against a regional identity server.
13
+ * The shell access token goes to that server only. Never pass it to a child app.
14
+ */
15
+ export async function exchangeShellTokenForAppSession(input: {
16
+ backendUrl: string;
17
+ companyId?: string | number;
18
+ shellAccessToken: string;
19
+ nowSeconds: number;
20
+ }): Promise<TokenExchangeOutcome> {
21
+ const companyId = `${input.companyId ?? ''}`.trim();
22
+ if (!/^\d+$/.test(companyId)) return { ok: false, reason: 'missing_company_id' };
23
+ if (!input.shellAccessToken) return { ok: false, reason: 'no_shell_session' };
24
+
25
+ const body = new URLSearchParams({
26
+ grant_type: TOKEN_EXCHANGE_GRANT,
27
+ subject_token: input.shellAccessToken,
28
+ subject_token_type: ACCESS_TOKEN_TYPE,
29
+ company_id: companyId,
30
+ });
31
+ let response: Response;
32
+ try {
33
+ response = await fetch(`${input.backendUrl}/oauth/token`, {
34
+ method: 'POST',
35
+ headers: {
36
+ Accept: 'application/json',
37
+ 'Content-Type': 'application/x-www-form-urlencoded',
38
+ },
39
+ body: body.toString(),
40
+ credentials: 'omit',
41
+ });
42
+ } catch {
43
+ return { ok: false, reason: 'token_exchange_unreachable' };
44
+ }
45
+ const payload = (await response.json().catch(() => null)) as Record<string, unknown> | null;
46
+ if (!response.ok) {
47
+ if (response.status === 404) return { ok: false, reason: 'token_exchange_unavailable' };
48
+ const code = typeof payload?.error === 'string' ? payload.error : `http_${response.status}`;
49
+ const detail =
50
+ typeof payload?.error_description === 'string' ? payload.error_description.slice(0, 200) : '';
51
+ return { ok: false, reason: detail ? `${code}: ${detail}` : code };
52
+ }
53
+ const session = buildSessionFromTokenPayload(payload, input.nowSeconds);
54
+ if (!session?.accessToken) return { ok: false, reason: 'token_exchange_empty' };
55
+ return { ok: true, session };
56
+ }
57
+
58
+ const HINTS: Record<string, string> = {
59
+ missing_company_id:
60
+ 'Set the regional company id (regional_company_id) as companyId on this app backend.',
61
+ no_shell_session: 'The shell has no session access token to exchange. Sign in to the shell.',
62
+ token_exchange_unreachable:
63
+ 'The regional identity server did not answer. Check its URL and that OIDC_CORS_ALLOWED_ORIGINS lists this shell origin.',
64
+ token_exchange_unavailable:
65
+ 'The regional identity server does not offer token exchange. It needs role region, GLOBAL_ISSUER_URL, GLOBAL_JWKS and GLOBAL_ACCESS_TOKEN_AUDIENCE.',
66
+ invalid_request:
67
+ 'The regional identity server refused the request. Check OIDC_CORS_ALLOWED_ORIGINS lists this shell origin.',
68
+ invalid_target: 'The regional identity server does not know this company id.',
69
+ invalid_grant:
70
+ 'The regional identity server refused the shell token or this user for that company.',
71
+ };
72
+
73
+ export function describeAppSessionFailure(reason: string): string | undefined {
74
+ const code = reason.split(':')[0].trim();
75
+ return HINTS[code];
76
+ }
@@ -0,0 +1,155 @@
1
+ // @vitest-environment happy-dom
2
+ import { act } from 'react';
3
+ import { createRoot, type Root } from 'react-dom/client';
4
+ import { MemoryRouter } from 'react-router';
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
6
+ import en from '../../../i18n/translations/en/common.json';
7
+ import fr from '../../../i18n/translations/fr/common.json';
8
+ import { SidebarProvider } from '../../../components/ui/sidebar';
9
+ import { getAccountInitials, LoginButton } from './LoginButton';
10
+
11
+ type User = { name?: string; email?: string; profilePicture?: string };
12
+ const auth: { isAuthenticated: boolean; isLoading: boolean; user: User | null } = {
13
+ isAuthenticated: true,
14
+ isLoading: false,
15
+ user: null,
16
+ };
17
+
18
+ vi.mock('../hooks/useAuth', () => ({
19
+ useAuth: () => ({ ...auth, logout: vi.fn() }),
20
+ }));
21
+ vi.mock('../../config/useConfig', () => ({
22
+ useConfig: () => ({ config: { backend: { type: 'shellui' } } }),
23
+ }));
24
+ vi.mock('../../../hooks/use-mobile', () => ({ useIsMobile: () => false }));
25
+ vi.mock('react-i18next', () => ({
26
+ useTranslation: () => ({
27
+ t: (key: string, opts?: Record<string, string>) => {
28
+ const [group, leaf] = key.split('.') as [keyof typeof en, string];
29
+ const raw = (en[group] as Record<string, string>)[leaf] ?? opts?.defaultValue ?? key;
30
+ return raw.replace(/\{\{(\w+)\}\}/g, (_, k: string) => opts?.[k] ?? '');
31
+ },
32
+ }),
33
+ }));
34
+
35
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
36
+
37
+ let container: HTMLDivElement;
38
+ let root: Root;
39
+
40
+ beforeEach(() => {
41
+ container = document.createElement('div');
42
+ document.body.appendChild(container);
43
+ root = createRoot(container);
44
+ auth.isAuthenticated = true;
45
+ auth.isLoading = false;
46
+ auth.user = null;
47
+ });
48
+
49
+ afterEach(() => {
50
+ act(() => root.unmount());
51
+ container.remove();
52
+ });
53
+
54
+ function render(open = true) {
55
+ act(() => {
56
+ root.render(
57
+ <MemoryRouter>
58
+ <SidebarProvider defaultOpen={open}>
59
+ <LoginButton variant="sidebar" />
60
+ </SidebarProvider>
61
+ </MemoryRouter>,
62
+ );
63
+ });
64
+ return container.querySelector<HTMLButtonElement>('[data-shellui-account-trigger]');
65
+ }
66
+
67
+ describe('getAccountInitials', () => {
68
+ it('uses the first and last word of the name', () => {
69
+ expect(getAccountInitials('Alex Martin', 'alex@acme.dev')).toBe('AM');
70
+ expect(getAccountInitials(' jean claude van damme ', null)).toBe('JD');
71
+ expect(getAccountInitials('Émile', null)).toBe('É');
72
+ });
73
+
74
+ it('falls back to the email', () => {
75
+ expect(getAccountInitials('', 'zoe@acme.dev')).toBe('Z');
76
+ expect(getAccountInitials(null, null)).toBe('');
77
+ });
78
+ });
79
+
80
+ describe('sidebar account block', () => {
81
+ it('shows initials, name, email and the chevrons-up-down icon', () => {
82
+ auth.user = { name: 'Alex Martin', email: 'alex@acme.dev' };
83
+ const btn = render();
84
+ expect(btn).not.toBeNull();
85
+ expect(btn?.querySelector('[data-shellui-account-initials]')?.textContent).toBe('AM');
86
+ expect(btn?.textContent).toContain('Alex Martin');
87
+ expect(btn?.querySelector('[data-shellui-account-email]')?.textContent).toBe('alex@acme.dev');
88
+ expect(btn?.querySelectorAll('svg path')).toHaveLength(2);
89
+ expect(btn?.getAttribute('aria-label')).toBe(
90
+ 'Open account menu for Alex Martin, alex@acme.dev',
91
+ );
92
+ expect(btn?.hasAttribute('data-shellui-no-drag')).toBe(true);
93
+ });
94
+
95
+ it('truncates long names and emails', () => {
96
+ auth.user = {
97
+ name: 'Maximilian Alexander von Hohenberg-Wittelsbach',
98
+ email: 'maximilian.alexander.von.hohenberg@very-long-company-domain.example',
99
+ };
100
+ const btn = render();
101
+ const email = btn?.querySelector('[data-shellui-account-email]');
102
+ expect(email?.className).toContain('truncate');
103
+ expect(email?.previousElementSibling?.className).toContain('truncate');
104
+ expect(email?.parentElement?.className).toContain('min-w-0');
105
+ });
106
+
107
+ it('shows the email as the name, once, when there is no name', () => {
108
+ auth.user = { email: 'zoe@acme.dev' };
109
+ const btn = render();
110
+ expect(btn?.querySelector('[data-shellui-account-email]')).toBeNull();
111
+ expect(btn?.querySelector('[data-shellui-account-initials]')?.textContent).toBe('Z');
112
+ expect(btn?.getAttribute('aria-label')).toBe('Open account menu for zoe@acme.dev');
113
+ });
114
+
115
+ it('shows the profile picture instead of initials', () => {
116
+ auth.user = {
117
+ name: 'Alex Martin',
118
+ email: 'alex@acme.dev',
119
+ profilePicture: 'https://x.test/a.png',
120
+ };
121
+ const btn = render();
122
+ expect(btn?.querySelector('img')?.getAttribute('src')).toBe('https://x.test/a.png');
123
+ expect(btn?.querySelector('[data-shellui-account-initials]')).toBeNull();
124
+ });
125
+
126
+ it('collapsed icon mode hides the text and keeps the avatar', () => {
127
+ auth.user = { name: 'Alex Martin', email: 'alex@acme.dev' };
128
+ const btn = render(false);
129
+ expect(btn?.querySelector('[data-shellui-account-initials]')).not.toBeNull();
130
+ expect(btn?.querySelector('[data-shellui-account-email]')?.parentElement?.className).toContain(
131
+ 'group-data-[collapsible=icon]:hidden',
132
+ );
133
+ expect(btn?.querySelector('svg')?.getAttribute('class')).toContain(
134
+ 'group-data-[collapsible=icon]:hidden',
135
+ );
136
+ });
137
+
138
+ it('renders a two line skeleton while loading', () => {
139
+ auth.isLoading = true;
140
+ render();
141
+ const status = container.querySelector('[data-shellui-auth-loading]');
142
+ expect(status?.getAttribute('aria-label')).toBe(en.authMenu.loadingAccount);
143
+ expect(status?.querySelectorAll('[data-slot="skeleton"], .animate-pulse').length).toBe(3);
144
+ });
145
+ });
146
+
147
+ describe('account aria strings', () => {
148
+ it('exist in en and fr', () => {
149
+ for (const key of ['openAccountMenuAriaLabel', 'openAccountMenuWithEmailAriaLabel'] as const) {
150
+ expect(en.authMenu[key]).toContain('{{name}}');
151
+ expect(fr.authMenu[key]).toContain('{{name}}');
152
+ }
153
+ expect(fr.authMenu.openAccountMenuWithEmailAriaLabel).toContain('{{email}}');
154
+ });
155
+ });
@@ -11,7 +11,7 @@ import { useConfig } from '../../config/useConfig';
11
11
  import { getAdminPath } from '../../admin/config';
12
12
  import { isAdminPath } from '../../admin/utils';
13
13
  import { flattenNavigationItems, getNavPathPrefix } from '../../layouts/utils';
14
- import { LogoutIcon, SidebarCaretIcon } from './LoginButtonIcons';
14
+ import { ChevronsUpDownIcon, LogoutIcon } from './LoginButtonIcons';
15
15
  import {
16
16
  DropdownMenu,
17
17
  DropdownMenuContent,
@@ -24,6 +24,17 @@ import { Skeleton } from '../../../components/ui/skeleton';
24
24
 
25
25
  type LoginButtonVariant = 'sidebar' | 'appbar' | 'windows';
26
26
 
27
+ /** Up to two initials from the name, else the first letter of the email. */
28
+ export function getAccountInitials(name?: string | null, email?: string | null): string {
29
+ const words = (name ?? '').trim().split(/\s+/).filter(Boolean);
30
+ if (words.length > 0) {
31
+ const first = Array.from(words[0])[0] ?? '';
32
+ const last = words.length > 1 ? (Array.from(words[words.length - 1])[0] ?? '') : '';
33
+ return (first + last).toUpperCase();
34
+ }
35
+ return (Array.from((email ?? '').trim())[0] ?? '').toUpperCase();
36
+ }
37
+
27
38
  const AdministrationIcon = ({ className }: { className?: string }) => (
28
39
  <svg
29
40
  xmlns="http://www.w3.org/2000/svg"
@@ -79,13 +90,13 @@ const variantConfig: Record<
79
90
  sidebar: {
80
91
  button: {
81
92
  authenticated:
82
- 'w-full h-8 rounded-md px-2 text-sm text-left text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-2!',
93
+ 'shellui-account-row w-full h-10 gap-2.5 rounded-[var(--shellui-r-row)] px-2 text-[13.5px] text-left text-sidebar-foreground hover:bg-[var(--shellui-nav-hover)] hover:text-sidebar-foreground data-[state=open]:bg-[var(--shellui-nav-hover)] group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-0!',
83
94
  loggedOut:
84
95
  'w-full h-8 rounded-md px-2 text-sm text-left text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-2!',
85
96
  loading:
86
- 'w-full h-8 px-2 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-2!',
97
+ 'shellui-account-row w-full h-10 gap-2.5 px-2 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-0!',
87
98
  },
88
- avatar: 'size-4',
99
+ avatar: 'size-6 text-[10.5px]',
89
100
  menu: { width: 'w-[min(16rem,calc(100vw-1.5rem))]', side: 'right', align: 'start' },
90
101
  showDisplayName: true,
91
102
  showCaret: true,
@@ -98,7 +109,7 @@ const variantConfig: Record<
98
109
  'h-7 max-w-[220px] rounded-md px-2.5 text-xs text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
99
110
  loading: 'size-7 justify-center',
100
111
  },
101
- avatar: 'size-4',
112
+ avatar: 'size-4 text-[10px]',
102
113
  menu: { width: 'w-[min(16rem,calc(100vw-1.5rem))]', side: 'bottom', align: 'end' },
103
114
  showDisplayName: false,
104
115
  showCaret: false,
@@ -111,7 +122,7 @@ const variantConfig: Record<
111
122
  'h-8 max-w-[180px] rounded-md px-2 text-xs text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
112
123
  loading: 'h-8 w-8 justify-center',
113
124
  },
114
- avatar: 'h-4 w-4',
125
+ avatar: 'h-4 w-4 text-[10px]',
115
126
  menu: { width: 'w-[min(15rem,calc(100vw-1.5rem))]', side: 'top', align: 'end' },
116
127
  showDisplayName: false,
117
128
  showCaret: false,
@@ -144,14 +155,22 @@ export const LoginButton = ({
144
155
  return name || email || t('authMenu.userFallback');
145
156
  }, [t, user?.email, user?.name]);
146
157
 
147
- const fallbackInitial = displayName.charAt(0).toUpperCase();
158
+ const name = user?.name?.trim() || '';
159
+ const email = user?.email?.trim() || '';
160
+ const initials = getAccountInitials(name, email) || displayName.charAt(0).toUpperCase();
161
+ // Small avatars (app bar, taskbar) only fit one letter.
162
+ const avatarText = variant === 'sidebar' ? initials : initials.charAt(0);
163
+ const accountAriaLabel =
164
+ name && email
165
+ ? t('authMenu.openAccountMenuWithEmailAriaLabel', { name, email })
166
+ : t('authMenu.openAccountMenuAriaLabel', { name: displayName });
148
167
  const { showDisplayName, showCaret } = currentVariantConfig;
149
168
  const menuSide = variant === 'sidebar' && isMobile ? 'top' : currentVariantConfig.menu.side;
150
169
  const menuAlign = variant === 'sidebar' && isMobile ? 'start' : currentVariantConfig.menu.align;
151
170
  const menuCollisionPadding = isMobile ? 12 : 8;
152
171
 
153
172
  const baseButtonClasses = cn(
154
- 'inline-flex items-center gap-2 min-w-0 shrink-0 transition-colors cursor-pointer',
173
+ 'inline-flex items-center gap-2 min-w-0 shrink-0 transition-colors motion-reduce:transition-none cursor-pointer',
155
174
  'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
156
175
  'disabled:pointer-events-none disabled:opacity-50 disabled:cursor-not-allowed',
157
176
  isAuthenticated
@@ -250,7 +269,10 @@ export const LoginButton = ({
250
269
  >
251
270
  <Skeleton className={cn('shrink-0 rounded-full', currentVariantConfig.avatar)} />
252
271
  {showDisplayName && (
253
- <Skeleton className="h-3 w-24 max-w-full group-data-[collapsible=icon]:hidden" />
272
+ <span className="flex min-w-0 flex-1 flex-col gap-1.5 group-data-[collapsible=icon]:hidden">
273
+ <Skeleton className="h-3 w-24 max-w-full" />
274
+ <Skeleton className="h-2.5 w-32 max-w-full" />
275
+ </span>
254
276
  )}
255
277
  </div>
256
278
  );
@@ -289,13 +311,16 @@ export const LoginButton = ({
289
311
  ref={triggerRef}
290
312
  type="button"
291
313
  className={baseButtonClasses}
292
- title={displayName}
293
- aria-label={t('authMenu.openAccountMenuAriaLabel', { name: displayName })}
314
+ title={name && email ? `${name}\n${email}` : displayName}
315
+ aria-label={accountAriaLabel}
316
+ data-shellui-account-trigger=""
317
+ data-shellui-no-drag=""
294
318
  >
295
319
  {user.profilePicture ? (
296
320
  <img
297
321
  src={user.profilePicture}
298
- alt={displayName}
322
+ alt=""
323
+ aria-hidden
299
324
  className={cn(
300
325
  'shrink-0 overflow-hidden rounded-full border border-sidebar-border object-cover aspect-square',
301
326
  currentVariantConfig.avatar,
@@ -305,30 +330,30 @@ export const LoginButton = ({
305
330
  ) : (
306
331
  <span
307
332
  className={cn(
308
- 'flex shrink-0 aspect-square items-center justify-center overflow-hidden rounded-full border border-sidebar-border bg-muted text-[10px] font-semibold leading-none',
333
+ 'flex shrink-0 aspect-square items-center justify-center overflow-hidden rounded-full border border-sidebar-border bg-sidebar-accent text-sidebar-foreground font-semibold leading-none',
309
334
  currentVariantConfig.avatar,
310
335
  )}
311
336
  aria-hidden
337
+ data-shellui-account-initials=""
312
338
  >
313
- {fallbackInitial}
339
+ {avatarText}
314
340
  </span>
315
341
  )}
316
342
  {showDisplayName && (
317
- <span className="truncate group-data-[collapsible=icon]:hidden">{displayName}</span>
343
+ <span className="flex min-w-0 flex-1 flex-col group-data-[collapsible=icon]:hidden">
344
+ <span className="truncate leading-tight">{displayName}</span>
345
+ {name && email ? (
346
+ <span
347
+ className="truncate text-[11.5px] leading-tight text-[var(--shellui-nav-label)]"
348
+ data-shellui-account-email=""
349
+ >
350
+ {email}
351
+ </span>
352
+ ) : null}
353
+ </span>
318
354
  )}
319
355
  {showCaret && (
320
- <span
321
- aria-hidden
322
- className={cn(
323
- 'ml-auto shrink-0 text-[10px] group-data-[collapsible=icon]:hidden',
324
- isMenuOpen ? 'text-foreground' : 'text-muted-foreground',
325
- )}
326
- >
327
- <SidebarCaretIcon
328
- isOpen={isMenuOpen}
329
- className="h-3 w-3"
330
- />
331
- </span>
356
+ <ChevronsUpDownIcon className="ml-auto size-4 shrink-0 text-[var(--shellui-nav-icon)] group-data-[collapsible=icon]:hidden" />
332
357
  )}
333
358
  </button>
334
359
  </DropdownMenuTrigger>
@@ -1,10 +1,5 @@
1
- export const SidebarCaretIcon = ({
2
- className,
3
- isOpen,
4
- }: {
5
- className?: string;
6
- isOpen: boolean;
7
- }) => (
1
+ /** lucide chevrons-up-down */
2
+ export const ChevronsUpDownIcon = ({ className }: { className?: string }) => (
8
3
  <svg
9
4
  xmlns="http://www.w3.org/2000/svg"
10
5
  width="24"
@@ -18,7 +13,8 @@ export const SidebarCaretIcon = ({
18
13
  className={className}
19
14
  aria-hidden
20
15
  >
21
- {isOpen ? <path d="m15 6-6 6 6 6" /> : <path d="m9 6 6 6-6 6" />}
16
+ <path d="m7 15 5 5 5-5" />
17
+ <path d="m7 9 5-5 5 5" />
22
18
  </svg>
23
19
  );
24
20
 
@@ -5,7 +5,7 @@ import urls from '../../../constants/urls';
5
5
  import { SHELLUI_AUTH_CODE_PARAM } from '../constants/oauth';
6
6
  import {
7
7
  buildAuthUrlWithNext,
8
- buildOAuthSessionRedirectTo,
8
+ resolveOAuthSessionRedirectTo,
9
9
  captureCliCallbackFromSearch,
10
10
  hashHasOAuthTokens,
11
11
  inferAccessPendingErrorCode,
@@ -15,7 +15,7 @@ import {
15
15
  redirectCliCallbackError,
16
16
  redirectToCliCallback,
17
17
  } from '../utils';
18
- import { WEB_PKCE_FLOW_PARAM, isMagicLinkFlowId, takeWebPkceVerifier } from '../utils/webPkce';
18
+ import { WEB_PKCE_FLOW_PARAM, isMagicLinkFlowId, takeWebPkceFlow } from '../utils/webPkce';
19
19
  import {
20
20
  isSilentAuthCallbackFrame,
21
21
  publishSilentAuthCallbackResult,
@@ -231,13 +231,15 @@ export const OAuthCallbackView = () => {
231
231
 
232
232
  let cancelled = false;
233
233
  const runSessionExchange = async () => {
234
- const redirectTo = buildOAuthSessionRedirectTo(
234
+ const pkceFlowId = params.get(WEB_PKCE_FLOW_PARAM);
235
+ const pkceFlow = takeWebPkceFlow(pkceFlowId);
236
+ const codeVerifier = pkceFlow?.verifier ?? undefined;
237
+ const redirectTo = resolveOAuthSessionRedirectTo(
238
+ pkceFlow?.redirectTo,
235
239
  window.location.origin,
236
240
  location.pathname,
237
241
  location.search,
238
242
  );
239
- const pkceFlowId = params.get(WEB_PKCE_FLOW_PARAM);
240
- const codeVerifier = takeWebPkceVerifier(pkceFlowId) ?? undefined;
241
243
  if (!codeVerifier && isMagicLinkFlowId(pkceFlowId)) {
242
244
  // The magic link verifier lives only in the browser that asked for the link.
243
245
  // Do not send the code: it stays unused.
@@ -1,6 +1,9 @@
1
1
  import { describe, expect, test } from 'vitest';
2
2
  import { SHELLUI_AUTH_CODE_PARAM } from '../constants/oauth';
3
- import { buildOAuthSessionRedirectTo } from './buildOAuthSessionRedirectTo';
3
+ import {
4
+ buildOAuthSessionRedirectTo,
5
+ resolveOAuthSessionRedirectTo,
6
+ } from './buildOAuthSessionRedirectTo';
4
7
 
5
8
  describe('buildOAuthSessionRedirectTo', () => {
6
9
  test('strips shellui_auth_code and keeps other query params', () => {
@@ -20,3 +23,41 @@ describe('buildOAuthSessionRedirectTo', () => {
20
23
  ).toBe('http://127.0.0.1:8765/callback');
21
24
  });
22
25
  });
26
+
27
+ describe('resolveOAuthSessionRedirectTo', () => {
28
+ const start =
29
+ 'https://playground.shellui.com/login/callback?provider=github&shellui_pkce_flow=o0123';
30
+
31
+ test('uses the stored start value when the host added a trailing slash', () => {
32
+ expect(
33
+ resolveOAuthSessionRedirectTo(
34
+ start,
35
+ 'https://playground.shellui.com',
36
+ '/login/callback/',
37
+ '?provider=github&shellui_pkce_flow=o0123&shellui_auth_code=abc',
38
+ ),
39
+ ).toBe(start);
40
+ });
41
+
42
+ test('falls back to the current URL when nothing was stored', () => {
43
+ expect(
44
+ resolveOAuthSessionRedirectTo(
45
+ null,
46
+ 'https://playground.shellui.com',
47
+ '/login/callback/',
48
+ '?provider=github&shellui_auth_code=abc',
49
+ ),
50
+ ).toBe('https://playground.shellui.com/login/callback/?provider=github');
51
+ });
52
+
53
+ test('ignores a stored value for another origin', () => {
54
+ expect(
55
+ resolveOAuthSessionRedirectTo(
56
+ 'https://evil.test/login/callback',
57
+ 'https://playground.shellui.com',
58
+ '/login/callback',
59
+ '?shellui_auth_code=abc',
60
+ ),
61
+ ).toBe('https://playground.shellui.com/login/callback');
62
+ });
63
+ });
@@ -15,3 +15,26 @@ export function buildOAuthSessionRedirectTo(
15
15
  url.search = params.toString();
16
16
  return url.toString();
17
17
  }
18
+
19
+ /**
20
+ * Pick the `redirect_to` for the session exchange. Identity compares it exactly
21
+ * with the value sent at sign-in start, so prefer that stored value. A static
22
+ * host can add a trailing slash on the way back (GitHub Pages turns
23
+ * `/login/callback` into `/login/callback/`). Fall back to the current URL when
24
+ * nothing was stored or the stored value is for another origin.
25
+ */
26
+ export function resolveOAuthSessionRedirectTo(
27
+ storedRedirectTo: string | null | undefined,
28
+ origin: string,
29
+ pathname: string,
30
+ search: string,
31
+ ): string {
32
+ if (storedRedirectTo) {
33
+ try {
34
+ if (new URL(storedRedirectTo).origin === origin) return storedRedirectTo;
35
+ } catch {
36
+ // invalid stored value: rebuild from the current URL
37
+ }
38
+ }
39
+ return buildOAuthSessionRedirectTo(origin, pathname, search);
40
+ }
@@ -0,0 +1,29 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { AuthSession } from '../types';
3
+ import { canRestoreStoredSession } from './canRestoreStoredSession';
4
+
5
+ const base = {
6
+ accessToken: '',
7
+ refreshToken: '',
8
+ tokenType: 'bearer',
9
+ expiresAt: Math.floor(Date.now() / 1000) + 3600,
10
+ provider: 'github',
11
+ } as unknown as AuthSession;
12
+
13
+ describe('canRestoreStoredSession', () => {
14
+ it('rejects a profile without tokens, as seen in a new tab', () => {
15
+ expect(canRestoreStoredSession(base, false)).toBe(false);
16
+ });
17
+
18
+ it('accepts a refresh token', () => {
19
+ expect(canRestoreStoredSession({ ...base, refreshToken: 'r' }, false)).toBe(true);
20
+ });
21
+
22
+ it('accepts an access token', () => {
23
+ expect(canRestoreStoredSession({ ...base, accessToken: 'a' }, false)).toBe(true);
24
+ });
25
+
26
+ it('accepts a token-less profile when BFF cookies can refresh it', () => {
27
+ expect(canRestoreStoredSession(base, true)).toBe(true);
28
+ });
29
+ });