@krak-stack/auth 0.3.2 → 0.4.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +37 -0
  3. package/dist/admin/api.group.d.ts +4 -4
  4. package/dist/admin/schema.d.ts +6 -6
  5. package/dist/api.d.ts +1577 -1331
  6. package/dist/auth/api.group.d.ts +124 -1
  7. package/dist/auth/api.group.js +36 -1
  8. package/dist/auth/schema.d.ts +38 -0
  9. package/dist/auth/schema.js +38 -0
  10. package/dist/components/account-deletion.js +2 -1
  11. package/dist/components/admin-organization-form.js +3 -2
  12. package/dist/components/admin-organizations.js +3 -3
  13. package/dist/components/admin-users.js +3 -3
  14. package/dist/components/appearance.d.ts +89 -0
  15. package/dist/components/appearance.js +59 -0
  16. package/dist/components/auth-client-api.d.ts +134 -4
  17. package/dist/components/auth-forms.d.ts +5 -1
  18. package/dist/components/auth-forms.js +60 -7
  19. package/dist/components/contact-fields.js +2 -1
  20. package/dist/components/index.d.ts +1 -0
  21. package/dist/components/organization-sso-atom.d.ts +71 -0
  22. package/dist/components/organization-sso-atom.js +40 -0
  23. package/dist/components/organization-sso-messages.d.ts +76 -0
  24. package/dist/components/organization-sso-messages.js +77 -0
  25. package/dist/components/organization-sso-settings.d.ts +6 -0
  26. package/dist/components/organization-sso-settings.js +96 -0
  27. package/dist/components/organization-switcher.d.ts +8 -3
  28. package/dist/components/organization-switcher.js +25 -13
  29. package/dist/components/scrollable-dialog.d.ts +3 -2
  30. package/dist/components/scrollable-dialog.js +11 -4
  31. package/dist/components/user-button.d.ts +8 -2
  32. package/dist/components/user-button.js +8 -7
  33. package/dist/service.d.ts +260 -0
  34. package/package.json +3 -3
