@krak-stack/auth 0.2.7 → 0.2.8
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/dist/components/member-required.js +21 -23
- package/dist/components/organization-switcher.d.ts +4 -2
- package/dist/components/organization-switcher.js +77 -96
- package/dist/components/user-button.d.ts +22 -6
- package/dist/components/user-button.js +171 -120
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/proxy-origin.d.ts +17 -0
- package/dist/server/proxy-origin.js +41 -0
- package/dist/server/proxy.d.ts +5 -3
- package/dist/server/proxy.js +16 -11
- package/dist/server/schema.d.ts +5 -0
- package/dist/server/schema.js +5 -0
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useAtomRefresh, useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
2
|
+
import { RegistryContext, useAtomRefresh, useAtomSet, useAtomValue, } from "@effect/atom-react";
|
|
3
3
|
import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
|
|
4
4
|
import { useNavigate, useRouterState, } from "@tanstack/react-router";
|
|
5
5
|
import { Effect, Option, Predicate, Schema } from "effect";
|
|
6
|
-
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
7
|
-
import { ArrowLeft, Building2, KeyRound, Loader2, LogOutIcon, Pencil, Plus, ShieldCheck, StopCircle, Trash2, UserCircleIcon, Users, UserIcon, } from "lucide-react";
|
|
6
|
+
import { AsyncResult, Atom, AtomRegistry } from "effect/unstable/reactivity";
|
|
7
|
+
import { ArrowLeft, Building2, KeyRound, Loader2, LogOutIcon, Mail, Pencil, Plus, ShieldCheck, StopCircle, Trash2, UserCircleIcon, Users, UserIcon, } from "lucide-react";
|
|
8
8
|
import { QRCode } from "react-qr-code";
|
|
9
|
-
import { createContext, useContext, useRef, useState, } from "react";
|
|
9
|
+
import { createContext, useContext, useRef, useEffect, useState, } from "react";
|
|
10
10
|
import { DataTable, DataTableListSummary, } from "@krak-stack/registry/data-table";
|
|
11
11
|
import { AppBrand } from "@krak-stack/registry/app-brand";
|
|
12
12
|
import { EditingLocaleSwitcher } from "@krak-stack/registry/editing-locale-switcher";
|
|
@@ -14,7 +14,7 @@ import { effectFormMessages, ImageField, SubmitButton, SubmitError, TextAreaFiel
|
|
|
14
14
|
import { Badge } from "@/components/ui/badge";
|
|
15
15
|
import { Button } from "@/components/ui/button";
|
|
16
16
|
import { CopyButton } from "@krak-stack/registry/copy-button";
|
|
17
|
-
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
|
17
|
+
import { Dialog, DialogContent, DialogFooter, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
|
18
18
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
19
19
|
import { Separator } from "@/components/ui/separator";
|
|
20
20
|
import { authClientApi, authHttpClient } from "./auth-client-api.js";
|
|
@@ -36,10 +36,13 @@ const messages = {
|
|
|
36
36
|
en: {
|
|
37
37
|
table_empty: "No results.",
|
|
38
38
|
user_account_cancel: "Cancel",
|
|
39
|
+
user_account_back: "Back",
|
|
40
|
+
user_two_factor_manage: "Manage",
|
|
41
|
+
user_account_change: "Change",
|
|
39
42
|
user_account_confirm_revoke: "Revoke account",
|
|
40
43
|
user_account_connected: "Connected",
|
|
41
44
|
user_account_current_password: "Current password",
|
|
42
|
-
user_account_google_connect: "
|
|
45
|
+
user_account_google_connect: "Set up",
|
|
43
46
|
user_account_google_description: "Use your Google account as a sign-in option.",
|
|
44
47
|
user_account_google_link_error: "Could not connect Google.",
|
|
45
48
|
user_account_google_title: "Google",
|
|
@@ -54,15 +57,19 @@ const messages = {
|
|
|
54
57
|
user_account_password_connected_description: "Password sign-in is enabled for this account.",
|
|
55
58
|
user_account_password_description: "Use an email and password as a sign-in option.",
|
|
56
59
|
user_account_password_set: "Set password",
|
|
60
|
+
user_account_password_setup: "Set up",
|
|
57
61
|
user_account_password_set_error: "Could not set your password.",
|
|
58
62
|
user_account_password_title: "Password",
|
|
59
63
|
user_account_password_verify_error: "Could not verify your password.",
|
|
60
64
|
user_account_revoke: "Revoke",
|
|
61
65
|
user_account_revoke_description: "Revoke {provider} from this account. You will not be able to use it to sign in unless you connect it again.",
|
|
62
66
|
user_account_revoke_error: "Could not revoke this account.",
|
|
63
|
-
user_accounts_description: "
|
|
67
|
+
user_accounts_description: "Manage your password and connected accounts.",
|
|
64
68
|
user_accounts_load_error: "Could not load connected accounts.",
|
|
65
|
-
user_accounts_title: "
|
|
69
|
+
user_accounts_title: "Sign-in methods",
|
|
70
|
+
user_account_email_otp_title: "Email OTP",
|
|
71
|
+
user_account_email_otp_status: "Always available",
|
|
72
|
+
user_account_email_otp_description: "Sign in with a one-time code sent to your email.",
|
|
66
73
|
user_api_key_copied: "Copied",
|
|
67
74
|
user_api_key_copy: "Copy",
|
|
68
75
|
user_api_key_back: "Back",
|
|
@@ -153,6 +160,7 @@ const messages = {
|
|
|
153
160
|
user_two_factor_disabled_message: "Two-factor authentication is disabled.",
|
|
154
161
|
user_two_factor_enable_error: "Could not start two-factor setup.",
|
|
155
162
|
user_two_factor_enable_submit: "Enable",
|
|
163
|
+
user_confirm_password: "Confirm password",
|
|
156
164
|
user_two_factor_enabled: "Enabled",
|
|
157
165
|
user_two_factor_enabled_message: "Two-factor authentication is enabled.",
|
|
158
166
|
user_two_factor_scan_description: "Add this account to your authenticator app, then enter the generated code below.",
|
|
@@ -163,10 +171,13 @@ const messages = {
|
|
|
163
171
|
fr: {
|
|
164
172
|
table_empty: "Aucun résultat.",
|
|
165
173
|
user_account_cancel: "Annuler",
|
|
174
|
+
user_account_back: "Retour",
|
|
175
|
+
user_two_factor_manage: "Gérer",
|
|
176
|
+
user_account_change: "Modifier",
|
|
166
177
|
user_account_confirm_revoke: "Révoquer le compte",
|
|
167
178
|
user_account_connected: "Connecté",
|
|
168
179
|
user_account_current_password: "Mot de passe actuel",
|
|
169
|
-
user_account_google_connect: "
|
|
180
|
+
user_account_google_connect: "Configurer",
|
|
170
181
|
user_account_google_description: "Utilisez votre compte Google comme option de connexion.",
|
|
171
182
|
user_account_google_link_error: "Impossible de connecter Google.",
|
|
172
183
|
user_account_google_title: "Google",
|
|
@@ -181,15 +192,19 @@ const messages = {
|
|
|
181
192
|
user_account_password_connected_description: "La connexion par mot de passe est activée pour ce compte.",
|
|
182
193
|
user_account_password_description: "Utilisez un courriel et un mot de passe comme option de connexion.",
|
|
183
194
|
user_account_password_set: "Définir le mot de passe",
|
|
195
|
+
user_account_password_setup: "Configurer",
|
|
184
196
|
user_account_password_set_error: "Impossible de définir votre mot de passe.",
|
|
185
197
|
user_account_password_title: "Mot de passe",
|
|
186
198
|
user_account_password_verify_error: "Impossible de vérifier votre mot de passe.",
|
|
187
199
|
user_account_revoke: "Révoquer",
|
|
188
200
|
user_account_revoke_description: "Révoquez {provider} de ce compte. Vous ne pourrez plus l'utiliser pour vous connecter, sauf si vous le reconnectez.",
|
|
189
201
|
user_account_revoke_error: "Impossible de révoquer ce compte.",
|
|
190
|
-
user_accounts_description: "
|
|
202
|
+
user_accounts_description: "Gérez votre mot de passe et vos comptes connectés.",
|
|
191
203
|
user_accounts_load_error: "Impossible de charger les comptes connectés.",
|
|
192
|
-
user_accounts_title: "
|
|
204
|
+
user_accounts_title: "Méthodes de connexion",
|
|
205
|
+
user_account_email_otp_title: "Code à usage unique par e-mail",
|
|
206
|
+
user_account_email_otp_status: "Toujours disponible",
|
|
207
|
+
user_account_email_otp_description: "Connectez-vous avec un code à usage unique envoyé à votre adresse e-mail.",
|
|
193
208
|
user_api_key_copied: "Copié",
|
|
194
209
|
user_api_key_copy: "Copier",
|
|
195
210
|
user_api_key_back: "Retour",
|
|
@@ -280,6 +295,7 @@ const messages = {
|
|
|
280
295
|
user_two_factor_disabled_message: "L'authentification à deux facteurs est désactivée.",
|
|
281
296
|
user_two_factor_enable_error: "Impossible de démarrer la configuration à deux facteurs.",
|
|
282
297
|
user_two_factor_enable_submit: "Activer",
|
|
298
|
+
user_confirm_password: "Confirmer le mot de passe",
|
|
283
299
|
user_two_factor_enabled: "Activée",
|
|
284
300
|
user_two_factor_enabled_message: "L'authentification à deux facteurs est activée.",
|
|
285
301
|
user_two_factor_scan_description: "Ajoutez ce compte à votre application d'authentification, puis saisissez le code généré ci-dessous.",
|
|
@@ -434,9 +450,9 @@ const uploadUserImageAsset = (file, m, baseUrl) => {
|
|
|
434
450
|
return authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.authExtra.uploadUserImage({ payload })), Effect.flatMap(Schema.decodeUnknownEffect(ExtraUploadedAsset)), Effect.mapError(() => new Error(m.user_profile_image_upload_error())));
|
|
435
451
|
};
|
|
436
452
|
const requiresPasswordForAccountRevoke = (accounts) => accounts.some((account) => account.providerId === "credential");
|
|
437
|
-
const userAccountsAtom = Atom.family((baseUrl) => Atom.keepAlive(Atom.map(authClientApi(baseUrl).query("auth", "listAccounts", {
|
|
453
|
+
const userAccountsAtom = Atom.family((baseUrl) => Atom.optimistic(Atom.keepAlive(Atom.map(authClientApi(baseUrl).query("auth", "listAccounts", {
|
|
438
454
|
reactivityKeys: ["user-accounts", baseUrl],
|
|
439
|
-
}), AsyncResult.map((accounts) => Array.from(accounts)))));
|
|
455
|
+
}), AsyncResult.map((accounts) => Array.from(accounts))))));
|
|
440
456
|
const emptyAccountsAtom = Atom.make(Effect.succeed(Array()));
|
|
441
457
|
const userApiKeysAtom = Atom.family((baseUrl) => Atom.keepAlive(Atom.map(authClientApi(baseUrl).query("auth", "apiKeyList", {
|
|
442
458
|
query: { configId: "user" },
|
|
@@ -464,6 +480,11 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
|
|
|
464
480
|
const isPending = sessionResult.waiting;
|
|
465
481
|
const [uncontrolledDialog, setUncontrolledDialog] = useState(defaultDialog);
|
|
466
482
|
const [isStoppingImpersonation, setIsStoppingImpersonation] = useState(false);
|
|
483
|
+
const [changingPassword, setChangingPassword] = useState(false);
|
|
484
|
+
const [settingPassword, setSettingPassword] = useState(false);
|
|
485
|
+
const [totpSetup, setTotpSetup] = useState(null);
|
|
486
|
+
const [managingTwoFactor, setManagingTwoFactor] = useState(false);
|
|
487
|
+
const [revokingAccount, setRevokingAccount] = useState(null);
|
|
467
488
|
const settingsDialog = controlledDialog !== undefined ? controlledDialog : uncontrolledDialog;
|
|
468
489
|
const [formError, setFormError] = useState(null);
|
|
469
490
|
const shouldLoadAccounts = Boolean(session) &&
|
|
@@ -473,11 +494,7 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
|
|
|
473
494
|
? loadedAccountsAtom
|
|
474
495
|
: emptyAccountsAtom;
|
|
475
496
|
const accountsResult = useAtomValue(accountsAtom);
|
|
476
|
-
const
|
|
477
|
-
const refreshEmptyAccounts = useAtomRefresh(emptyAccountsAtom);
|
|
478
|
-
const refreshAccounts = shouldLoadAccounts
|
|
479
|
-
? refreshLoadedAccounts
|
|
480
|
-
: refreshEmptyAccounts;
|
|
497
|
+
const registry = useContext(RegistryContext);
|
|
481
498
|
const [signOutAction] = useState(() => authClientApi(resolvedBaseUrl).runtime.fn(({ baseUrl, redirectUrl, }) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.signOut()), Effect.tap(() => Effect.sync(notifyAuthChange)), Effect.flatMap(() => Effect.tryPromise(() => navigate({ href: redirectUrl }))))));
|
|
482
499
|
const signOut = useAtomSet(signOutAction);
|
|
483
500
|
const signOutResult = useAtomValue(signOutAction);
|
|
@@ -503,7 +520,12 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
|
|
|
503
520
|
onFailure: () => m.user_accounts_load_error(),
|
|
504
521
|
onSuccess: () => null,
|
|
505
522
|
}),
|
|
506
|
-
reload: async () =>
|
|
523
|
+
reload: async () => {
|
|
524
|
+
registry.refresh(loadedAccountsAtom);
|
|
525
|
+
await Effect.runPromise(AtomRegistry.getResult(registry, loadedAccountsAtom, {
|
|
526
|
+
suspendOnWaiting: true,
|
|
527
|
+
}));
|
|
528
|
+
},
|
|
507
529
|
};
|
|
508
530
|
const setSettingsDialog = (next) => {
|
|
509
531
|
const nextDialog = Predicate.isFunction(next) ? next(settingsDialog) : next;
|
|
@@ -531,51 +553,96 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
|
|
|
531
553
|
: `${import.meta.env.VITE_SITE_URL}${signOutRedirect.startsWith("/") ? signOutRedirect : `/${signOutRedirect}`}`;
|
|
532
554
|
signOut({ baseUrl: resolvedBaseUrl, redirectUrl });
|
|
533
555
|
};
|
|
534
|
-
return (_jsxs(UserButtonMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "outline", size: "icon", children: [displayImage ? (_jsx("img", { src: displayImage, alt: displayName || displayEmail, className: "size-full
|
|
556
|
+
return (_jsxs(UserButtonMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "outline", size: "icon", className: "overflow-hidden", children: [displayImage ? (_jsx("img", { src: displayImage, alt: displayName || displayEmail, className: "size-full object-cover" })) : (_jsx(UserIcon, { className: "size-4.5" })), _jsx("span", { className: "sr-only", children: m.user_button_aria_label() })] }) }), _jsx(DropdownMenuContent, { className: "w-56 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [isImpersonating ? (_jsx("div", { className: "px-1 py-0.5", children: _jsx(Badge, { variant: "secondary", className: "text-xs font-normal", children: m.user_button_impersonating() }) })) : null, _jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: displayName || displayEmail, subtitle: displayName ? displayEmail : m.user_button_account(), icon: UserIcon, className: "px-1 py-1.5 text-left text-sm", ...(displayImage ? { imageSrc: displayImage } : {}) }) }), menuActions ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), menuActions] })) : null, _jsx(DropdownMenuSeparator, {}), canManageUserSettings ? (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { disabled: isPending, onClick: () => setSettingsDialog("account"), children: [_jsx(UserCircleIcon, {}), m.user_button_account()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("security"), children: [_jsx(ShieldCheck, {}), m.user_button_security()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] }), _jsx(DropdownMenuSeparator, {})] })) : null, (isAdmin && canUseAdminSettings) || isImpersonating ? (_jsxs(_Fragment, { children: [isAdmin && canUseAdminSettings ? (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminUsers"), children: [_jsx(Users, {}), m.user_button_admin_users()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminOrganizations"), children: [_jsx(Building2, {}), m.user_button_admin_organizations()] })] })) : null, isImpersonating ? (_jsxs(DropdownMenuItem, { disabled: isStoppingImpersonation, onClick: () => stopImpersonating({
|
|
535
557
|
baseUrl: resolvedBaseUrl,
|
|
536
558
|
currentSiteHref,
|
|
537
559
|
refreshSession,
|
|
538
560
|
}), children: [_jsx(StopCircle, {}), m.user_button_stop_impersonating()] })) : null, _jsx(DropdownMenuSeparator, {})] })) : null, _jsxs(DropdownMenuItem, { disabled: signOutResult.waiting, onClick: startSignOut, children: [_jsx(LogOutIcon, {}), m.user_button_logout()] }), authActionError ? (_jsx(DropdownMenuLabel, { className: "text-destructive text-xs font-normal", children: authActionError })) : null] }) })] })), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "account", onOpenChange: (open) => {
|
|
539
561
|
setSettingsDialog((current) => open ? "account" : current === "account" ? null : current);
|
|
540
|
-
}, children:
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
562
|
+
}, children: _jsx(UserForm, { defaultValues: {
|
|
563
|
+
name: displayName ?? "",
|
|
564
|
+
image: displayImage || null,
|
|
565
|
+
emails: Array.from(metadata.emails ?? []),
|
|
566
|
+
phones: Array.from(metadata.phones ?? []),
|
|
567
|
+
websites: Array.from(metadata.websites ?? []),
|
|
568
|
+
socials: Array.from(metadata.socials ?? []),
|
|
569
|
+
}, error: formError, onSubmit: (values) => Effect.gen(function* () {
|
|
570
|
+
setFormError(null);
|
|
571
|
+
const metadata = yield* Effect.try({
|
|
572
|
+
try: () => userMetadataFromForm(values),
|
|
573
|
+
catch: () => new Error(m.user_contact_validation_error()),
|
|
574
|
+
});
|
|
575
|
+
const imageFile = isFile(values.image) ? values.image : null;
|
|
576
|
+
const image = imageFile
|
|
577
|
+
? assetPath((yield* uploadUserImageAsset(imageFile, m, resolvedBaseUrl))
|
|
578
|
+
.url)
|
|
579
|
+
: Schema.is(Schema.String)(values.image)
|
|
580
|
+
? assetPath(values.image)
|
|
581
|
+
: null;
|
|
582
|
+
const client = yield* authHttpClient(resolvedBaseUrl);
|
|
583
|
+
yield* client.auth.updateUser({
|
|
584
|
+
payload: {
|
|
585
|
+
name: values.name.trim(),
|
|
586
|
+
image: image?.trim() ?? "",
|
|
587
|
+
metadata,
|
|
588
|
+
},
|
|
589
|
+
});
|
|
590
|
+
notifyAuthChange();
|
|
591
|
+
yield* Effect.sync(refreshSession);
|
|
592
|
+
setSettingsDialog(null);
|
|
593
|
+
}).pipe(Effect.tapError((error) => Effect.sync(() => setFormError(error instanceof Error
|
|
594
|
+
? error.message
|
|
595
|
+
: m.user_form_update_error())))) }) }), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "security", onOpenChange: (open) => {
|
|
596
|
+
setChangingPassword(false);
|
|
597
|
+
setSettingPassword(false);
|
|
598
|
+
setTotpSetup(null);
|
|
599
|
+
setManagingTwoFactor(false);
|
|
600
|
+
setRevokingAccount(null);
|
|
575
601
|
setSettingsDialog((current) => open ? "security" : current === "security" ? null : current);
|
|
576
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children:
|
|
602
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: changingPassword
|
|
603
|
+
? m.user_account_password_change_title()
|
|
604
|
+
: settingPassword
|
|
605
|
+
? m.user_account_password_set()
|
|
606
|
+
: revokingAccount
|
|
607
|
+
? m.user_account_revoke()
|
|
608
|
+
: managingTwoFactor
|
|
609
|
+
? m.user_two_factor_title()
|
|
610
|
+
: m.user_security_title() }), _jsx(DialogDescription, { children: changingPassword
|
|
611
|
+
? m.user_account_password_change_description()
|
|
612
|
+
: settingPassword
|
|
613
|
+
? m.user_account_password_description()
|
|
614
|
+
: revokingAccount
|
|
615
|
+
? m.user_account_revoke_description({
|
|
616
|
+
provider: providerName(revokingAccount.providerId, m),
|
|
617
|
+
})
|
|
618
|
+
: managingTwoFactor
|
|
619
|
+
? m.user_two_factor_description()
|
|
620
|
+
: m.user_security_description() }), changingPassword ||
|
|
621
|
+
settingPassword ||
|
|
622
|
+
revokingAccount ||
|
|
623
|
+
managingTwoFactor ? (_jsxs(Button, { className: "mt-2 w-fit", type: "button", variant: "secondary", onClick: () => {
|
|
624
|
+
setChangingPassword(false);
|
|
625
|
+
setSettingPassword(false);
|
|
626
|
+
setTotpSetup(null);
|
|
627
|
+
setManagingTwoFactor(false);
|
|
628
|
+
setRevokingAccount(null);
|
|
629
|
+
}, children: [_jsx(ArrowLeft, {}), m.user_account_back()] })) : null] }), _jsx(Separator, {}), changingPassword ? (_jsx(ChangePasswordForm, { baseUrl: resolvedBaseUrl })) : settingPassword ? (_jsx(SetPasswordForm, { baseUrl: resolvedBaseUrl, onSaved: async () => {
|
|
630
|
+
await accountCache.reload();
|
|
631
|
+
setSettingPassword(false);
|
|
632
|
+
} })) : revokingAccount ? (_jsx(RevokeAccountForm, { baseUrl: resolvedBaseUrl, account: revokingAccount, requirePassword: requiresPasswordForAccountRevoke(accountCache.accounts ?? []), onCancel: () => setRevokingAccount(null), onRevoked: async () => {
|
|
633
|
+
await accountCache.reload();
|
|
634
|
+
setRevokingAccount(null);
|
|
635
|
+
} })) : totpSetup ? (_jsx(VerifyTotpSetup, { baseUrl: resolvedBaseUrl, setup: totpSetup, onVerified: async () => {
|
|
636
|
+
await refreshSession();
|
|
637
|
+
setTotpSetup(null);
|
|
638
|
+
setManagingTwoFactor(false);
|
|
639
|
+
} })) : managingTwoFactor ? (_jsx(AccountSecuritySettings, { baseUrl: resolvedBaseUrl, accountCache: accountCache, onSetup: setTotpSetup })) : (_jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(ConnectedAccounts, { onChangePassword: () => setChangingPassword(true), onSetupPassword: () => setSettingPassword(true), onRevokeAccount: setRevokingAccount, baseUrl: resolvedBaseUrl, accountCache: accountCache, googleEnabled: projectConfig?.authOptions.google ?? true, currentSiteHref: currentSiteHref, navigate: navigate }), _jsx(Separator, {}), _jsxs("section", { className: "flex flex-col gap-6", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_two_factor_title() }), _jsx("p", { className: "text-muted-foreground text-xs", children: m.user_two_factor_description() })] }), _jsx(Badge, { variant: hasTwoFactorEnabled(session?.user)
|
|
640
|
+
? "default"
|
|
641
|
+
: "secondary", children: hasTwoFactorEnabled(session?.user)
|
|
642
|
+
? m.user_two_factor_enabled()
|
|
643
|
+
: m.user_two_factor_disabled() })] }), hasTwoFactorEnabled(session?.user) ? (_jsx(AccountSecuritySettings, { baseUrl: resolvedBaseUrl, accountCache: accountCache, onSetup: setTotpSetup })) : (_jsx(Button, { type: "button", className: "self-start", onClick: () => setManagingTwoFactor(true), children: m.user_two_factor_enable_submit() }))] })] }))] }) }), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "apiKeys", onOpenChange: (open) => {
|
|
577
644
|
setSettingsDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
578
|
-
}, children: _jsx(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-
|
|
645
|
+
}, children: _jsx(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-[calc(100%-2rem)]", children: _jsx(ApiKeyManager, { baseUrl: resolvedBaseUrl, active: settingsDialog === "apiKeys", permissionLabels: auth?.accessLabels ?? undefined, permissions: apiKeyPermissions ?? auth?.access?.apiKeyPermissions.user ?? {} }) }) }), isAdmin ? (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: settingsDialog === "adminUsers", onOpenChange: (open) => {
|
|
579
646
|
setSettingsDialog((current) => open ? "adminUsers" : current === "adminUsers" ? null : current);
|
|
580
647
|
}, children: _jsxs(DialogContent, { className: "flex h-[85vh] flex-col overflow-y-auto sm:max-w-6xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_button_admin_users() }), _jsx(DialogDescription, { children: m.user_button_admin_users_description() })] }), _jsx(Separator, {}), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(AdminUsersTable, {}) })] }) }), _jsx(Dialog, { open: settingsDialog === "adminOrganizations", onOpenChange: (open) => {
|
|
581
648
|
setSettingsDialog((current) => open
|
|
@@ -585,11 +652,10 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
|
|
|
585
652
|
: current);
|
|
586
653
|
}, children: _jsxs(DialogContent, { className: "flex h-[85vh] flex-col overflow-y-auto sm:max-w-6xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_button_admin_organizations() }), _jsx(DialogDescription, { children: m.user_button_admin_organizations_description() })] }), _jsx(Separator, {}), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(AdminOrganizationsTable, {}) })] }) })] })) : null] }));
|
|
587
654
|
};
|
|
588
|
-
function ConnectedAccounts({ baseUrl, accountCache, googleEnabled, currentSiteHref, navigate, }) {
|
|
655
|
+
function ConnectedAccounts({ onSetupPassword, onRevokeAccount, onChangePassword, baseUrl, accountCache, googleEnabled, currentSiteHref, navigate, }) {
|
|
589
656
|
const m = useUserButtonMessages();
|
|
590
657
|
const [error, setError] = useState(null);
|
|
591
658
|
const [isLinking, setIsLinking] = useState(false);
|
|
592
|
-
const [revokingAccount, setRevokingAccount] = useState(null);
|
|
593
659
|
const [linkGoogleAction] = useState(() => authClientApi(baseUrl).runtime.fn((input) => Effect.gen(function* () {
|
|
594
660
|
setError(null);
|
|
595
661
|
setIsLinking(true);
|
|
@@ -613,27 +679,15 @@ function ConnectedAccounts({ baseUrl, accountCache, googleEnabled, currentSiteHr
|
|
|
613
679
|
setIsLinking(false);
|
|
614
680
|
})))));
|
|
615
681
|
const linkGoogle = useAtomSet(linkGoogleAction);
|
|
616
|
-
const revokeAccount = (account) => authHttpClient(baseUrl).pipe(Effect.tap(() => Effect.sync(() => setError(null))), Effect.flatMap((client) => client.auth.unlinkAccount({
|
|
617
|
-
payload: {
|
|
618
|
-
providerId: account.providerId,
|
|
619
|
-
accountId: account.accountId,
|
|
620
|
-
},
|
|
621
|
-
})), Effect.tap(() => Effect.sync(notifyAuthChange)), Effect.flatMap(() => Effect.tryPromise(() => accountCache.reload())), Effect.tap(() => Effect.sync(() => setRevokingAccount(null))), Effect.catch((cause) => Effect.sync(() => setError(cause instanceof Error && cause.message
|
|
622
|
-
? cause.message
|
|
623
|
-
: m.user_account_revoke_error()))));
|
|
624
682
|
const accounts = accountCache.accounts ?? [];
|
|
625
683
|
const googleAccount = accounts.find((account) => account.providerId === "google");
|
|
626
|
-
const requirePassword = requiresPasswordForAccountRevoke(accounts);
|
|
627
684
|
const showGoogleAccount = googleEnabled || Boolean(googleAccount);
|
|
628
|
-
if (accountCache.accounts && (accounts.length === 0 || !showGoogleAccount)) {
|
|
629
|
-
return null;
|
|
630
|
-
}
|
|
631
685
|
const startLinkGoogle = () => {
|
|
632
686
|
if (!googleEnabled)
|
|
633
687
|
return;
|
|
634
688
|
linkGoogle({ baseUrl, callbackURL: currentSiteHref });
|
|
635
689
|
};
|
|
636
|
-
return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_accounts_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_accounts_description() })] }),
|
|
690
|
+
return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_accounts_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_accounts_description() })] }), _jsxs("div", { className: "flex min-w-0 items-center gap-3 rounded-lg border p-4", children: [_jsx("span", { className: "bg-background flex size-9 shrink-0 items-center justify-center rounded-full border", children: _jsx(Mail, { className: "size-5", "aria-hidden": "true" }) }), _jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("p", { className: "font-medium", children: m.user_account_email_otp_title() }), _jsx(Badge, { children: m.user_account_email_otp_status() })] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_account_email_otp_description() })] })] }), _jsx(PasswordSettings, { onSetupPassword: onSetupPassword, accountCache: accountCache, onChangePassword: onChangePassword, onRevokeAccount: onRevokeAccount }), accountCache.accounts ? (_jsx(_Fragment, { children: showGoogleAccount ? (_jsx(AccountProviderRow, { icon: _jsx(GoogleLogo, {}), title: m.user_account_google_title(), description: m.user_account_google_description(), account: googleAccount, connected: Boolean(googleAccount), connectLabel: m.user_account_google_connect(), revokeLabel: m.user_account_revoke(), isConnecting: isLinking, renderDisconnected: undefined, onConnect: startLinkGoogle, onRevoke: onRevokeAccount })) : null })) : !accountCache.error ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : null, accountCache.error ? (_jsx("p", { className: "text-destructive text-sm", children: accountCache.error })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }));
|
|
637
691
|
}
|
|
638
692
|
function AccountProviderRow({ icon, title, description, account, connected, connectLabel, revokeLabel, isConnecting, renderDisconnected, onConnect, onRevoke, }) {
|
|
639
693
|
const m = useUserButtonMessages();
|
|
@@ -644,23 +698,13 @@ function AccountProviderRow({ icon, title, description, account, connected, conn
|
|
|
644
698
|
function GoogleLogo() {
|
|
645
699
|
return (_jsxs("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", className: "size-5", children: [_jsx("path", { fill: "#4285F4", d: "M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" }), _jsx("path", { fill: "#34A853", d: "M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" }), _jsx("path", { fill: "#FBBC05", d: "M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" }), _jsx("path", { fill: "#EA4335", d: "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84C6.71 7.31 9.14 5.38 12 5.38z" })] }));
|
|
646
700
|
}
|
|
647
|
-
function PasswordSettings({
|
|
648
|
-
const [error, setError] = useState(null);
|
|
649
|
-
const [revokingAccount, setRevokingAccount] = useState(null);
|
|
701
|
+
function PasswordSettings({ onSetupPassword, onRevokeAccount, onChangePassword, accountCache, }) {
|
|
650
702
|
const m = useUserButtonMessages();
|
|
651
703
|
const accounts = accountCache.accounts ?? [];
|
|
652
704
|
const passwordAccount = accounts.find((account) => account.providerId === "credential");
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
payload: {
|
|
657
|
-
providerId: account.providerId,
|
|
658
|
-
accountId: account.accountId,
|
|
659
|
-
},
|
|
660
|
-
})), Effect.tap(() => Effect.sync(notifyAuthChange)), Effect.flatMap(() => Effect.tryPromise(() => accountCache.reload())), Effect.tap(() => Effect.sync(() => setRevokingAccount(null))), Effect.catch((cause) => Effect.sync(() => setError(cause instanceof Error && cause.message
|
|
661
|
-
? cause.message
|
|
662
|
-
: m.user_account_revoke_error()))));
|
|
663
|
-
return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_account_password_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_account_password_description() })] }), accountCache.accounts && hasPassword && passwordAccount ? (_jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3 rounded-lg border p-4", children: [_jsxs("div", { className: "flex flex-col gap-1", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("p", { className: "font-medium", children: m.user_account_password_title() }), _jsx(Badge, { children: m.user_account_connected() })] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_account_password_connected_description() })] }), _jsx(Button, { type: "button", variant: "outline", onClick: () => setRevokingAccount(passwordAccount), children: m.user_account_revoke() })] }), revokingAccount ? (_jsx(RevokeAccountForm, { baseUrl: baseUrl, account: revokingAccount, requirePassword: requirePassword, onCancel: () => setRevokingAccount(null), onRevoke: revokePassword })) : null, _jsx(Separator, {}), _jsx(ChangePasswordForm, { baseUrl: baseUrl })] })) : accountCache.accounts ? (_jsx(SetPasswordForm, { baseUrl: baseUrl, onSaved: accountCache.reload })) : !accountCache.error ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : null, accountCache.error ? (_jsx("p", { className: "text-destructive text-sm", children: accountCache.error })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }));
|
|
705
|
+
return (_jsxs("section", { className: "flex flex-col gap-4", children: [accountCache.accounts ? (_jsx("div", { className: "flex flex-col gap-4", children: _jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3 rounded-lg border p-4", children: [_jsxs("div", { className: "flex min-w-0 items-center gap-3", children: [_jsx("span", { className: "bg-background flex size-9 shrink-0 items-center justify-center rounded-full border text-sm font-semibold", children: _jsx(KeyRound, { className: "size-5", "aria-hidden": "true" }) }), _jsxs("div", { className: "flex flex-col gap-1", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("p", { className: "font-medium", children: m.user_account_password_title() }), passwordAccount ? (_jsx(Badge, { children: m.user_account_connected() })) : null] }), _jsx("p", { className: "text-muted-foreground text-sm", children: passwordAccount
|
|
706
|
+
? m.user_account_password_connected_description()
|
|
707
|
+
: m.user_account_password_description() })] })] }), passwordAccount ? (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Button, { type: "button", variant: "outline", onClick: onChangePassword, children: m.user_account_change() }), _jsx(Button, { type: "button", variant: "outline", onClick: () => onRevokeAccount(passwordAccount), children: m.user_account_revoke() })] })) : (_jsx(Button, { type: "button", variant: "outline", onClick: onSetupPassword, children: m.user_account_password_setup() }))] }) })) : !accountCache.error ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : null, accountCache.error ? (_jsx("p", { className: "text-destructive text-sm", children: accountCache.error })) : null] }));
|
|
664
708
|
}
|
|
665
709
|
function ChangePasswordForm({ baseUrl }) {
|
|
666
710
|
const m = useUserButtonMessages();
|
|
@@ -686,22 +730,20 @@ function ChangePasswordForm({ baseUrl }) {
|
|
|
686
730
|
event.preventDefault();
|
|
687
731
|
event.stopPropagation();
|
|
688
732
|
submit();
|
|
689
|
-
}, children: [
|
|
733
|
+
}, children: [_jsx(form.currentPassword, { label: m.user_account_current_password(), type: "password", autoComplete: "current-password", required: true }), _jsx(form.newPassword, { label: m.user_account_new_password(), type: "password", autoComplete: "new-password", required: true }), _jsx(SubmitError, { result: submitResult }), saved ? (_jsx("p", { className: "text-sm text-green-600", children: m.user_account_password_change_success() })) : null, _jsx(SubmitButton, { form: form, children: m.user_account_password_change_submit() })] }) }));
|
|
690
734
|
}
|
|
691
735
|
function SetPasswordForm({ baseUrl, onSaved, }) {
|
|
692
736
|
const m = useUserButtonMessages();
|
|
693
|
-
let reset = () => { };
|
|
694
737
|
const [form] = useState(() => FormReact.make(passwordFormBuilder(true), {
|
|
695
738
|
runtime: authClientApi(baseUrl).runtime,
|
|
696
739
|
fields: { password: TextField },
|
|
697
740
|
mode: { validation: "onSubmit" },
|
|
698
741
|
onSubmit: (_, { decoded }) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.authExtra.setPassword({
|
|
699
742
|
payload: { newPassword: decoded.password },
|
|
700
|
-
})), Effect.tap(() => Effect.sync(notifyAuthChange)), Effect.
|
|
743
|
+
})), Effect.tap(() => Effect.sync(notifyAuthChange)), Effect.flatMap(() => Effect.tryPromise(() => onSaved())), Effect.mapError((cause) => cause instanceof Error
|
|
701
744
|
? cause
|
|
702
745
|
: new Error(m.user_account_password_set_error()))),
|
|
703
746
|
}));
|
|
704
|
-
reset = useAtomSet(form.reset);
|
|
705
747
|
const submit = useAtomSet(form.submit);
|
|
706
748
|
const submitResult = useAtomValue(form.submit);
|
|
707
749
|
return (_jsx(form.Initialize, { defaultValues: { password: "" }, children: _jsxs("form", { className: "flex w-full flex-col gap-3 sm:max-w-sm", onSubmit: (event) => {
|
|
@@ -710,33 +752,42 @@ function SetPasswordForm({ baseUrl, onSaved, }) {
|
|
|
710
752
|
submit();
|
|
711
753
|
}, children: [_jsx(form.password, { label: m.user_account_new_password(), type: "password", autoComplete: "new-password", required: true }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form, children: m.user_account_password_set() })] }) }));
|
|
712
754
|
}
|
|
713
|
-
function RevokeAccountForm({ baseUrl, account, requirePassword, onCancel,
|
|
755
|
+
function RevokeAccountForm({ baseUrl, account, requirePassword, onCancel, onRevoked, }) {
|
|
714
756
|
const m = useUserButtonMessages();
|
|
715
757
|
const [form] = useState(() => FormReact.make(passwordFormBuilder(requirePassword), {
|
|
716
758
|
runtime: authClientApi(baseUrl).runtime,
|
|
717
759
|
fields: { password: TextField },
|
|
718
760
|
mode: { validation: "onSubmit" },
|
|
719
761
|
onSubmit: (_, { decoded }) => Effect.gen(function* () {
|
|
762
|
+
const client = yield* authHttpClient(baseUrl);
|
|
720
763
|
if (requirePassword) {
|
|
721
|
-
const client = yield* authHttpClient(baseUrl);
|
|
722
764
|
yield* client.authExtra.verifyPassword({
|
|
723
765
|
payload: { password: decoded.password },
|
|
724
766
|
});
|
|
725
767
|
}
|
|
726
|
-
yield*
|
|
768
|
+
yield* client.auth
|
|
769
|
+
.unlinkAccount({
|
|
770
|
+
payload: {
|
|
771
|
+
providerId: account.providerId,
|
|
772
|
+
accountId: account.accountId,
|
|
773
|
+
},
|
|
774
|
+
})
|
|
775
|
+
.pipe(Effect.mapError((cause) => cause instanceof Error
|
|
776
|
+
? cause
|
|
777
|
+
: new Error(m.user_account_revoke_error())));
|
|
778
|
+
yield* Effect.sync(notifyAuthChange);
|
|
779
|
+
yield* Effect.tryPromise(onRevoked);
|
|
727
780
|
}).pipe(Effect.mapError((cause) => cause instanceof Error
|
|
728
781
|
? cause
|
|
729
782
|
: new Error(m.user_account_password_verify_error()))),
|
|
730
783
|
}));
|
|
731
784
|
const submit = useAtomSet(form.submit);
|
|
732
785
|
const submitResult = useAtomValue(form.submit);
|
|
733
|
-
return (_jsx(form.Initialize, { defaultValues: { password: "" }, children: _jsxs("form", { className: "
|
|
786
|
+
return (_jsx(form.Initialize, { defaultValues: { password: "" }, children: _jsxs("form", { className: "flex w-full flex-col gap-3 sm:max-w-md", onSubmit: (event) => {
|
|
734
787
|
event.preventDefault();
|
|
735
788
|
event.stopPropagation();
|
|
736
789
|
submit();
|
|
737
|
-
}, children: [_jsxs("div", { className: "flex flex-
|
|
738
|
-
provider: providerName(account.providerId, m),
|
|
739
|
-
}) })] }), requirePassword ? (_jsx(form.password, { label: m.user_field_password(), type: "password", autoComplete: "current-password", required: true })) : null, _jsx(SubmitError, { result: submitResult }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { type: "button", variant: "outline", onClick: onCancel, children: m.user_account_cancel() }), requirePassword ? (_jsx(SubmitButton, { form: form, children: m.user_account_confirm_revoke() })) : (_jsxs(Button, { type: "button", disabled: submitResult.waiting, onClick: () => submit(), children: [submitResult.waiting ? (_jsx(Loader2, { "data-icon": "inline-start", className: "animate-spin" })) : null, m.user_account_confirm_revoke()] }))] })] }) }));
|
|
790
|
+
}, children: [requirePassword ? (_jsx(form.password, { label: m.user_field_password(), type: "password", autoComplete: "current-password", required: true })) : null, _jsx(SubmitError, { result: submitResult }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { type: "button", variant: "outline", onClick: onCancel, children: m.user_account_cancel() }), requirePassword ? (_jsx(SubmitButton, { form: form, children: m.user_confirm_password() })) : (_jsxs(Button, { type: "button", disabled: submitResult.waiting, onClick: () => submit(), children: [submitResult.waiting ? (_jsx(Loader2, { "data-icon": "inline-start", className: "animate-spin" })) : null, m.user_account_confirm_revoke()] }))] })] }) }));
|
|
740
791
|
}
|
|
741
792
|
const providerName = (providerId, m) => {
|
|
742
793
|
if (providerId === "google")
|
|
@@ -763,19 +814,19 @@ const UserForm = ({ defaultValues, error, onSubmit, }) => {
|
|
|
763
814
|
: new Error(m.user_form_update_error()))),
|
|
764
815
|
}));
|
|
765
816
|
const submit = useAtomSet(form.submit);
|
|
766
|
-
return (
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
817
|
+
return (_jsx(form.Initialize, { defaultValues: defaultValues, children: _jsx("form", { onSubmit: (event) => {
|
|
818
|
+
event.preventDefault();
|
|
819
|
+
event.stopPropagation();
|
|
820
|
+
submit();
|
|
821
|
+
}, children: _jsxs(DialogContent, { className: "grid max-h-[85vh] min-w-0 grid-rows-[auto_minmax(0,1fr)_auto] gap-0 overflow-hidden sm:max-w-3xl", children: [_jsxs(DialogHeader, { className: "pb-6", children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_form_title() }), _jsx(DialogDescription, { children: m.user_form_description() })] }), _jsxs("div", { className: "-mx-6 flex min-h-0 flex-col gap-4 overflow-y-auto px-6 pb-6", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_profile_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_profile_description() })] }), _jsx(form.image, { label: m.user_profile_photo_upload_label(), size: {
|
|
822
|
+
width: 96,
|
|
823
|
+
height: 96,
|
|
824
|
+
suggestedWidth: 512,
|
|
825
|
+
suggestedHeight: 512,
|
|
826
|
+
} }), _jsx(form.name, { label: m.user_form_name_label(), autoComplete: "name", required: true }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h3", { className: "text-sm leading-none font-medium", children: m.user_contact_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_contact_description() })] }), _jsx(EditingLocaleSwitcher, { value: editingLocale, onValueChange: setEditingLocale })] }), _jsx(UserContactGroup, { title: m.user_contact_email_type(), children: _jsx(form.emails, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) }), _jsx(UserContactGroup, { title: m.user_contact_phone_type(), children: _jsx(form.phones, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) }), _jsx(UserContactGroup, { title: m.user_contact_website_type(), children: _jsx(form.websites, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) }), _jsx(UserContactGroup, { title: m.user_contact_social_type(), children: _jsx(form.socials, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) })] })] }), _jsx(DialogFooter, { className: "-mx-6 -mb-6 border-t px-6 py-4", children: _jsxs("div", { className: "flex flex-col gap-3", children: [error && (_jsx("p", { role: "alert", className: "text-destructive text-sm", children: error })), _jsx(SubmitButton, { form: form })] }) })] }) }) }));
|
|
776
827
|
};
|
|
777
828
|
const UserContactGroup = ({ children, title, }) => (_jsxs("div", { className: "flex flex-col gap-3", children: [_jsx("h4", { className: "text-sm font-medium", children: title }), children] }));
|
|
778
|
-
function AccountSecuritySettings({ baseUrl, accountCache, }) {
|
|
829
|
+
function AccountSecuritySettings({ baseUrl, accountCache, onSetup, }) {
|
|
779
830
|
const m = useUserButtonMessages();
|
|
780
831
|
const sessionAtom = authSessionAtom(baseUrl);
|
|
781
832
|
const sessionResult = useAtomValue(sessionAtom);
|
|
@@ -785,24 +836,17 @@ function AccountSecuritySettings({ baseUrl, accountCache, }) {
|
|
|
785
836
|
onFailure: () => null,
|
|
786
837
|
onSuccess: ({ value }) => value,
|
|
787
838
|
});
|
|
788
|
-
const [setup, setSetup] = useState(null);
|
|
789
839
|
const [message, setMessage] = useState(null);
|
|
790
840
|
const twoFactorEnabled = hasTwoFactorEnabled(session?.user);
|
|
791
841
|
const requirePassword = accountCache.accounts
|
|
792
842
|
? accountCache.accounts.some((account) => account.providerId === "credential")
|
|
793
843
|
: null;
|
|
794
|
-
return (_jsxs("div", { className: "flex flex-col gap-6", children: [
|
|
795
|
-
? m.user_two_factor_enabled()
|
|
796
|
-
: m.user_two_factor_disabled() })] }), requirePassword === null ? (_jsx("p", { className: accountCache.error
|
|
844
|
+
return (_jsxs("div", { className: "flex flex-col gap-6", children: [requirePassword === null ? (_jsx("p", { className: accountCache.error
|
|
797
845
|
? "text-destructive text-sm"
|
|
798
846
|
: "text-muted-foreground text-sm", children: accountCache.error ?? m.user_loading() })) : twoFactorEnabled ? (_jsx(DisableTotpForm, { baseUrl: baseUrl, requirePassword: requirePassword, onDisabled: async () => {
|
|
799
847
|
setMessage(m.user_two_factor_disabled_message());
|
|
800
848
|
await refreshSession();
|
|
801
|
-
} })) :
|
|
802
|
-
setSetup(null);
|
|
803
|
-
setMessage(m.user_two_factor_enabled_message());
|
|
804
|
-
await refreshSession();
|
|
805
|
-
} })) : (_jsx(EnableTotpForm, { baseUrl: baseUrl, requirePassword: requirePassword, onEnabled: setSetup })), message ? (_jsx("p", { className: "text-muted-foreground text-sm", children: message })) : null] }));
|
|
849
|
+
} })) : (_jsx(EnableTotpForm, { baseUrl: baseUrl, requirePassword: requirePassword, onEnabled: onSetup })), message ? (_jsx("p", { className: "text-muted-foreground text-sm", children: message })) : null] }));
|
|
806
850
|
}
|
|
807
851
|
function EnableTotpForm({ baseUrl, requirePassword, onEnabled, }) {
|
|
808
852
|
const m = useUserButtonMessages();
|
|
@@ -812,7 +856,7 @@ function EnableTotpForm({ baseUrl, requirePassword, onEnabled, }) {
|
|
|
812
856
|
mode: { validation: "onSubmit" },
|
|
813
857
|
onSubmit: (_, { decoded }) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.twoFactorEnable({
|
|
814
858
|
payload: requirePassword ? { password: decoded.password } : {},
|
|
815
|
-
})), Effect.tap((
|
|
859
|
+
})), Effect.tap((result) => Effect.sync(() => onEnabled({
|
|
816
860
|
totpURI: result.totpURI,
|
|
817
861
|
backupCodes: Array.from(result.backupCodes),
|
|
818
862
|
}))), Effect.mapError((cause) => cause instanceof Error
|
|
@@ -821,11 +865,18 @@ function EnableTotpForm({ baseUrl, requirePassword, onEnabled, }) {
|
|
|
821
865
|
}));
|
|
822
866
|
const submit = useAtomSet(form.submit);
|
|
823
867
|
const submitResult = useAtomValue(form.submit);
|
|
868
|
+
const startedPasswordlessSetup = useRef(false);
|
|
869
|
+
useEffect(() => {
|
|
870
|
+
if (requirePassword || startedPasswordlessSetup.current)
|
|
871
|
+
return;
|
|
872
|
+
startedPasswordlessSetup.current = true;
|
|
873
|
+
submit();
|
|
874
|
+
}, [requirePassword, submit]);
|
|
824
875
|
return (_jsx(form.Initialize, { defaultValues: { password: "" }, children: _jsxs("form", { className: "flex max-w-md flex-col gap-4", onSubmit: (event) => {
|
|
825
876
|
event.preventDefault();
|
|
826
877
|
event.stopPropagation();
|
|
827
878
|
submit();
|
|
828
|
-
}, children: [requirePassword ? (_jsx(form.password, { label: m.user_field_password(), type: "password", autoComplete: "current-password", required: true })) : null, _jsx(SubmitError, { result: submitResult }), requirePassword ? (_jsx(SubmitButton, { form: form, children: m.
|
|
879
|
+
}, children: [requirePassword ? (_jsx(form.password, { label: m.user_field_password(), type: "password", autoComplete: "current-password", required: true })) : null, _jsx(SubmitError, { result: submitResult }), requirePassword ? (_jsx(SubmitButton, { form: form, children: m.user_confirm_password() })) : (_jsxs(Button, { type: "button", disabled: submitResult.waiting, onClick: () => submit(), children: [submitResult.waiting ? (_jsx(Loader2, { "data-icon": "inline-start", className: "animate-spin" })) : null, m.user_two_factor_enable_submit()] }))] }) }));
|
|
829
880
|
}
|
|
830
881
|
function VerifyTotpSetup({ baseUrl, setup, onVerified, }) {
|
|
831
882
|
const m = useUserButtonMessages();
|
|
@@ -865,7 +916,7 @@ function DisableTotpForm({ baseUrl, requirePassword, onDisabled, }) {
|
|
|
865
916
|
event.preventDefault();
|
|
866
917
|
event.stopPropagation();
|
|
867
918
|
submit();
|
|
868
|
-
}, children: [requirePassword ? (_jsx(form.password, { label: m.user_field_password(), type: "password", autoComplete: "current-password", required: true })) : null, _jsx(SubmitError, { result: submitResult }), requirePassword ? (_jsx(SubmitButton, { form: form })) : (_jsxs(Button, { type: "button", disabled: submitResult.waiting, onClick: () => submit(), children: [submitResult.waiting ? (_jsx(Loader2, { "data-icon": "inline-start", className: "animate-spin" })) : null, effectFormMessages().submit] }))] }) }));
|
|
919
|
+
}, children: [requirePassword ? (_jsx(form.password, { label: m.user_field_password(), type: "password", autoComplete: "current-password", required: true })) : null, _jsx(SubmitError, { result: submitResult }), requirePassword ? (_jsx(SubmitButton, { form: form, children: m.user_confirm_password() })) : (_jsxs(Button, { type: "button", disabled: submitResult.waiting, onClick: () => submit(), children: [submitResult.waiting ? (_jsx(Loader2, { "data-icon": "inline-start", className: "animate-spin" })) : null, effectFormMessages().submit] }))] }) }));
|
|
869
920
|
}
|
|
870
921
|
function ApiKeyManager({ baseUrl, active, permissionLabels, permissions = {}, }) {
|
|
871
922
|
const m = useUserButtonMessages();
|
package/dist/server/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { AuthClientConfig } from "../config.js";
|
|
|
4
4
|
export { ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api.group.js";
|
|
5
5
|
export { proxyAuthHttpEffect, proxyAuthRequest, proxyAuthRequestEffect, } from "./proxy.js";
|
|
6
6
|
export type { ProxyAuthRequestOptions } from "./proxy.js";
|
|
7
|
+
export { AuthProxyError, authProxyKeyHeader, proxyOriginHeaders, readProxyOrigin, stripProxyOriginHeaders, } from "./proxy-origin.js";
|
|
7
8
|
export { ActorRequired } from "./actor.js";
|
|
8
9
|
export type { ActorConstraint } from "./actor.js";
|
|
9
10
|
export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware.js";
|