@krak-stack/auth 0.3.3 → 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.
- package/CHANGELOG.md +14 -0
- package/dist/api.d.ts +248 -2
- package/dist/auth/api.group.d.ts +124 -1
- package/dist/auth/api.group.js +36 -1
- package/dist/auth/schema.d.ts +38 -0
- package/dist/auth/schema.js +38 -0
- package/dist/components/auth-client-api.d.ts +130 -0
- package/dist/components/auth-forms.d.ts +5 -1
- package/dist/components/auth-forms.js +60 -7
- package/dist/components/organization-sso-atom.d.ts +71 -0
- package/dist/components/organization-sso-atom.js +40 -0
- package/dist/components/organization-sso-messages.d.ts +76 -0
- package/dist/components/organization-sso-messages.js +77 -0
- package/dist/components/organization-sso-settings.d.ts +6 -0
- package/dist/components/organization-sso-settings.js +96 -0
- package/dist/components/organization-switcher.d.ts +1 -1
- package/dist/components/organization-switcher.js +14 -3
- package/dist/service.d.ts +260 -0
- package/package.json +1 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export declare const organizationSsoMessages: {
|
|
2
|
+
en: {
|
|
3
|
+
organization_security: () => string;
|
|
4
|
+
organization_security_description: () => string;
|
|
5
|
+
sso_settings_title: () => string;
|
|
6
|
+
sso_settings_description: () => string;
|
|
7
|
+
sso_connection_details: () => string;
|
|
8
|
+
sso_callback_step: () => string;
|
|
9
|
+
sso_callback_help: () => string;
|
|
10
|
+
sso_status_enabled: () => string;
|
|
11
|
+
sso_status_disabled: () => string;
|
|
12
|
+
sso_update_help: () => string;
|
|
13
|
+
sso_loading: () => string;
|
|
14
|
+
sso_load_error: () => string;
|
|
15
|
+
sso_issuer: () => string;
|
|
16
|
+
sso_domain: () => string;
|
|
17
|
+
sso_client_id: () => string;
|
|
18
|
+
sso_client_secret: () => string;
|
|
19
|
+
sso_secret_unchanged: () => string;
|
|
20
|
+
sso_save_help: () => string;
|
|
21
|
+
sso_save: () => string;
|
|
22
|
+
sso_callback: () => string;
|
|
23
|
+
sso_domain_verification: () => string;
|
|
24
|
+
sso_dns_help: () => string;
|
|
25
|
+
sso_dns_name: () => string;
|
|
26
|
+
sso_dns_value: () => string;
|
|
27
|
+
sso_verified: () => string;
|
|
28
|
+
sso_unverified: () => string;
|
|
29
|
+
sso_verify: () => string;
|
|
30
|
+
sso_enable: () => string;
|
|
31
|
+
sso_disable: () => string;
|
|
32
|
+
sso_remove: () => string;
|
|
33
|
+
sso_remove_title: () => string;
|
|
34
|
+
sso_remove_warning: () => string;
|
|
35
|
+
sso_remove_confirm: () => string;
|
|
36
|
+
sso_cancel: () => string;
|
|
37
|
+
sso_action_error: () => string;
|
|
38
|
+
};
|
|
39
|
+
fr: {
|
|
40
|
+
organization_security: () => string;
|
|
41
|
+
organization_security_description: () => string;
|
|
42
|
+
sso_settings_title: () => string;
|
|
43
|
+
sso_settings_description: () => string;
|
|
44
|
+
sso_connection_details: () => string;
|
|
45
|
+
sso_callback_step: () => string;
|
|
46
|
+
sso_callback_help: () => string;
|
|
47
|
+
sso_status_enabled: () => string;
|
|
48
|
+
sso_status_disabled: () => string;
|
|
49
|
+
sso_update_help: () => string;
|
|
50
|
+
sso_loading: () => string;
|
|
51
|
+
sso_load_error: () => string;
|
|
52
|
+
sso_issuer: () => string;
|
|
53
|
+
sso_domain: () => string;
|
|
54
|
+
sso_client_id: () => string;
|
|
55
|
+
sso_client_secret: () => string;
|
|
56
|
+
sso_secret_unchanged: () => string;
|
|
57
|
+
sso_save_help: () => string;
|
|
58
|
+
sso_save: () => string;
|
|
59
|
+
sso_callback: () => string;
|
|
60
|
+
sso_domain_verification: () => string;
|
|
61
|
+
sso_dns_help: () => string;
|
|
62
|
+
sso_dns_name: () => string;
|
|
63
|
+
sso_dns_value: () => string;
|
|
64
|
+
sso_verified: () => string;
|
|
65
|
+
sso_unverified: () => string;
|
|
66
|
+
sso_verify: () => string;
|
|
67
|
+
sso_enable: () => string;
|
|
68
|
+
sso_disable: () => string;
|
|
69
|
+
sso_remove: () => string;
|
|
70
|
+
sso_remove_title: () => string;
|
|
71
|
+
sso_remove_warning: () => string;
|
|
72
|
+
sso_remove_confirm: () => string;
|
|
73
|
+
sso_cancel: () => string;
|
|
74
|
+
sso_action_error: () => string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -321,6 +321,6 @@ type OrganizationSummary = {
|
|
|
321
321
|
userId?: string | null | undefined;
|
|
322
322
|
parentId?: string | null | undefined;
|
|
323
323
|
};
|
|
324
|
-
export type OrganizationSwitcherDialog = "create" | "manage" | "members" | "apiKeys" | "invitations";
|
|
324
|
+
export type OrganizationSwitcherDialog = "create" | "manage" | "members" | "apiKeys" | "invitations" | "security";
|
|
325
325
|
export declare const OrganizationSwitcher: (props: OrganizationSwitcherProps) => import("react").JSX.Element;
|
|
326
326
|
export {};
|
|
@@ -4,7 +4,7 @@ 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
9
|
import { DataTableListCell, } from "@krak-stack/registry/data-table";
|
|
10
10
|
import { CheckboxField, ImageField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
|
|
@@ -38,6 +38,8 @@ import { assetPath, assetUrl, cn } from "./utils.js";
|
|
|
38
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 = {
|
|
@@ -727,6 +729,8 @@ export const OrganizationSwitcher = (props) => (_jsx(AuthUIStylesContext.Provide
|
|
|
727
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, }) => {
|
|
728
730
|
const auth = useKrakstackAuth();
|
|
729
731
|
const baseUrl = providedBaseUrl ?? auth?.baseUrl;
|
|
732
|
+
const locale = auth?.locale ?? getLocale();
|
|
733
|
+
const security = organizationSsoMessages[locale];
|
|
730
734
|
const labels = organizationSwitcherMessages(messages);
|
|
731
735
|
const m = organizationMessageFns(labels);
|
|
732
736
|
const sessionAtom = authSessionAtom(baseUrl);
|
|
@@ -779,6 +783,9 @@ const OrganizationSwitcherContent = ({ classNames, variant = "ghost", size, trig
|
|
|
779
783
|
const activeMemberRoles = parseRoleList(activeOrganization?.members.find((member) => member.userId === session?.user.id)?.role);
|
|
780
784
|
const canManageApiKeys = activeMemberRoles.includes("owner");
|
|
781
785
|
const canUpdateOrganization = activeMemberRoles.some((role) => role === "owner" || role === "admin");
|
|
786
|
+
const canManageSecurity = canUpdateOrganization &&
|
|
787
|
+
!session?.session.impersonatedBy &&
|
|
788
|
+
!session?.session.impersonatedByOrganizationId;
|
|
782
789
|
const canSwitchOrganizations = features?.organizationSwitching ?? true;
|
|
783
790
|
const canCreateOrganization = features?.organizationCreation ?? true;
|
|
784
791
|
const canViewOrganizationInvitations = features?.userInvitations ?? true;
|
|
@@ -857,7 +864,7 @@ const OrganizationSwitcherContent = ({ classNames, variant = "ghost", size, trig
|
|
|
857
864
|
return (_jsxs(DropdownMenuItem, { onClick: () => {
|
|
858
865
|
void navigator.clipboard.writeText(organizationId);
|
|
859
866
|
}, children: [_jsx(Copy, {}), m.organization_copy_id()] }));
|
|
860
|
-
})(), 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 &&
|
|
861
868
|
canDeleteOrganization(activeOrganization, session.user.id) ? (_jsxs(DropdownMenuItem, { variant: "destructive", onClick: () => setDeletingOrganization({
|
|
862
869
|
id: activeOrganization.id,
|
|
863
870
|
name: activeOrganization.name,
|
|
@@ -884,7 +891,11 @@ const OrganizationSwitcherContent = ({ classNames, variant = "ghost", size, trig
|
|
|
884
891
|
}
|
|
885
892
|
} }) }), _jsx(Dialog, { open: dialog === "manage" && canUpdateOrganization, onOpenChange: (open) => {
|
|
886
893
|
setDialog((current) => open ? "manage" : current === "manage" ? null : current);
|
|
887
|
-
}, 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 === "
|
|
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) => {
|
|
888
899
|
setDialog((current) => open ? "members" : current === "members" ? null : current);
|
|
889
900
|
}, children: _jsx(ScrollableDialogContent, { size: "4xl", children: activeOrganization ? (_jsx(OrganizationMembersManager, { baseUrl: baseUrl, canManageMembers: canUpdateOrganization, organization: activeOrganization, currentUserId: session.user.id, active: dialog === "members", onLeft: () => {
|
|
890
901
|
setDialog(null);
|