@@ -0,0 +1,77 @@
1
+ const en = {
2
+ organization_security: () => "Security",
3
+ organization_security_description: () => "Manage sign-in security for this organization.",
4
+ sso_settings_title: () => "Single sign-on (SSO)",
5
+ sso_settings_description: () => "Let existing members sign in with your organization's identity provider. Password and email-code sign-in remain available.",
6
+ sso_connection_details: () => "Identity provider",
7
+ sso_callback_step: () => "Callback URL",
8
+ sso_callback_help: () => "Register this URL in your identity provider's app settings.",
9
+ sso_status_enabled: () => "Enabled",
10
+ sso_status_disabled: () => "Disabled",
11
+ sso_update_help: () => "Changing the client ID or secret disables SSO until you enable it again. Saving unchanged credentials keeps the current status. Leave the secret blank to keep it. To change the issuer or domain, remove this connection first.",
12
+ sso_loading: () => "Loading SSO settings…",
13
+ sso_load_error: () => "Could not load SSO settings. Check that your auth server supports organization SSO and try again.",
14
+ sso_issuer: () => "OIDC issuer URL",
15
+ sso_domain: () => "Company email domain",
16
+ sso_client_id: () => "Client ID",
17
+ sso_client_secret: () => "Client secret",
18
+ sso_secret_unchanged: () => "Leave blank to keep the existing secret. Stored secrets are never displayed.",
19
+ sso_save_help: () => "Use Google, Microsoft Entra ID, Okta or Auth0. Custom provider domains require platform approval. Save to continue with callback and DNS setup; SSO stays disabled until you enable it.",
20
+ sso_save: () => "Save connection",
21
+ sso_callback: () => "Callback URL to register with your identity provider",
22
+ sso_domain_verification: () => "Domain verification",
23
+ sso_dns_help: () => "Publish this DNS TXT record for your company email domain, then verify it here.",
24
+ sso_dns_name: () => "TXT record name",
25
+ sso_dns_value: () => "TXT record value",
26
+ sso_verified: () => "Domain verified",
27
+ sso_unverified: () => "Domain not yet verified",
28
+ sso_verify: () => "Verify DNS record",
29
+ sso_enable: () => "Enable SSO",
30
+ sso_disable: () => "Disable SSO",
31
+ sso_remove: () => "Remove connection",
32
+ sso_remove_title: () => "Remove SSO connection?",
33
+ sso_remove_warning: () => "Members will no longer be able to sign in through this provider. Their accounts, memberships and other sign-in methods stay unchanged. Existing sessions remain active. Nothing is deleted from your identity provider.",
34
+ sso_remove_confirm: () => "Remove SSO connection",
35
+ sso_cancel: () => "Cancel",
36
+ sso_action_error: () => "Could not update SSO. Check your permissions, provider details and DNS record. A verified email domain can only be enabled for one organization.",
37
+ };
38
+ export const organizationSsoMessages = {
39
+ en,
40
+ fr: {
41
+ organization_security: () => "Sécurité",
42
+ organization_security_description: () => "Gérez la sécurité de connexion de cette organisation.",
43
+ sso_settings_title: () => "Authentification unique (SSO)",
44
+ sso_settings_description: () => "Permettez aux membres existants de se connecter avec le fournisseur d’identité de votre organisation. Le mot de passe et le code par courriel restent disponibles.",
45
+ sso_connection_details: () => "Fournisseur d’identité",
46
+ sso_callback_step: () => "URL de retour",
47
+ sso_callback_help: () => "Enregistrez cette URL dans les paramètres de l’application de votre fournisseur d’identité.",
48
+ sso_status_enabled: () => "Activé",
49
+ sso_status_disabled: () => "Désactivé",
50
+ sso_update_help: () => "La modification de l’identifiant client ou du secret désactive le SSO jusqu’à sa réactivation. Un enregistrement sans modification conserve l’état actuel. Laissez le secret vide pour le conserver. Pour changer l’émetteur ou le domaine, supprimez d’abord cette connexion.",
51
+ sso_loading: () => "Chargement des paramètres SSO…",
52
+ sso_load_error: () => "Impossible de charger les paramètres SSO. Vérifiez que votre serveur d’authentification prend en charge le SSO d’organisation, puis réessayez.",
53
+ sso_issuer: () => "URL de l’émetteur OIDC",
54
+ sso_domain: () => "Domaine de courriel de l’entreprise",
55
+ sso_client_id: () => "Identifiant client",
56
+ sso_client_secret: () => "Secret client",
57
+ sso_secret_unchanged: () => "Laissez vide pour conserver le secret actuel. Les secrets enregistrés ne sont jamais affichés.",
58
+ sso_save_help: () => "Utilisez Google, Microsoft Entra ID, Okta ou Auth0. Les domaines personnalisés nécessitent l’approbation de la plateforme. Enregistrez pour configurer l’URL de retour et le DNS ; le SSO reste désactivé jusqu’à son activation.",
59
+ sso_save: () => "Enregistrer la connexion",
60
+ sso_callback: () => "URL de retour à enregistrer chez votre fournisseur d’identité",
61
+ sso_domain_verification: () => "Vérification du domaine",
62
+ sso_dns_help: () => "Publiez cet enregistrement DNS TXT pour votre domaine de courriel, puis vérifiez-le ici.",
63
+ sso_dns_name: () => "Nom de l’enregistrement TXT",
64
+ sso_dns_value: () => "Valeur de l’enregistrement TXT",
65
+ sso_verified: () => "Domaine vérifié",
66
+ sso_unverified: () => "Domaine non vérifié",
67
+ sso_verify: () => "Vérifier l’enregistrement DNS",
68
+ sso_enable: () => "Activer le SSO",
69
+ sso_disable: () => "Désactiver le SSO",
70
+ sso_remove: () => "Supprimer la connexion",
71
+ sso_remove_title: () => "Supprimer la connexion SSO ?",
72
+ sso_remove_warning: () => "Les membres ne pourront plus se connecter via ce fournisseur. Leurs comptes, leurs adhésions et leurs autres méthodes de connexion restent inchangés. Les sessions existantes restent actives. Rien n’est supprimé chez votre fournisseur d’identité.",
73
+ sso_remove_confirm: () => "Supprimer la connexion SSO",
74
+ sso_cancel: () => "Annuler",
75
+ sso_action_error: () => "Impossible de modifier le SSO. Vérifiez vos permissions, la configuration du fournisseur et l’enregistrement DNS. Un domaine vérifié ne peut être activé que pour une organisation.",
76
+ },
77
+ };
@@ -0,0 +1,6 @@
1
+ import type { KrakstackAuthLocale } from "./auth-provider.js";
2
+ export declare const OrganizationSsoSettingsPanel: ({ organizationId, baseUrl, locale, }: {
3
+ organizationId: string;
4
+ baseUrl?: string;
5
+ locale: KrakstackAuthLocale;
6
+ }) => import("react").JSX.Element;
@@ -0,0 +1,96 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useAtomSet, useAtomValue } from "@effect/atom-react";
3
+ import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
4
+ import { ErrorMessage, SubmitButton, TextField, } from "@krak-stack/registry/effect-form";
5
+ import { CopyButton } from "@krak-stack/registry/copy-button";
6
+ import { AsyncResult } from "effect/reactivity";
7
+ import { Schema } from "effect";
8
+ import { useEffect, useLayoutEffect, useRef, useState, } from "react";
9
+ import { ChevronDownIcon, KeyRoundIcon, LinkIcon, ShieldCheckIcon, } from "lucide-react";
10
+ import { Button } from "@/components/ui/button";
11
+ import { Input } from "@/components/ui/input";
12
+ import { Badge } from "@/components/ui/badge";
13
+ import { organizationSsoAtoms } from "./organization-sso-atom.js";
14
+ import { organizationSsoMessages } from "./organization-sso-messages.js";
15
+ const builder = FormBuilder.empty
16
+ .addField("issuer", Schema.Trim.check(Schema.isNonEmpty()))
17
+ .addField("domain", Schema.Trim.check(Schema.isNonEmpty()))
18
+ .addField("clientId", Schema.Trim.check(Schema.isNonEmpty()))
19
+ .addField("clientSecret", Schema.String);
20
+ const SsoSettingsCard = ({ title, description, icon, open, children, }) => (_jsxs("details", { className: "group rounded-lg border", open: open, children: [_jsxs("summary", { className: "hover:bg-muted/40 focus-visible:ring-ring flex cursor-pointer list-none items-center gap-3 rounded-lg p-4 focus-visible:ring-2 focus-visible:outline-none [&::-webkit-details-marker]:hidden", children: [_jsx("span", { className: "bg-background flex size-9 shrink-0 items-center justify-center rounded-full border", children: icon }), _jsxs("span", { className: "min-w-0 flex-1", children: [_jsx("span", { className: "block text-sm font-medium", children: title }), description] }), _jsx(ChevronDownIcon, { className: "text-muted-foreground size-4 shrink-0 transition-transform group-open:rotate-180", "aria-hidden": "true" })] }), _jsx("div", { className: "px-4 pt-3 pb-4", children: children })] }));
21
+ export const OrganizationSsoSettingsPanel = ({ organizationId, baseUrl, locale, }) => {
22
+ const m = organizationSsoMessages[locale];
23
+ const atoms = organizationSsoAtoms(baseUrl)(organizationId);
24
+ const result = useAtomValue(atoms.settings);
25
+ return AsyncResult.match(result, {
26
+ onInitial: () => _jsx("p", { role: "status", children: m.sso_loading() }),
27
+ onFailure: () => _jsx(ErrorMessage, { text: m.sso_load_error() }),
28
+ onSuccess: ({ value }) => (_jsx(OrganizationSsoForm, { atoms: atoms, connection: value, m: m }, value?.providerId ?? "new")),
29
+ });
30
+ };
31
+ const OrganizationSsoForm = ({ atoms, connection, m, }) => {
32
+ const [form] = useState(() => FormReact.make(builder, {
33
+ fields: {
34
+ issuer: TextField,
35
+ domain: TextField,
36
+ clientId: TextField,
37
+ clientSecret: TextField,
38
+ },
39
+ onSubmit: (_, { decoded: { clientSecret, ...value }, get }) => get.setResult(atoms.save, {
40
+ ...value,
41
+ clientSecret: clientSecret || undefined,
42
+ }),
43
+ }));
44
+ const submit = useAtomSet(form.submit);
45
+ const result = useAtomValue(form.submit);
46
+ const clearSecret = useAtomSet(form.getFieldAtoms(form.fields.clientSecret).setValue);
47
+ useEffect(() => {
48
+ if (AsyncResult.isSuccess(result) && !result.waiting) {
49
+ clearSecret("");
50
+ }
51
+ }, [result, clearSecret]);
52
+ const verify = useAtomSet(atoms.verify);
53
+ const verificationResult = useAtomValue(atoms.verify);
54
+ const enable = useAtomSet(atoms.enable);
55
+ const enableResult = useAtomValue(atoms.enable);
56
+ const remove = useAtomSet(atoms.remove);
57
+ const removeResult = useAtomValue(atoms.remove);
58
+ const [confirmingRemoval, setConfirmingRemoval] = useState(false);
59
+ const [callbackInitiallyOpen] = useState(() => !connection?.enabled);
60
+ const removeButton = useRef(null);
61
+ const restoreRemovalFocus = useRef(false);
62
+ useLayoutEffect(() => {
63
+ if (!confirmingRemoval && restoreRemovalFocus.current) {
64
+ restoreRemovalFocus.current = false;
65
+ removeButton.current?.focus();
66
+ }
67
+ }, [confirmingRemoval]);
68
+ const busy = result.waiting ||
69
+ verificationResult.waiting ||
70
+ enableResult.waiting ||
71
+ removeResult.waiting;
72
+ const failed = AsyncResult.isFailure(result) ||
73
+ AsyncResult.isFailure(verificationResult) ||
74
+ AsyncResult.isFailure(enableResult) ||
75
+ AsyncResult.isFailure(removeResult);
76
+ const callbackUrl = connection?.callbackURL;
77
+ return (_jsxs(_Fragment, { children: [confirmingRemoval ? (_jsxs("section", { "aria-label": m.sso_remove_title(), className: "flex flex-col gap-4", children: [_jsxs("div", { className: "space-y-2", children: [_jsx("h2", { className: "text-base font-medium", children: m.sso_remove_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.sso_remove_warning() })] }), AsyncResult.isFailure(removeResult) ? (_jsx(ErrorMessage, { text: m.sso_action_error() })) : null, _jsxs("div", { className: "flex flex-wrap justify-end gap-2", children: [_jsx(Button, { autoFocus: true, variant: "outline", disabled: busy, onClick: () => {
78
+ // Restore focus after React has made the settings visible,
79
+ // before the dialog handles the removed confirmation button.
80
+ restoreRemovalFocus.current = true;
81
+ setConfirmingRemoval(false);
82
+ }, children: m.sso_cancel() }), _jsx(Button, { variant: "destructive", disabled: busy, onClick: () => remove(), children: m.sso_remove_confirm() })] })] })) : null, _jsxs("section", { className: confirmingRemoval ? "hidden" : "flex min-w-0 flex-col gap-4", children: [_jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.sso_settings_title() }), connection ? (_jsx(Badge, { variant: connection.enabled ? "default" : "secondary", role: "status", children: connection.enabled
83
+ ? m.sso_status_enabled()
84
+ : m.sso_status_disabled() })) : null] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.sso_settings_description() })] }), _jsxs("div", { className: "flex flex-col gap-3", children: [_jsx(SsoSettingsCard, { title: m.sso_connection_details(), icon: _jsx(KeyRoundIcon, { className: "size-5", "aria-hidden": "true" }), open: !connection, description: connection ? (_jsx("span", { className: "text-muted-foreground mt-1 block text-xs break-all", children: connection.domain })) : null, children: _jsx(form.Initialize, { defaultValues: {
85
+ issuer: connection?.issuer ?? "",
86
+ domain: connection?.domain ?? "",
87
+ clientId: connection?.clientId ?? "",
88
+ clientSecret: "",
89
+ }, children: _jsx("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
90
+ event.preventDefault();
91
+ event.stopPropagation();
92
+ submit();
93
+ }, children: _jsxs("fieldset", { disabled: busy, className: "contents", children: [_jsx(form.issuer, { label: m.sso_issuer(), disabled: Boolean(connection), placeholder: "https://accounts.google.com" }), _jsx(form.domain, { label: m.sso_domain(), disabled: Boolean(connection), placeholder: "example.com" }), _jsx(form.clientId, { label: m.sso_client_id(), autoComplete: "off" }), _jsx(form.clientSecret, { label: m.sso_client_secret(), type: "password", required: !connection, autoComplete: "new-password", description: connection ? m.sso_secret_unchanged() : undefined }), _jsx("p", { className: "text-muted-foreground text-sm", children: connection ? m.sso_update_help() : m.sso_save_help() }), _jsx(SubmitButton, { form: form, children: m.sso_save() })] }) }) }) }), connection ? (_jsxs(_Fragment, { children: [callbackUrl ? (_jsx(SsoSettingsCard, { title: m.sso_callback_step(), icon: _jsx(LinkIcon, { className: "size-5", "aria-hidden": "true" }), open: callbackInitiallyOpen, description: _jsx("span", { className: "text-muted-foreground mt-1 block text-xs", children: m.sso_callback_help() }), children: _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("label", { className: "text-muted-foreground text-sm", htmlFor: "sso-callback", children: m.sso_callback() }), _jsxs("div", { className: "flex min-w-0 gap-2", children: [_jsx(Input, { id: "sso-callback", readOnly: true, value: callbackUrl }), _jsx(CopyButton, { value: callbackUrl })] })] }) })) : null, _jsx(SsoSettingsCard, { title: m.sso_domain_verification(), icon: _jsx(ShieldCheckIcon, { className: "size-5", "aria-hidden": "true" }), open: !connection.domainVerified, description: _jsx(Badge, { variant: connection.domainVerified ? "default" : "secondary", className: "mt-1", children: connection.domainVerified
94
+ ? m.sso_verified()
95
+ : m.sso_unverified() }), children: connection.verificationToken ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-muted-foreground text-sm", children: m.sso_dns_help() }), _jsxs("dl", { className: "mt-3 grid gap-2 text-sm", children: [_jsx("dt", { children: m.sso_dns_name() }), _jsxs("dd", { className: "bg-muted/50 flex min-w-0 items-center gap-2 rounded-md border p-2 text-sm", children: [_jsx("code", { className: "min-w-0 flex-1 break-all", children: connection.verificationName }), _jsx(CopyButton, { value: connection.verificationName })] }), _jsx("dt", { children: m.sso_dns_value() }), _jsxs("dd", { className: "bg-muted/50 flex min-w-0 items-center gap-2 rounded-md border p-2 text-sm", children: [_jsx("code", { className: "min-w-0 flex-1 break-all", children: connection.verificationToken }), _jsx(CopyButton, { value: connection.verificationToken })] })] }), !connection.domainVerified ? (_jsx(Button, { className: "mt-3", disabled: busy, onClick: () => verify(), children: m.sso_verify() })) : null] })) : null })] })) : null] }), connection ? (_jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { variant: connection.enabled ? "outline" : "default", disabled: busy || !connection.domainVerified, onClick: () => enable(!connection.enabled), children: connection.enabled ? m.sso_disable() : m.sso_enable() }), _jsx(Button, { ref: removeButton, variant: "destructive", disabled: busy, onClick: () => setConfirmingRemoval(true), children: m.sso_remove() })] })) : null, failed ? _jsx(ErrorMessage, { text: m.sso_action_error() }) : null] })] }));
96
+ };
@@ -1,5 +1,6 @@
1
1
  import { type ComponentProps, type ReactNode } from "react";
2
- import { DropdownMenuContent } from "@/components/ui/dropdown-menu";
2
+ import { Button } from "@/components/ui/button";
3
+ import { DropdownMenuContent, type AuthUIClassNames } from "./appearance.js";
3
4
  declare const messages: {
4
5
  readonly en: {
5
6
  readonly organization_back: "Back";
@@ -292,6 +293,10 @@ export type OrganizationSwitcherFeatures = {
292
293
  userInvitations?: boolean;
293
294
  };
294
295
  export type OrganizationSwitcherProps = {
296
+ classNames?: AuthUIClassNames;
297
+ variant?: ComponentProps<typeof Button>["variant"];
298
+ size?: ComponentProps<typeof Button>["size"];
299
+ triggerBadge?: ReactNode;
295
300
  baseUrl?: string | undefined;
296
301
  side?: ComponentProps<typeof DropdownMenuContent>["side"];
297
302
  className?: string;
@@ -316,6 +321,6 @@ type OrganizationSummary = {
316
321
  userId?: string | null | undefined;
317
322
  parentId?: string | null | undefined;
318
323
  };
319
- export type OrganizationSwitcherDialog = "create" | "manage" | "members" | "apiKeys" | "invitations";
320
- export declare function OrganizationSwitcher({ baseUrl: providedBaseUrl, side, className, defaultDialog, features, hideTrigger, menuActions, renderUnauthenticated, allowedOrganizationIds, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, apiKeyPermissions, }: OrganizationSwitcherProps): import("react").JSX.Element;
324
+ export type OrganizationSwitcherDialog = "create" | "manage" | "members" | "apiKeys" | "invitations" | "security";
325
+ export declare const OrganizationSwitcher: (props: OrganizationSwitcherProps) => import("react").JSX.Element;
321
326
  export {};
@@ -4,19 +4,18 @@ import { useAtomRefresh, useAtomSet, useAtomSubscribe, useAtomValue, } from "@ef
4
4
  import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
5
5
  import { Effect, Option, Predicate, Schema } from "effect";
6
6
  import { AsyncResult, Atom } from "effect/reactivity";
7
- import { ArrowLeft, Building2, Check, ChevronsUpDown, Copy, KeyRound, LogOut, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
7
+ import { ArrowLeft, Building2, Check, ChevronsUpDown, Copy, KeyRound, LogOut, Mail, PencilIcon, Plus, ShieldCheck, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
8
8
  import { createContext, useContext, useEffect, useRef, useState, } from "react";
9
- import { DataTable, DataTableListCell, } from "@krak-stack/registry/data-table";
10
- import { CheckboxField, ImageField, SelectField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
9
+ import { DataTableListCell, } from "@krak-stack/registry/data-table";
10
+ import { CheckboxField, ImageField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
11
11
  import { EditingLocaleSwitcher } from "@krak-stack/registry/editing-locale-switcher";
12
- import { AppBrand } from "@krak-stack/registry/app-brand";
13
12
  import { FieldSet } from "@/components/ui/field";
14
13
  import { Badge } from "@/components/ui/badge";
15
14
  import { Button } from "@/components/ui/button";
16
- import { AlertDialog, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog";
15
+ import { AlertDialog } from "@/components/ui/alert-dialog";
17
16
  import { CopyButton } from "@krak-stack/registry/copy-button";
18
- import { Dialog, DialogFooter, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
19
- import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
17
+ import { Dialog } from "@/components/ui/dialog";
18
+ import { DropdownMenu, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
20
19
  import { Separator } from "@/components/ui/separator";
21
20
  import { OrganizationEmail, OrganizationAddress, OrganizationMetadata, OrganizationPhone, OrganizationSocial, OrganizationTranslation, OrganizationWebsite, decodeOrganizationMetadata, } from "@krak-stack/auth/schema";
22
21
  import { isOrganizationRole, normalizeOrganizationRole, normalizeOrganizationRoles, organizationRoles, parseRoleList, } from "../roles.js";
@@ -36,8 +35,11 @@ import { ScrollableDialogBody, ScrollableDialogContent, ScrollableDialogHeader,
36
35
  import { invitationDisplayStatus, isInvitationExpired, useInvitationExpirationClock, } from "./invitation-expiration.js";
37
36
  import { ExtraUploadedAsset } from "../extra/schema.js";
38
37
  import { assetPath, assetUrl, cn } from "./utils.js";
38
+ import { AuthUIStylesContext, AppBrand, DataTable, DialogFooter, DialogDescription, DialogHeader, DialogTitle, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, SelectField, } from "./appearance.js";
39
39
  import { AssociatedProjectsNotice } from "./associated-projects-notice.js";
40
40
  import { ExtraApiKeyPermissions } from "../extra/schema.js";
41
+ import { OrganizationSsoSettingsPanel } from "./organization-sso-settings.js";
42
+ import { organizationSsoMessages } from "./organization-sso-messages.js";
41
43
  class OrganizationActionError extends Data.TaggedError("OrganizationActionError") {
42
44
  }
43
45
  const messages = {
@@ -723,9 +725,12 @@ const organizationMetadataFromForm = Effect.fn(function* (value, m, uploadImage,
723
725
  addresses,
724
726
  };
725
727
  });
726
- export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom", className, defaultDialog = null, features, hideTrigger = false, menuActions, renderUnauthenticated, allowedOrganizationIds, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, apiKeyPermissions, }) {
728
+ export const OrganizationSwitcher = (props) => (_jsx(AuthUIStylesContext.Provider, { value: props.classNames, children: _jsx(OrganizationSwitcherContent, { ...props }) }));
729
+ const OrganizationSwitcherContent = ({ classNames, variant = "ghost", size, triggerBadge, baseUrl: providedBaseUrl, side = "bottom", className, defaultDialog = null, features, hideTrigger = false, menuActions, renderUnauthenticated, allowedOrganizationIds, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, apiKeyPermissions, }) => {
727
730
  const auth = useKrakstackAuth();
728
731
  const baseUrl = providedBaseUrl ?? auth?.baseUrl;
732
+ const locale = auth?.locale ?? getLocale();
733
+ const security = organizationSsoMessages[locale];
729
734
  const labels = organizationSwitcherMessages(messages);
730
735
  const m = organizationMessageFns(labels);
731
736
  const sessionAtom = authSessionAtom(baseUrl);
@@ -778,6 +783,9 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
778
783
  const activeMemberRoles = parseRoleList(activeOrganization?.members.find((member) => member.userId === session?.user.id)?.role);
779
784
  const canManageApiKeys = activeMemberRoles.includes("owner");
780
785
  const canUpdateOrganization = activeMemberRoles.some((role) => role === "owner" || role === "admin");
786
+ const canManageSecurity = canUpdateOrganization &&
787
+ !session?.session.impersonatedBy &&
788
+ !session?.session.impersonatedByOrganizationId;
781
789
  const canSwitchOrganizations = features?.organizationSwitching ?? true;
782
790
  const canCreateOrganization = features?.organizationCreation ?? true;
783
791
  const canViewOrganizationInvitations = features?.userInvitations ?? true;
@@ -821,13 +829,13 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
821
829
  };
822
830
  const activeDisplay = organizationDisplay(active ?? null, m, baseUrl);
823
831
  const activeSubtitle = organizationSwitcherSubtitle(active ?? null, activeDisplay.subtitle, m);
824
- return (_jsxs(OrganizationMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "ghost", className: cn("h-11 w-full justify-between gap-2 !px-1 !py-0 group-data-[collapsible=icon]:size-8 group-data-[collapsible=icon]:justify-start group-data-[collapsible=icon]:!p-0", className), children: [_jsx(AppBrand, { to: null, label: activeName
832
+ return (_jsxs(OrganizationMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: variant, size: size, "data-auth-slot": "organization-trigger", className: cn("w-full justify-between gap-2 group-data-[collapsible=icon]:size-8 group-data-[collapsible=icon]:justify-start group-data-[collapsible=icon]:!p-0", size === undefined && "h-11 !px-1 !py-0", triggerBadge != null && "relative", className), children: [triggerBadge != null ? (_jsx("span", { "data-auth-slot": "trigger-badge", className: cn("pointer-events-none absolute -top-1 -right-1 z-10", classNames?.trigger?.badge), children: triggerBadge })) : null, _jsx(AppBrand, { appearance: "trigger", to: null, label: activeName
825
833
  ? activeDisplay.name
826
834
  : activeLoading
827
835
  ? m.organization_loading()
828
836
  : m.organization_switcher_label(), subtitle: activeSubtitle, icon: Building2, variant: "sidebar", className: "min-w-0 flex-1 !p-0 text-left group-data-[collapsible=icon]:flex-none group-data-[collapsible=icon]:justify-start", ...(activeDisplay.image
829
837
  ? { imageSrc: activeDisplay.image }
830
- : {}) }), _jsx(ChevronsUpDown, { className: "text-muted-foreground size-4 shrink-0 group-data-[collapsible=icon]:hidden" })] }) }), _jsx(DropdownMenuContent, { className: "max-w-[calc(100vw-1rem)] min-w-64 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: activeDisplay.name, subtitle: activeSubtitle, icon: Building2, variant: "sidebar", className: "px-1 py-1.5 text-left text-sm", ...(activeDisplay.image
838
+ : {}) }), _jsx(ChevronsUpDown, { "data-auth-slot": "trigger-indicator", className: cn("text-muted-foreground size-4 shrink-0 group-data-[collapsible=icon]:hidden", classNames?.trigger?.indicator) })] }) }), _jsx(DropdownMenuContent, { className: "max-w-[calc(100vw-1rem)] min-w-64 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { appearance: "menuHeader", to: null, label: activeDisplay.name, subtitle: activeSubtitle, icon: Building2, variant: "sidebar", className: "px-1 py-1.5 text-left text-sm", ...(activeDisplay.image
831
839
  ? { imageSrc: activeDisplay.image }
832
840
  : {}) }) }), active ? (_jsx(AssociatedProjectsNotice, { baseUrl: baseUrl, getSummary: (count) => m.organization_projects_summary({ count }), organizationId: active.id, viewLabel: m.organization_projects_view() })) : null, menuActions ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), menuActions] })) : null, hasOrganizationListItems ? _jsx(DropdownMenuSeparator, {}) : null, organizationsResult._tag === "Initial" ? (_jsx(DropdownMenuItem, { disabled: true, children: m.organization_loading() })) : null, organizationsError ? (_jsx(DropdownMenuItem, { disabled: true, children: organizationsError })) : null, canSwitchOrganizations && selectableOrganizations.length ? (_jsx("div", { className: cn(scrollOrganizationList &&
833
841
  "max-h-64 overflow-y-auto overscroll-contain"), children: selectableOrganizations.map((organization) => {
@@ -856,7 +864,7 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
856
864
  return (_jsxs(DropdownMenuItem, { onClick: () => {
857
865
  void navigator.clipboard.writeText(organizationId);
858
866
  }, children: [_jsx(Copy, {}), m.organization_copy_id()] }));
859
- })(), canUpdateOrganization ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("manage"), children: [_jsx(PencilIcon, {}), m.organization_switcher_manage()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => setDialog("members"), children: [_jsx(Users, {}), m.organization_members_title()] }), canManageApiKeys ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })) : null, deletionControlsEnabled &&
867
+ })(), canUpdateOrganization ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("manage"), children: [_jsx(PencilIcon, {}), m.organization_switcher_manage()] })) : null, canManageSecurity ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("security"), children: [_jsx(ShieldCheck, {}), security.organization_security()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => setDialog("members"), children: [_jsx(Users, {}), m.organization_members_title()] }), canManageApiKeys ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })) : null, deletionControlsEnabled &&
860
868
  canDeleteOrganization(activeOrganization, session.user.id) ? (_jsxs(DropdownMenuItem, { variant: "destructive", onClick: () => setDeletingOrganization({
861
869
  id: activeOrganization.id,
862
870
  name: activeOrganization.name,
@@ -883,7 +891,11 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
883
891
  }
884
892
  } }) }), _jsx(Dialog, { open: dialog === "manage" && canUpdateOrganization, onOpenChange: (open) => {
885
893
  setDialog((current) => open ? "manage" : current === "manage" ? null : current);
886
- }, children: activeOrganization && canUpdateOrganization ? (_jsx(EditOrganizationSection, { header: _jsxs(DialogHeader, { className: "sm:flex-row sm:items-end sm:justify-between sm:gap-4", children: [_jsxs("div", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() })] }), _jsx("div", { className: "mt-2 w-fit sm:mt-0", children: _jsx(EditingLocaleSwitcher, { locale: auth?.locale, value: editingOrganizationLocale, onValueChange: (value) => setEditingOrganizationLocale(value === "fr" ? "fr" : "en") }) })] }), baseUrl: baseUrl, editingLocale: editingOrganizationLocale, organization: activeOrganization })) : null }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
894
+ }, children: activeOrganization && canUpdateOrganization ? (_jsx(EditOrganizationSection, { header: _jsxs(DialogHeader, { className: "sm:flex-row sm:items-end sm:justify-between sm:gap-4", children: [_jsxs("div", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() })] }), _jsx("div", { className: "mt-2 w-fit sm:mt-0", children: _jsx(EditingLocaleSwitcher, { locale: auth?.locale, value: editingOrganizationLocale, onValueChange: (value) => setEditingOrganizationLocale(value === "fr" ? "fr" : "en") }) })] }), baseUrl: baseUrl, editingLocale: editingOrganizationLocale, organization: activeOrganization })) : null }), _jsx(Dialog, { open: dialog === "security" &&
895
+ canManageSecurity &&
896
+ Boolean(activeOrganization), onOpenChange: (open) => {
897
+ setDialog((current) => open ? "security" : current === "security" ? null : current);
898
+ }, children: dialog === "security" && activeOrganization && canManageSecurity ? (_jsxs(ScrollableDialogContent, { size: "2xl", children: [_jsx(ScrollableDialogHeader, { children: _jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: security.organization_security() }), _jsx(DialogDescription, { children: security.organization_security_description() })] }) }), _jsx(ScrollableDialogBody, { children: _jsx(OrganizationSsoSettingsPanel, { organizationId: activeOrganization.id, baseUrl: baseUrl, locale: locale }, JSON.stringify([baseUrl, activeOrganization.id])) })] })) : null }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
887
899
  setDialog((current) => open ? "members" : current === "members" ? null : current);
