@shellui/core 0.5.4-alpha.1 → 0.6.0
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.
- package/README.md +2 -0
- package/package.json +6 -4
- package/schemas/shellui.config.schema.json +104 -64
- package/src/app.tsx +5 -3
- package/src/components/ContentView.tsx +26 -5
- package/src/components/LoadingOverlay.tsx +1 -1
- package/src/components/ui/sonner.spec.tsx +138 -0
- package/src/components/ui/sonner.tsx +5 -5
- package/src/components/ui/switch.tsx +1 -1
- package/src/features/admin/AdminView.tsx +14 -3
- package/src/features/ai/AiBridge.tsx +106 -0
- package/src/features/ai/AiUnavailableResponder.tsx +39 -0
- package/src/features/ai/README.md +52 -0
- package/src/features/ai/ShellAiHost.tsx +24 -0
- package/src/features/ai/adapters/ollama.ts +170 -0
- package/src/features/ai/adapters/promptApi.spec.ts +135 -0
- package/src/features/ai/adapters/promptApi.ts +222 -0
- package/src/features/ai/adapters/webllm.experimental.spec.ts +69 -0
- package/src/features/ai/adapters/webllm.spec.ts +527 -0
- package/src/features/ai/adapters/webllm.ts +142 -0
- package/src/features/ai/aiDisabledResponses.spec.ts +29 -0
- package/src/features/ai/aiDisabledResponses.ts +32 -0
- package/src/features/ai/browserInstallStore.spec.ts +58 -0
- package/src/features/ai/browserInstallStore.ts +76 -0
- package/src/features/ai/catalog.ts +31 -0
- package/src/features/ai/createRegistry.ts +83 -0
- package/src/features/ai/developHarness.spec.ts +108 -0
- package/src/features/ai/developHarness.ts +161 -0
- package/src/features/ai/engine/formatAiError.spec.ts +85 -0
- package/src/features/ai/engine/formatAiError.ts +132 -0
- package/src/features/ai/engine/mapInitProgress.ts +9 -0
- package/src/features/ai/engine/normalizeWebLlmModule.spec.ts +47 -0
- package/src/features/ai/engine/vite-worker.d.ts +6 -0
- package/src/features/ai/engine/webllm.worker.ts +51 -0
- package/src/features/ai/engine/webllmEngine.ts +1011 -0
- package/src/features/ai/handleRequest.spec.ts +288 -0
- package/src/features/ai/handleRequest.ts +325 -0
- package/src/features/ai/isAiFeatureEnabled.spec.ts +15 -0
- package/src/features/ai/isAiFeatureEnabled.ts +9 -0
- package/src/features/ai/promptApiSupport.spec.ts +64 -0
- package/src/features/ai/promptApiSupport.ts +117 -0
- package/src/features/ai/registry.spec.ts +100 -0
- package/src/features/ai/registry.ts +131 -0
- package/src/features/ai/status.spec.ts +92 -0
- package/src/features/ai/status.ts +85 -0
- package/src/features/ai/types.ts +100 -0
- package/src/features/ai/webLlmBrowserSupport.spec.ts +86 -0
- package/src/features/ai/webLlmBrowserSupport.ts +92 -0
- package/src/features/alertDialog/DialogContext.tsx +3 -1
- package/src/features/auth/AuthProvider.tsx +254 -39
- package/src/features/auth/backends/index.ts +8 -0
- package/src/features/auth/backends/shellui.spec.ts +201 -0
- package/src/features/auth/backends/shellui.ts +93 -16
- package/src/features/auth/backends/supabase.ts +8 -0
- package/src/features/auth/backends/types.ts +16 -1
- package/src/features/auth/components/LoginButton.tsx +26 -2
- package/src/features/auth/components/LoginView.tsx +119 -134
- package/src/features/auth/components/OAuthCallbackView.tsx +12 -3
- package/src/features/auth/components/SessionLoadingView.tsx +21 -0
- package/src/features/auth/hooks/useAuth.tsx +12 -0
- package/src/features/auth/shellAccountRequests.ts +76 -0
- package/src/features/auth/utils/authRequestError.spec.ts +11 -0
- package/src/features/auth/utils/authRequestError.ts +10 -1
- package/src/features/auth/utils/authSessionPersistence.spec.ts +11 -0
- package/src/features/auth/utils/authSessionPersistence.ts +12 -0
- package/src/features/auth/utils/index.ts +5 -0
- package/src/features/auth/utils/resolveLoginSettings.spec.ts +33 -0
- package/src/features/auth/utils/resolveLoginSettings.ts +33 -0
- package/src/features/auth/utils/shareInFlight.spec.ts +41 -0
- package/src/features/auth/utils/shareInFlight.ts +14 -0
- package/src/features/config/ConfigProvider.ts +9 -1
- package/src/features/config/types.ts +43 -0
- package/src/features/layouts/appbar/AppBarLayout.tsx +8 -3
- package/src/features/layouts/filterNavigationForAuthState.spec.ts +41 -0
- package/src/features/layouts/floating/FloatingLayout.tsx +9 -4
- package/src/features/layouts/sidebar/SidebarLayout.tsx +9 -4
- package/src/features/layouts/utils.ts +6 -2
- package/src/features/layouts/windows/WindowsLayout.tsx +8 -3
- package/src/features/messaging/MessagingSecurityBootstrap.tsx +6 -6
- package/src/features/security/trustedFrames.spec.ts +65 -0
- package/src/features/security/trustedFrames.ts +52 -0
- package/src/features/settings/SettingsIcons.tsx +17 -0
- package/src/features/settings/SettingsProvider.tsx +28 -3
- package/src/features/settings/SettingsRoutes.tsx +8 -0
- package/src/features/settings/SettingsView.tsx +21 -4
- package/src/features/settings/components/Ai.tsx +830 -0
- package/src/features/settings/components/Develop.tsx +4 -0
- package/src/features/settings/components/Storage.tsx +197 -32
- package/src/features/settings/components/UserSettingsPanel.tsx +160 -12
- package/src/features/settings/components/createUserSettingsRoute.tsx +4 -0
- package/src/features/settings/components/develop/AiTestTools.tsx +231 -0
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +54 -1
- package/src/features/settings/utils/buildSettingsForPropagation.ts +15 -1
- package/src/features/settings/utils/mergePreferencesIntoSettings.spec.ts +6 -0
- package/src/features/settings/utils/shouldShowStorageSettings.spec.ts +49 -0
- package/src/features/settings/utils/shouldShowStorageSettings.ts +19 -0
- package/src/features/storage/uploads/UploadToastCard.tsx +2 -442
- package/src/features/storage/uploads/UploadToaster.tsx +2 -44
- package/src/features/storage/uploads/uploadQueue.ts +128 -308
- package/src/features/storage/uploads/useUploadQueue.ts +7 -3
- package/src/features/transfers/TransferToastCard.tsx +467 -0
- package/src/features/transfers/TransferToaster.tsx +50 -0
- package/src/features/transfers/index.ts +33 -0
- package/src/features/transfers/transferQueue.spec.ts +97 -0
- package/src/features/transfers/transferQueue.ts +442 -0
- package/src/features/transfers/types.ts +38 -0
- package/src/features/transfers/useTransferQueue.ts +30 -0
- package/src/i18n/translations/en/common.json +49 -2
- package/src/i18n/translations/en/settings.json +152 -2
- package/src/i18n/translations/fr/common.json +49 -2
- package/src/i18n/translations/fr/settings.json +152 -2
- package/src/index.css +57 -4
- package/src/index.ts +1 -0
- package/src/routes/components/NavigationItemRoute.tsx +2 -1
|
@@ -18,9 +18,10 @@ import {
|
|
|
18
18
|
getPreferredBackendProvider,
|
|
19
19
|
getProviderVisual,
|
|
20
20
|
isAccessPendingErrorCode,
|
|
21
|
-
|
|
21
|
+
loginErrorMessageKey,
|
|
22
22
|
normalizeNextPath,
|
|
23
23
|
redirectToCliCallback,
|
|
24
|
+
resolveLoginSettings,
|
|
24
25
|
} from '../utils';
|
|
25
26
|
import { AppBrandIcon } from '../../layouts/branding/AppBrandIcon';
|
|
26
27
|
import { DESKTOP_TITLEBAR_HEIGHT_PX } from '../../layouts/chrome/constants';
|
|
@@ -35,6 +36,8 @@ const LOGIN_CHROME_PAD_Y = '2rem';
|
|
|
35
36
|
const LOGIN_BRAND_BELOW_TITLEBAR_GAP = '0.75rem';
|
|
36
37
|
|
|
37
38
|
const LAST_USED_LOGIN_STORAGE_KEY = 'shellui.auth.last_used_login';
|
|
39
|
+
/** Seconds before the user can go back to the form and request another magic link. */
|
|
40
|
+
const MAGIC_LINK_RESEND_COOLDOWN_SECONDS = 60;
|
|
38
41
|
|
|
39
42
|
const SHELLUI_OAUTH_ERROR_PARAM = 'shellui_oauth_error';
|
|
40
43
|
const SHELLUI_OAUTH_ERROR_CODE_PARAM = 'shellui_oauth_error_code';
|
|
@@ -105,30 +108,16 @@ export const LoginView = () => {
|
|
|
105
108
|
sendMagicLink,
|
|
106
109
|
session,
|
|
107
110
|
} = useAuth();
|
|
108
|
-
const configuredSettings = useMemo<AuthSettings>(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const configuredProvidersRaw = Array.isArray(config.backend?.login?.oauthProviders)
|
|
113
|
-
? config.backend.login.oauthProviders
|
|
114
|
-
.filter(
|
|
115
|
-
(provider): provider is string =>
|
|
116
|
-
typeof provider === 'string' && provider.trim() !== '',
|
|
117
|
-
)
|
|
118
|
-
.map((provider) => provider.toLowerCase())
|
|
119
|
-
: [];
|
|
120
|
-
const configuredProviders = Array.from(new Set(configuredProvidersRaw));
|
|
121
|
-
return {
|
|
122
|
-
methods: configuredMethods,
|
|
123
|
-
oauthProviders: configuredProviders,
|
|
124
|
-
oauthClients: [],
|
|
125
|
-
};
|
|
126
|
-
}, [config.backend?.login?.methods, config.backend?.login?.oauthProviders]);
|
|
111
|
+
const configuredSettings = useMemo<AuthSettings>(
|
|
112
|
+
() => resolveLoginSettings(config.backend),
|
|
113
|
+
[config.backend],
|
|
114
|
+
);
|
|
127
115
|
const [oauthLoadingProvider, setOauthLoadingProvider] = useState<string | null>(null);
|
|
128
116
|
const [web3Loading, setWeb3Loading] = useState(false);
|
|
129
117
|
const [magicLinkEmail, setMagicLinkEmail] = useState('');
|
|
130
118
|
const [magicLinkLoading, setMagicLinkLoading] = useState(false);
|
|
131
|
-
const [
|
|
119
|
+
const [magicLinkSentTo, setMagicLinkSentTo] = useState<string | null>(null);
|
|
120
|
+
const [magicLinkCooldown, setMagicLinkCooldown] = useState(0);
|
|
132
121
|
const [magicLinkError, setMagicLinkError] = useState<string | null>(null);
|
|
133
122
|
const [methodError, setMethodError] = useState<string | null>(null);
|
|
134
123
|
const [oauthBounceError, setOauthBounceError] = useState<string | null>(null);
|
|
@@ -170,7 +159,10 @@ export const LoginView = () => {
|
|
|
170
159
|
const path = `${location.pathname}${qs ? `?${qs}` : ''}${location.hash}`;
|
|
171
160
|
navigate(path, { replace: true });
|
|
172
161
|
setOauthLoadingProvider(null);
|
|
173
|
-
const
|
|
162
|
+
const messageKey = loginErrorMessageKey(code);
|
|
163
|
+
const baseMsg = messageKey
|
|
164
|
+
? t(messageKey)
|
|
165
|
+
: rawErr.trim() || t('loginPage.signInCouldNotContinue');
|
|
174
166
|
const hint =
|
|
175
167
|
code === 'redirect_not_allowed'
|
|
176
168
|
? t('loginPage.redirectNotAllowedHint', {
|
|
@@ -226,18 +218,12 @@ export const LoginView = () => {
|
|
|
226
218
|
if (!featuredOAuthProvider) return allOAuthProviders;
|
|
227
219
|
return allOAuthProviders.filter((provider) => provider !== featuredOAuthProvider);
|
|
228
220
|
}, [allOAuthProviders, featuredOAuthProvider, supportsOAuth]);
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
if (featuredMethod === 'magic_link') {
|
|
237
|
-
return (supportsOAuth && otherOAuthProviders.length > 0) || supportsWeb3;
|
|
238
|
-
}
|
|
239
|
-
return false;
|
|
240
|
-
}, [featuredMethod, otherOAuthProviders.length, supportsMagicLink, supportsOAuth, supportsWeb3]);
|
|
221
|
+
const showWeb3Section = supportsWeb3 && featuredMethod !== 'web3';
|
|
222
|
+
const showOAuthSection = supportsOAuth && otherOAuthProviders.length > 0;
|
|
223
|
+
const showMagicLinkSection = supportsMagicLink && featuredMethod !== 'magic_link';
|
|
224
|
+
const hasAlternativeMethods =
|
|
225
|
+
featuredMethod !== null && (showWeb3Section || showOAuthSection || showMagicLinkSection);
|
|
226
|
+
const showMagicLinkDivider = showMagicLinkSection && (showWeb3Section || showOAuthSection);
|
|
241
227
|
const showAlternatives = featuredMethod === null || showAlternativeMethods;
|
|
242
228
|
const alternativesAreCollapsible = featuredMethod !== null && hasAlternativeMethods;
|
|
243
229
|
useEffect(() => {
|
|
@@ -319,11 +305,16 @@ export const LoginView = () => {
|
|
|
319
305
|
[getAuthSettings, supportsWeb3, t],
|
|
320
306
|
);
|
|
321
307
|
|
|
308
|
+
useEffect(() => {
|
|
309
|
+
if (magicLinkCooldown <= 0) return;
|
|
310
|
+
const timer = window.setTimeout(() => setMagicLinkCooldown((seconds) => seconds - 1), 1000);
|
|
311
|
+
return () => window.clearTimeout(timer);
|
|
312
|
+
}, [magicLinkCooldown]);
|
|
313
|
+
|
|
322
314
|
const handleOAuthLogin = async (provider: string) => {
|
|
323
315
|
setMethodError(null);
|
|
324
316
|
setOauthBounceError(null);
|
|
325
317
|
setMagicLinkError(null);
|
|
326
|
-
setMagicLinkMessage(null);
|
|
327
318
|
setOauthLoadingProvider(provider);
|
|
328
319
|
const support = await verifyMethodSupport('oauth', provider);
|
|
329
320
|
if (!support.isSupported) {
|
|
@@ -354,7 +345,6 @@ export const LoginView = () => {
|
|
|
354
345
|
const handleWeb3Login = async () => {
|
|
355
346
|
setMethodError(null);
|
|
356
347
|
setMagicLinkError(null);
|
|
357
|
-
setMagicLinkMessage(null);
|
|
358
348
|
setWeb3Loading(true);
|
|
359
349
|
const support = await verifyMethodSupport('web3');
|
|
360
350
|
if (!support.isSupported) {
|
|
@@ -389,13 +379,11 @@ export const LoginView = () => {
|
|
|
389
379
|
const email = magicLinkEmail.trim();
|
|
390
380
|
if (!email) {
|
|
391
381
|
setMagicLinkError(t('loginPage.enterEmail'));
|
|
392
|
-
setMagicLinkMessage(null);
|
|
393
382
|
setMethodError(null);
|
|
394
383
|
return;
|
|
395
384
|
}
|
|
396
385
|
setMagicLinkLoading(true);
|
|
397
386
|
setMagicLinkError(null);
|
|
398
|
-
setMagicLinkMessage(null);
|
|
399
387
|
setMethodError(null);
|
|
400
388
|
|
|
401
389
|
try {
|
|
@@ -408,8 +396,9 @@ export const LoginView = () => {
|
|
|
408
396
|
if (typeof window !== 'undefined') {
|
|
409
397
|
localStorage.setItem(LAST_USED_LOGIN_STORAGE_KEY, JSON.stringify(rememberedLogin));
|
|
410
398
|
}
|
|
411
|
-
await sendMagicLink(email,
|
|
412
|
-
|
|
399
|
+
await sendMagicLink(email, oauthCallbackPathWithNext);
|
|
400
|
+
setMagicLinkSentTo(email);
|
|
401
|
+
setMagicLinkCooldown(MAGIC_LINK_RESEND_COOLDOWN_SECONDS);
|
|
413
402
|
} catch (err) {
|
|
414
403
|
setMagicLinkError(err instanceof Error ? err.message : t('loginPage.couldNotSendMagicLink'));
|
|
415
404
|
} finally {
|
|
@@ -417,6 +406,80 @@ export const LoginView = () => {
|
|
|
417
406
|
}
|
|
418
407
|
};
|
|
419
408
|
|
|
409
|
+
const magicLinkContent = magicLinkSentTo ? (
|
|
410
|
+
<div
|
|
411
|
+
role="status"
|
|
412
|
+
className="space-y-3 rounded-xl border border-border bg-background p-4 text-center"
|
|
413
|
+
>
|
|
414
|
+
<div className="mx-auto flex size-10 items-center justify-center rounded-full bg-muted text-foreground">
|
|
415
|
+
<svg
|
|
416
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
417
|
+
width="20"
|
|
418
|
+
height="20"
|
|
419
|
+
viewBox="0 0 24 24"
|
|
420
|
+
fill="none"
|
|
421
|
+
stroke="currentColor"
|
|
422
|
+
strokeWidth="2"
|
|
423
|
+
strokeLinecap="round"
|
|
424
|
+
strokeLinejoin="round"
|
|
425
|
+
aria-hidden
|
|
426
|
+
>
|
|
427
|
+
<rect
|
|
428
|
+
width="20"
|
|
429
|
+
height="16"
|
|
430
|
+
x="2"
|
|
431
|
+
y="4"
|
|
432
|
+
rx="2"
|
|
433
|
+
/>
|
|
434
|
+
<path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7" />
|
|
435
|
+
</svg>
|
|
436
|
+
</div>
|
|
437
|
+
<div className="space-y-1">
|
|
438
|
+
<p className="text-sm font-medium text-foreground">{t('loginPage.magicLinkSentTitle')}</p>
|
|
439
|
+
<p className="text-sm text-muted-foreground">
|
|
440
|
+
{t('loginPage.magicLinkSentDescription')}{' '}
|
|
441
|
+
<span className="break-all font-medium text-foreground">{magicLinkSentTo}</span>
|
|
442
|
+
</p>
|
|
443
|
+
</div>
|
|
444
|
+
<Button
|
|
445
|
+
type="button"
|
|
446
|
+
variant="ghost"
|
|
447
|
+
size="sm"
|
|
448
|
+
disabled={magicLinkCooldown > 0}
|
|
449
|
+
onClick={() => setMagicLinkSentTo(null)}
|
|
450
|
+
>
|
|
451
|
+
{magicLinkCooldown > 0
|
|
452
|
+
? t('loginPage.magicLinkChangeEmailIn', { seconds: magicLinkCooldown })
|
|
453
|
+
: t('loginPage.magicLinkChangeEmail')}
|
|
454
|
+
</Button>
|
|
455
|
+
</div>
|
|
456
|
+
) : (
|
|
457
|
+
<form
|
|
458
|
+
className="space-y-2"
|
|
459
|
+
onSubmit={(event) => void handleMagicLinkLogin(event)}
|
|
460
|
+
>
|
|
461
|
+
<input
|
|
462
|
+
id="magic-link-email"
|
|
463
|
+
type="email"
|
|
464
|
+
value={magicLinkEmail}
|
|
465
|
+
onChange={(event) => setMagicLinkEmail(event.target.value)}
|
|
466
|
+
placeholder={t('loginPage.emailPlaceholder')}
|
|
467
|
+
autoComplete="email"
|
|
468
|
+
required
|
|
469
|
+
className="h-10 w-full rounded-md border border-input bg-background px-3 text-sm text-foreground outline-none ring-offset-background focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
470
|
+
/>
|
|
471
|
+
<Button
|
|
472
|
+
type="submit"
|
|
473
|
+
variant="secondary"
|
|
474
|
+
className="w-full"
|
|
475
|
+
disabled={isActionPending || magicLinkCooldown > 0}
|
|
476
|
+
>
|
|
477
|
+
{magicLinkLoading ? t('loginPage.sendingMagicLink') : t('loginPage.sendMagicLink')}
|
|
478
|
+
</Button>
|
|
479
|
+
{magicLinkError && <p className="text-sm text-destructive">{magicLinkError}</p>}
|
|
480
|
+
</form>
|
|
481
|
+
);
|
|
482
|
+
|
|
420
483
|
const panelUrl = useMemo(
|
|
421
484
|
() => validateLoginPanelUrl(config.backend?.login?.panelUrl, config),
|
|
422
485
|
[config],
|
|
@@ -584,35 +647,7 @@ export const LoginView = () => {
|
|
|
584
647
|
<p className="text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
|
585
648
|
{t('loginPage.lastUsed')}
|
|
586
649
|
</p>
|
|
587
|
-
|
|
588
|
-
className="space-y-2"
|
|
589
|
-
onSubmit={(event) => void handleMagicLinkLogin(event)}
|
|
590
|
-
>
|
|
591
|
-
<input
|
|
592
|
-
id="magic-link-email"
|
|
593
|
-
type="email"
|
|
594
|
-
value={magicLinkEmail}
|
|
595
|
-
onChange={(event) => setMagicLinkEmail(event.target.value)}
|
|
596
|
-
placeholder={t('loginPage.emailPlaceholder')}
|
|
597
|
-
autoComplete="email"
|
|
598
|
-
required
|
|
599
|
-
className="h-10 w-full rounded-md border border-input bg-background px-3 text-sm text-foreground outline-none ring-offset-background focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
600
|
-
/>
|
|
601
|
-
<Button
|
|
602
|
-
type="submit"
|
|
603
|
-
variant="secondary"
|
|
604
|
-
className="w-full"
|
|
605
|
-
disabled={isActionPending}
|
|
606
|
-
>
|
|
607
|
-
{magicLinkLoading
|
|
608
|
-
? t('loginPage.sendingMagicLink')
|
|
609
|
-
: t('loginPage.sendMagicLink')}
|
|
610
|
-
</Button>
|
|
611
|
-
{magicLinkMessage && (
|
|
612
|
-
<p className="text-sm text-muted-foreground">{magicLinkMessage}</p>
|
|
613
|
-
)}
|
|
614
|
-
{magicLinkError && <p className="text-sm text-destructive">{magicLinkError}</p>}
|
|
615
|
-
</form>
|
|
650
|
+
{magicLinkContent}
|
|
616
651
|
</section>
|
|
617
652
|
)}
|
|
618
653
|
|
|
@@ -681,7 +716,8 @@ export const LoginView = () => {
|
|
|
681
716
|
: 'grid-rows-[1fr] opacity-100',
|
|
682
717
|
)}
|
|
683
718
|
>
|
|
684
|
-
|
|
719
|
+
{/* Inset matches focus ring + offset (4px) so overflow-hidden does not clip it. */}
|
|
720
|
+
<div className="-m-1 min-h-0 overflow-hidden p-1">
|
|
685
721
|
<div
|
|
686
722
|
className={cn(
|
|
687
723
|
'space-y-4 transition-transform duration-500 ease-out',
|
|
@@ -690,26 +726,7 @@ export const LoginView = () => {
|
|
|
690
726
|
: 'translate-y-0',
|
|
691
727
|
)}
|
|
692
728
|
>
|
|
693
|
-
{
|
|
694
|
-
(otherOAuthProviders.length > 0 || supportsMagicLink || supportsWeb3) && (
|
|
695
|
-
<div className="relative py-1">
|
|
696
|
-
<div className="border-t border-border" />
|
|
697
|
-
<span className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 bg-background px-2 text-xs text-muted-foreground">
|
|
698
|
-
{t('loginPage.or')}
|
|
699
|
-
</span>
|
|
700
|
-
</div>
|
|
701
|
-
)}
|
|
702
|
-
|
|
703
|
-
{featuredMethod === 'magic_link' && (supportsOAuth || supportsWeb3) && (
|
|
704
|
-
<div className="relative py-1">
|
|
705
|
-
<div className="border-t border-border" />
|
|
706
|
-
<span className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 bg-background px-2 text-xs text-muted-foreground">
|
|
707
|
-
{t('loginPage.or')}
|
|
708
|
-
</span>
|
|
709
|
-
</div>
|
|
710
|
-
)}
|
|
711
|
-
|
|
712
|
-
{featuredMethod === 'web3' && (supportsOAuth || supportsMagicLink) && (
|
|
729
|
+
{hasAlternativeMethods && (
|
|
713
730
|
<div className="relative py-1">
|
|
714
731
|
<div className="border-t border-border" />
|
|
715
732
|
<span className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 bg-background px-2 text-xs text-muted-foreground">
|
|
@@ -718,7 +735,7 @@ export const LoginView = () => {
|
|
|
718
735
|
</div>
|
|
719
736
|
)}
|
|
720
737
|
|
|
721
|
-
{
|
|
738
|
+
{showWeb3Section && (
|
|
722
739
|
<section className="space-y-2">
|
|
723
740
|
<p className="text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
|
724
741
|
{t('loginPage.walletLogin')}
|
|
@@ -750,7 +767,7 @@ export const LoginView = () => {
|
|
|
750
767
|
</section>
|
|
751
768
|
)}
|
|
752
769
|
|
|
753
|
-
{
|
|
770
|
+
{showOAuthSection && (
|
|
754
771
|
<section className="space-y-2">
|
|
755
772
|
<p className="text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
|
756
773
|
{featuredMethod === 'oauth'
|
|
@@ -793,53 +810,21 @@ export const LoginView = () => {
|
|
|
793
810
|
</section>
|
|
794
811
|
)}
|
|
795
812
|
|
|
796
|
-
{
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
<
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
</div>
|
|
805
|
-
)}
|
|
813
|
+
{showMagicLinkDivider && (
|
|
814
|
+
<div className="relative py-1">
|
|
815
|
+
<div className="border-t border-border" />
|
|
816
|
+
<span className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 bg-background px-2 text-xs text-muted-foreground">
|
|
817
|
+
{t('loginPage.or')}
|
|
818
|
+
</span>
|
|
819
|
+
</div>
|
|
820
|
+
)}
|
|
806
821
|
|
|
807
|
-
{
|
|
822
|
+
{showMagicLinkSection && (
|
|
808
823
|
<section className="space-y-2">
|
|
809
824
|
<p className="text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
|
810
825
|
{t('loginPage.emailMagicLink')}
|
|
811
826
|
</p>
|
|
812
|
-
|
|
813
|
-
className="space-y-2"
|
|
814
|
-
onSubmit={(event) => void handleMagicLinkLogin(event)}
|
|
815
|
-
>
|
|
816
|
-
<input
|
|
817
|
-
id="magic-link-email"
|
|
818
|
-
type="email"
|
|
819
|
-
value={magicLinkEmail}
|
|
820
|
-
onChange={(event) => setMagicLinkEmail(event.target.value)}
|
|
821
|
-
placeholder={t('loginPage.emailPlaceholder')}
|
|
822
|
-
autoComplete="email"
|
|
823
|
-
required
|
|
824
|
-
className="h-10 w-full rounded-md border border-input bg-background px-3 text-sm text-foreground outline-none ring-offset-background focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
825
|
-
/>
|
|
826
|
-
<Button
|
|
827
|
-
type="submit"
|
|
828
|
-
variant="secondary"
|
|
829
|
-
className="w-full"
|
|
830
|
-
disabled={isActionPending}
|
|
831
|
-
>
|
|
832
|
-
{magicLinkLoading
|
|
833
|
-
? t('loginPage.sendingMagicLink')
|
|
834
|
-
: t('loginPage.sendMagicLink')}
|
|
835
|
-
</Button>
|
|
836
|
-
{magicLinkMessage && (
|
|
837
|
-
<p className="text-sm text-muted-foreground">{magicLinkMessage}</p>
|
|
838
|
-
)}
|
|
839
|
-
{magicLinkError && (
|
|
840
|
-
<p className="text-sm text-destructive">{magicLinkError}</p>
|
|
841
|
-
)}
|
|
842
|
-
</form>
|
|
827
|
+
{magicLinkContent}
|
|
843
828
|
</section>
|
|
844
829
|
)}
|
|
845
830
|
</div>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
2
3
|
import { useLocation, useNavigate } from 'react-router';
|
|
3
4
|
import urls from '../../../constants/urls';
|
|
4
5
|
import { SHELLUI_AUTH_CODE_PARAM } from '../constants/oauth';
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
hashHasOAuthTokens,
|
|
10
11
|
inferAccessPendingErrorCode,
|
|
11
12
|
isAccessPendingErrorCode,
|
|
13
|
+
loginErrorMessageKey,
|
|
12
14
|
normalizeNextPath,
|
|
13
15
|
redirectCliCallbackError,
|
|
14
16
|
redirectToCliCallback,
|
|
@@ -85,6 +87,7 @@ const looksLikeUsedOAuthCode = (message: string | null | undefined) => {
|
|
|
85
87
|
export const OAuthCallbackView = () => {
|
|
86
88
|
const location = useLocation();
|
|
87
89
|
const navigate = useNavigate();
|
|
90
|
+
const { t } = useTranslation();
|
|
88
91
|
const {
|
|
89
92
|
completeOAuthCallback,
|
|
90
93
|
completeOAuthSessionCallback,
|
|
@@ -137,13 +140,15 @@ export const OAuthCallbackView = () => {
|
|
|
137
140
|
const bounceError = params.get(SHELLUI_OAUTH_ERROR_PARAM);
|
|
138
141
|
if (bounceError) {
|
|
139
142
|
const bounceCode = params.get(SHELLUI_OAUTH_ERROR_CODE_PARAM) || 'oauth_error';
|
|
140
|
-
|
|
143
|
+
const messageKey = loginErrorMessageKey(bounceCode);
|
|
144
|
+
const displayError = messageKey ? t(messageKey) : bounceError;
|
|
145
|
+
if (redirectCliCallbackError(displayError, bounceCode)) return;
|
|
141
146
|
if (isAccessPendingErrorCode(bounceCode)) {
|
|
142
147
|
setPendingAccess({ message: bounceError, code: bounceCode });
|
|
143
148
|
setIsWorking(false);
|
|
144
149
|
return;
|
|
145
150
|
}
|
|
146
|
-
setLocalError(
|
|
151
|
+
setLocalError(displayError);
|
|
147
152
|
setIsWorking(false);
|
|
148
153
|
return;
|
|
149
154
|
}
|
|
@@ -189,7 +194,10 @@ export const OAuthCallbackView = () => {
|
|
|
189
194
|
return;
|
|
190
195
|
}
|
|
191
196
|
|
|
192
|
-
const
|
|
197
|
+
const messageKey = loginErrorMessageKey(result.errorCode);
|
|
198
|
+
const message = messageKey
|
|
199
|
+
? t(messageKey)
|
|
200
|
+
: (result.error ?? 'Unable to complete OAuth login.');
|
|
193
201
|
if (redirectCliCallbackError(message, result.errorCode)) return;
|
|
194
202
|
setLocalError(message);
|
|
195
203
|
setIsWorking(false);
|
|
@@ -310,6 +318,7 @@ export const OAuthCallbackView = () => {
|
|
|
310
318
|
location.search,
|
|
311
319
|
navigate,
|
|
312
320
|
nextPath,
|
|
321
|
+
t,
|
|
313
322
|
]);
|
|
314
323
|
|
|
315
324
|
const backToLogin = () => {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next';
|
|
2
|
+
|
|
3
|
+
/** Full-area spinner shown while the first session restore resolves (e.g. after a reload). */
|
|
4
|
+
export const SessionLoadingView = () => {
|
|
5
|
+
const { t } = useTranslation('common');
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<div
|
|
9
|
+
role="status"
|
|
10
|
+
aria-live="polite"
|
|
11
|
+
data-shellui-session-loading=""
|
|
12
|
+
className="flex h-full w-full flex-col items-center justify-center gap-3 p-6"
|
|
13
|
+
>
|
|
14
|
+
<div
|
|
15
|
+
className="size-6 shrink-0 animate-spin rounded-full border-2 border-muted-foreground/25 border-t-muted-foreground"
|
|
16
|
+
aria-hidden
|
|
17
|
+
/>
|
|
18
|
+
<p className="text-sm text-muted-foreground">{t('sessionLoading')}</p>
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
@@ -13,6 +13,10 @@ export interface AuthContextValue {
|
|
|
13
13
|
session: AuthSession | null;
|
|
14
14
|
user: AuthUser | null;
|
|
15
15
|
isAuthenticated: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* True while the first session restore is in flight (e.g. refresh-token exchange after a page
|
|
18
|
+
* reload). Background token refreshes never set it, so UI can show loading placeholders safely.
|
|
19
|
+
*/
|
|
16
20
|
isLoading: boolean;
|
|
17
21
|
error: string | null;
|
|
18
22
|
errorCode: string | null;
|
|
@@ -35,6 +39,14 @@ export interface AuthContextValue {
|
|
|
35
39
|
syncUserPreferences: (preferences: UserPreferences) => Promise<void>;
|
|
36
40
|
loadUserPreferences: () => Promise<UserPreferences | null>;
|
|
37
41
|
logout: () => Promise<void>;
|
|
42
|
+
/** Whether the configured auth backend supports self-service account deletion. */
|
|
43
|
+
supportsAccountDeletion: boolean;
|
|
44
|
+
/** Delete the signed-in account for the current company, then sign out. */
|
|
45
|
+
deleteAccount: () => Promise<void>;
|
|
46
|
+
/** Whether the configured auth backend supports editing the display name. */
|
|
47
|
+
supportsProfileUpdate: boolean;
|
|
48
|
+
/** Update the signed-in user's display name and the local session. */
|
|
49
|
+
updateProfile: (profile: { name: string }) => Promise<{ name: string }>;
|
|
38
50
|
}
|
|
39
51
|
|
|
40
52
|
export const AuthContext = createContext<AuthContextValue | null>(null);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { postShellMessage, shellui, type ShellUIMessage } from '@shellui/sdk';
|
|
2
|
+
|
|
3
|
+
type ShellUIMessageType = ShellUIMessage['type'];
|
|
4
|
+
|
|
5
|
+
export type DeleteAccountResultStatus = 'deleted' | 'cancelled' | 'error';
|
|
6
|
+
|
|
7
|
+
export type UpdateProfileResult =
|
|
8
|
+
| { status: 'saved'; name: string }
|
|
9
|
+
| { status: 'error'; error?: string };
|
|
10
|
+
|
|
11
|
+
/** The delete confirmation dialog stays open until the user answers, so only give up after a long wait. */
|
|
12
|
+
const DELETE_RESULT_TIMEOUT_MS = 10 * 60_000;
|
|
13
|
+
const UPDATE_PROFILE_TIMEOUT_MS = 30_000;
|
|
14
|
+
|
|
15
|
+
const createRequestId = (): string =>
|
|
16
|
+
typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function'
|
|
17
|
+
? crypto.randomUUID()
|
|
18
|
+
: `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Post an account request to the top-level shell (which owns the session) and resolve with
|
|
22
|
+
* the payload of the matching result message, or `null` on timeout.
|
|
23
|
+
*/
|
|
24
|
+
function requestFromShell(
|
|
25
|
+
requestType: ShellUIMessageType,
|
|
26
|
+
resultType: ShellUIMessageType,
|
|
27
|
+
payload: Record<string, unknown>,
|
|
28
|
+
timeoutMs: number,
|
|
29
|
+
): Promise<Record<string, unknown> | null> {
|
|
30
|
+
const id = createRequestId();
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
let settled = false;
|
|
33
|
+
const finish = (result: Record<string, unknown> | null) => {
|
|
34
|
+
if (settled) return;
|
|
35
|
+
settled = true;
|
|
36
|
+
clearTimeout(timer);
|
|
37
|
+
cleanup();
|
|
38
|
+
resolve(result);
|
|
39
|
+
};
|
|
40
|
+
const cleanup = shellui.addMessageListener(resultType, (message: ShellUIMessage) => {
|
|
41
|
+
const result = message.payload as Record<string, unknown> | undefined;
|
|
42
|
+
if (result?.id === id) finish(result);
|
|
43
|
+
});
|
|
44
|
+
const timer = setTimeout(() => finish(null), timeoutMs);
|
|
45
|
+
postShellMessage({ type: requestType, payload: { ...payload, id } });
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Ask the shell to confirm and delete the signed-in account for the current company. */
|
|
50
|
+
export async function requestAccountDeletion(): Promise<DeleteAccountResultStatus> {
|
|
51
|
+
const result = await requestFromShell(
|
|
52
|
+
'SHELLUI_DELETE_ACCOUNT_REQUEST',
|
|
53
|
+
'SHELLUI_DELETE_ACCOUNT_RESULT',
|
|
54
|
+
{},
|
|
55
|
+
DELETE_RESULT_TIMEOUT_MS,
|
|
56
|
+
);
|
|
57
|
+
const status = result?.status;
|
|
58
|
+
return status === 'deleted' || status === 'cancelled' ? status : 'error';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Ask the shell to update the signed-in user's display name. */
|
|
62
|
+
export async function requestProfileUpdate(name: string): Promise<UpdateProfileResult> {
|
|
63
|
+
const result = await requestFromShell(
|
|
64
|
+
'SHELLUI_UPDATE_PROFILE_REQUEST',
|
|
65
|
+
'SHELLUI_UPDATE_PROFILE_RESULT',
|
|
66
|
+
{ name },
|
|
67
|
+
UPDATE_PROFILE_TIMEOUT_MS,
|
|
68
|
+
);
|
|
69
|
+
if (result?.status === 'saved' && typeof result.name === 'string') {
|
|
70
|
+
return { status: 'saved', name: result.name };
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
status: 'error',
|
|
74
|
+
error: typeof result?.error === 'string' ? result.error : undefined,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
getAuthRequestErrorCode,
|
|
5
5
|
inferAccessPendingErrorCode,
|
|
6
6
|
isAccessPendingErrorCode,
|
|
7
|
+
loginErrorMessageKey,
|
|
7
8
|
} from './authRequestError';
|
|
8
9
|
|
|
9
10
|
describe('isAccessPendingErrorCode', () => {
|
|
@@ -15,6 +16,16 @@ describe('isAccessPendingErrorCode', () => {
|
|
|
15
16
|
});
|
|
16
17
|
});
|
|
17
18
|
|
|
19
|
+
describe('loginErrorMessageKey', () => {
|
|
20
|
+
it('maps staff magic-link refusal to the login copy key', () => {
|
|
21
|
+
expect(loginErrorMessageKey('magic_link_staff_disabled')).toBe(
|
|
22
|
+
'loginPage.magicLinkStaffDisabled',
|
|
23
|
+
);
|
|
24
|
+
expect(loginErrorMessageKey('redirect_not_allowed')).toBe(null);
|
|
25
|
+
expect(loginErrorMessageKey(null)).toBe(null);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
18
29
|
describe('AuthRequestError', () => {
|
|
19
30
|
it('stores optional error code', () => {
|
|
20
31
|
const err = new AuthRequestError('Waiting for approval.', 'access_pending');
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export class AuthRequestError extends Error {
|
|
2
2
|
readonly code: string | null;
|
|
3
|
+
/** Extra fields from the error response body (e.g. `companies` for `last_company_owner`). */
|
|
4
|
+
readonly details: Record<string, unknown>;
|
|
3
5
|
|
|
4
|
-
constructor(message: string, code?: string | null) {
|
|
6
|
+
constructor(message: string, code?: string | null, details?: Record<string, unknown>) {
|
|
5
7
|
super(message);
|
|
6
8
|
this.name = 'AuthRequestError';
|
|
7
9
|
this.code = typeof code === 'string' && code.trim() ? code.trim() : null;
|
|
10
|
+
this.details = details ?? {};
|
|
8
11
|
}
|
|
9
12
|
}
|
|
10
13
|
|
|
@@ -13,6 +16,12 @@ export function isAccessPendingErrorCode(code: string | null | undefined): boole
|
|
|
13
16
|
return code === 'access_pending' || code === 'access_denied';
|
|
14
17
|
}
|
|
15
18
|
|
|
19
|
+
/** i18n key when the shell replaces a backend sign-in sentence with its own copy. */
|
|
20
|
+
export function loginErrorMessageKey(code: string | null | undefined): string | null {
|
|
21
|
+
if (code === 'magic_link_staff_disabled') return 'loginPage.magicLinkStaffDisabled';
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
16
25
|
/** Duck-type safe: `instanceof` can fail across duplicated bundles. */
|
|
17
26
|
export function getAuthRequestErrorCode(err: unknown): string | null {
|
|
18
27
|
if (!err || typeof err !== 'object') return null;
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from './authStorageKeys';
|
|
8
8
|
import {
|
|
9
9
|
clearStoredAuthSession,
|
|
10
|
+
hasStoredAuthSession,
|
|
10
11
|
persistAuthSession,
|
|
11
12
|
readStoredAuthSession,
|
|
12
13
|
} from './authSessionPersistence';
|
|
@@ -84,6 +85,16 @@ describe('authSessionPersistence', () => {
|
|
|
84
85
|
expect(localStorage.setItem).toHaveBeenCalledWith(AUTH_PROFILE_STORAGE_KEY, expect.any(String));
|
|
85
86
|
});
|
|
86
87
|
|
|
88
|
+
it('reports a stored session only when a profile or legacy snapshot exists', () => {
|
|
89
|
+
expect(hasStoredAuthSession()).toBe(false);
|
|
90
|
+
persistAuthSession(sampleSession());
|
|
91
|
+
expect(hasStoredAuthSession()).toBe(true);
|
|
92
|
+
clearStoredAuthSession();
|
|
93
|
+
expect(hasStoredAuthSession()).toBe(false);
|
|
94
|
+
localStorage.setItem(LEGACY_AUTH_SESSION_STORAGE_KEY, JSON.stringify(sampleSession()));
|
|
95
|
+
expect(hasStoredAuthSession()).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
|
|
87
98
|
it('clears profile, refresh, and legacy keys', () => {
|
|
88
99
|
clearStoredAuthSession();
|
|
89
100
|
expect(localStorage.removeItem).toHaveBeenCalledWith(AUTH_PROFILE_STORAGE_KEY);
|
|
@@ -124,6 +124,18 @@ export const readStoredAuthSession = (): AuthSession | null => {
|
|
|
124
124
|
return mergeProfileAndTokens(profile, '', refreshToken);
|
|
125
125
|
};
|
|
126
126
|
|
|
127
|
+
/** Whether a session snapshot exists to restore, without migrating or mutating storage. */
|
|
128
|
+
export const hasStoredAuthSession = (): boolean => {
|
|
129
|
+
try {
|
|
130
|
+
return (
|
|
131
|
+
localStorage.getItem(AUTH_PROFILE_STORAGE_KEY) !== null ||
|
|
132
|
+
localStorage.getItem(LEGACY_AUTH_SESSION_STORAGE_KEY) !== null
|
|
133
|
+
);
|
|
134
|
+
} catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
127
139
|
/** Remove all persisted auth keys (profile, refresh, legacy). */
|
|
128
140
|
export const clearStoredAuthSession = () => {
|
|
129
141
|
writeProfile(null);
|