888
900
  }, children: _jsx(ScrollableDialogContent, { size: "4xl", children: activeOrganization ? (_jsx(OrganizationMembersManager, { baseUrl: baseUrl, canManageMembers: canUpdateOrganization, organization: activeOrganization, currentUserId: session.user.id, active: dialog === "members", onLeft: () => {
889
901
  setDialog(null);
@@ -897,7 +909,7 @@ export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom"
897
909
  }, children: _jsxs(ScrollableDialogContent, { size: "4xl", children: [_jsx(ScrollableDialogHeader, { children: _jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_user_invitations_title() }), _jsx(DialogDescription, { children: m.organization_user_invitations_description() })] }) }), _jsx(ScrollableDialogBody, { children: _jsx(UserInvitationsManager, { baseUrl: baseUrl, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError, ...(activeOrganization
898
910
  ? { activeOrganizationId: activeOrganization.id }
899
911
  : {}), onActionComplete: refreshAfterInvitationAction }) })] }) })] }));
900
- }
912
+ };
901
913
  const OrganizationDeletionDialog = ({ baseUrl, organization, onClose, onDeleted, }) => {
902
914
  const auth = useKrakstackAuth();
903
915
  const labels = adminOrganizationsMessages(auth?.locale ?? "en");
@@ -1,7 +1,8 @@
1
1
  import type { ComponentProps, ReactNode } from "react";
2
- import { DialogContent } from "@/components/ui/dialog";
2
+ import { DialogContent } from "./appearance.js";
3
3
  type ScrollableDialogSize = "2xl" | "3xl" | "4xl" | "6xl";
4
- export declare const ScrollableDialogContent: ({ children, size, ...props }: Omit<ComponentProps<typeof DialogContent>, "className"> & {
4
+ export declare const ScrollableDialogContent: ({ children, size, className, ...props }: Omit<ComponentProps<typeof DialogContent>, "className"> & {
5
+ readonly className?: string;
5
6
  readonly children: ReactNode;
6
7
  readonly size: ScrollableDialogSize;
7
8
  }) => import("react").JSX.Element;
@@ -1,12 +1,19 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { DialogContent } from "@/components/ui/dialog";
2
+ import { DialogContent, useAuthUIStyles } from "./appearance.js";
3
3
  import { Separator } from "@/components/ui/separator";
4
+ import { cn } from "./utils.js";
4
5
  const widthClass = {
5
6
  "2xl": "sm:max-w-2xl",
6
7
  "3xl": "sm:max-w-3xl",
7
8
  "4xl": "sm:max-w-4xl",
8
9
  "6xl": "sm:max-w-6xl",
9
10
  };
10
- export const ScrollableDialogContent = ({ children, size, ...props }) => (_jsx(DialogContent, { className: `grid max-h-[85vh] min-w-0 grid-rows-[auto_minmax(0,1fr)_auto] gap-0 overflow-hidden ${widthClass[size]}`, ...props, children: children }));
11
- export const ScrollableDialogHeader = ({ children, className = "", ...props }) => (_jsxs("div", { className: `flex flex-col gap-6 pb-6 ${className}`, ...props, children: [children, _jsx(Separator, {})] }));
12
- export const ScrollableDialogBody = ({ children, className = "", padding = "default", ...props }) => (_jsx("div", { className: "-mx-6 min-h-0 overflow-y-auto", ...props, children: _jsx("div", { className: `min-w-0 px-6 pt-1 ${padding === "form" ? "pb-6" : "pb-2"} ${className}`, children: children }) }));
11
+ export const ScrollableDialogContent = ({ children, size, className, ...props }) => (_jsx(DialogContent, { className: cn(`grid max-h-[85vh] min-w-0 grid-rows-[auto_minmax(0,1fr)_auto] gap-0 overflow-hidden ${widthClass[size]}`, className), ...props, children: children }));
12
+ export const ScrollableDialogHeader = ({ children, className = "", ...props }) => {
13
+ const styles = useAuthUIStyles();
14
+ return (_jsxs("div", { "data-auth-slot": "dialog-header", className: cn("flex flex-col gap-6 pb-6", styles?.dialog?.header, className), ...props, children: [children, _jsx(Separator, {})] }));
15
+ };
16
+ export const ScrollableDialogBody = ({ children, className = "", padding = "default", ...props }) => {
17
+ const styles = useAuthUIStyles();
18
+ return (_jsx("div", { "data-auth-slot": "dialog-body", className: cn("-mx-6 min-h-0 overflow-y-auto", styles?.dialog?.body), ...props, children: _jsx("div", { "data-auth-slot": "form-scope", className: cn(`min-w-0 px-6 pt-1 ${padding === "form" ? "pb-6" : "pb-2"}`, styles?.form?.content, className), children: children }) }));
19
+ };
@@ -1,6 +1,7 @@
1
1
  import { Schema } from "effect";
2
2
  import { type ComponentProps, type ReactNode } from "react";
3
- import { DropdownMenuContent } from "@/components/ui/dropdown-menu";
3
+ import { Button } from "@/components/ui/button";
4
+ import { DropdownMenuContent, type AuthUIClassNames } from "./appearance.js";
4
5
  import { type ContactEmail as ContactEmailValue, type ContactPhone as ContactPhoneValue, type ContactSocial as ContactSocialValue, type ContactWebsite as ContactWebsiteValue, UserMetadata } from "../schema.js";
5
6
  declare const messages: {
6
7
  readonly en: {
@@ -366,6 +367,11 @@ export declare const UserContactSocialsForm: Schema.$Array<Schema.Struct<{
366
367
  }>>;
367
368
  export declare const userMetadataFromForm: (value: UserFormType) => UserMetadata;
368
369
  export type UserButtonProps = {
370
+ className?: string;
371
+ classNames?: AuthUIClassNames;
372
+ variant?: ComponentProps<typeof Button>["variant"];
373
+ size?: ComponentProps<typeof Button>["size"];
374
+ triggerBadge?: ReactNode;
369
375
  baseUrl?: string | undefined;
370
376
  signOutRedirect?: string;
371
377
  side?: ComponentProps<typeof DropdownMenuContent>["side"];
@@ -379,5 +385,5 @@ export type UserButtonProps = {
379
385
  onDialogChange?: (dialog: UserButtonDialog | null) => void;
380
386
  };
381
387
  export type UserButtonDialog = "deleteAccount" | "account" | "security" | "apiKeys" | "adminUsers" | "adminOrganizations";
382
- export declare const UserButton: ({ baseUrl, signOutRedirect, side, defaultDialog, hideTrigger, renderUnauthenticated, menuActions, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }: UserButtonProps) => import("react").JSX.Element;
388
+ export declare const UserButton: (props: UserButtonProps) => import("react").JSX.Element;
383
389
  export {};
@@ -8,15 +8,14 @@ import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
8
8
  import { ArrowLeft, Building2, KeyRound, Loader2, LogOutIcon, Mail, Pencil, Plus, ShieldCheck, StopCircle, Trash2, UserCircleIcon, Users, UserIcon, } from "lucide-react";
9
9
  import { QRCode } from "react-qr-code";
10
10
  import { createContext, useContext, useRef, useEffect, useState, } from "react";
11
- import { DataTable, } from "@krak-stack/registry/data-table";
12
- import { AppBrand } from "@krak-stack/registry/app-brand";
11
+ import {} from "@krak-stack/registry/data-table";
13
12
  import { EditingLocaleSwitcher } from "@krak-stack/registry/editing-locale-switcher";
14
13
  import { effectFormMessages, ImageField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
15
14
  import { Badge } from "@/components/ui/badge";
16
15
  import { Button } from "@/components/ui/button";
17
16
  import { CopyButton } from "@krak-stack/registry/copy-button";
18
- import { Dialog, DialogFooter, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
19
- import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
17
+ import { Dialog } from "@/components/ui/dialog";
18
+ import { DropdownMenu, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
20
19
  import { Separator } from "@/components/ui/separator";
21
20
  import { FieldLabel } from "@/components/ui/field";
22
21
  import { Input } from "@/components/ui/input";
@@ -32,7 +31,8 @@ import { ApiKeyRateLimit, apiKeyUsagePercent } from "./api-key-rate-limit.js";
32
31
  import { ApiKeyReferrers } from "./api-key-referrers.js";
33
32
  import { useLatestAtom, useOpenedOnce } from "./hooks.js";
34
33
  import { ExtraUploadedAsset } from "../extra/schema.js";
35
- import { assetPath, assetUrl } from "./utils.js";
34
+ import { assetPath, assetUrl, cn } from "./utils.js";
35
+ import { AuthUIStylesContext, AppBrand, DataTable, DialogFooter, DialogDescription, DialogHeader, DialogTitle, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, } from "./appearance.js";
36
36
  import { AdminOrganizationsTable } from "./admin-organizations.js";
37
37
  import { AdminUsersTable } from "./admin-users.js";
38
38
  import { ScrollableDialogBody, ScrollableDialogContent, ScrollableDialogHeader, } from "./scrollable-dialog.js";
@@ -528,7 +528,8 @@ const userApiKeysAtom = Atom.family((baseUrl) => Atom.keepAlive(Atom.map(authCli
528
528
  reactivityKeys: ["user-api-keys", baseUrl],
529
529
  }), AsyncResult.map(({ apiKeys }) => Array.from(apiKeys)))));
530
530
  const emptyApiKeysAtom = Atom.make(Effect.succeed(Array()));
531
- export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", defaultDialog = null, hideTrigger = false, renderUnauthenticated, menuActions, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }) => {
531
+ export const UserButton = (props) => (_jsx(AuthUIStylesContext.Provider, { value: props.classNames, children: _jsx(UserButtonContent, { ...props }) }));
532
+ const UserButtonContent = ({ className, classNames, variant = "outline", size = "icon", triggerBadge, baseUrl, signOutRedirect = "/", side = "bottom", defaultDialog = null, hideTrigger = false, renderUnauthenticated, menuActions, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }) => {
532
533
  const auth = useKrakstackAuth();
533
534
  const resolvedBaseUrl = baseUrl ?? auth?.baseUrl;
534
535
  const labels = userButtonMessages(messages);
@@ -638,7 +639,7 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
638
639
  : `${import.meta.env.VITE_SITE_URL}${signOutRedirect.startsWith("/") ? signOutRedirect : `/${signOutRedirect}`}`;
639
640
  signOut({ baseUrl: resolvedBaseUrl, redirectUrl });
640
641
  };
641
- 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 } : {}) }) }), _jsx(AssociatedProjectsNotice, { baseUrl: resolvedBaseUrl, getSummary: (count) => m.user_form_projects_summary({ count }), viewLabel: m.user_form_projects_view() }), 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, deletionControlsEnabled &&
642
+ return (_jsxs(UserButtonMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: variant, size: size, "data-auth-slot": "user-trigger", className: cn(triggerBadge != null ? "relative" : "overflow-hidden", className), children: [triggerBadge != null ? (_jsx("span", { "data-auth-slot": "trigger-badge", className: cn("pointer-events-none absolute -top-1 -right-1 z-10", classNames?.trigger?.badge), children: triggerBadge })) : null, _jsx("span", { "data-auth-slot": "trigger-visual", className: cn("flex size-full items-center justify-center overflow-hidden rounded-[inherit]", classNames?.trigger?.visual), children: displayImage ? (_jsx("img", { src: displayImage, alt: displayName || displayEmail, "data-auth-slot": "trigger-image", className: cn("size-full object-cover", classNames?.trigger?.image) })) : (_jsx(UserIcon, { "data-auth-slot": "trigger-icon", className: cn("size-4.5", classNames?.trigger?.icon) })) }), _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, { appearance: "menuHeader", 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 } : {}) }) }), _jsx(AssociatedProjectsNotice, { baseUrl: resolvedBaseUrl, getSummary: (count) => m.user_form_projects_summary({ count }), viewLabel: m.user_form_projects_view() }), 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, deletionControlsEnabled &&
642
643
  !isImpersonating &&
643
644
  !isOrganizationImpersonating ? (_jsxs(DropdownMenuItem, { variant: "destructive", onClick: () => setSettingsDialog("deleteAccount"), children: [_jsx(Trash2, {}), m.user_delete_title()] })) : 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({
644
645
  baseUrl: resolvedBaseUrl,