@krak-stack/auth 0.1.28 → 0.1.30

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.
@@ -1,4 +1,5 @@
1
1
  export { OrganizationSwitcher } from "./organization-switcher";
2
+ export { ResetPassword, Signin, Signup, TwoFactor } from "./auth-forms";
2
3
  export { UserButton } from "./user-button";
3
4
  export type { OrganizationSwitcherDialog } from "./organization-switcher";
4
5
  export type { UserButtonDialog } from "./user-button";
@@ -1,2 +1,3 @@
1
1
  export { OrganizationSwitcher } from "./organization-switcher";
2
+ export { ResetPassword, Signin, Signup, TwoFactor } from "./auth-forms";
2
3
  export { UserButton } from "./user-button";
@@ -1,10 +1,11 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useAtomSet } from "@effect/atom-react";
2
+ import { useAtomRefresh, useAtomSet, useAtomValue } from "@effect/atom-react";
3
3
  import { useStore } from "@tanstack/react-form";
4
4
  import {} from "@tanstack/react-table";
5
- import { Schema } from "effect";
5
+ import { Effect, Schema } from "effect";
6
+ import { AsyncResult, Atom } from "effect/unstable/reactivity";
6
7
  import { Building2, Check, ChevronsUpDown, Copy, KeyRound, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
7
- import { createContext, useContext, useEffect, useEffectEvent, useState, } from "react";
8
+ import { createContext, useContext, useEffect, useState, } from "react";
8
9
  import { DataTable } from "@/components/ui/data-table";
9
10
  import { EditingLocaleSwitcher } from "@/components/ui/editing-locale-switcher";
10
11
  import { AppBrand } from "@/components/ui/app-brand";
@@ -19,7 +20,8 @@ import { cn } from "@/lib/utils";
19
20
  import { OrganizationMetadata, } from "@krak-stack/auth/schema";
20
21
  import { authApiClient } from "./auth-api-client";
21
22
  import { createApiKey } from "./api-key";
22
- import { ExtraPresignedUpload } from "../extra/schema";
23
+ import { useOpenedOnce } from "./hooks";
24
+ import { ExtraUploadedAsset } from "../extra/schema";
23
25
  import { assetPath, assetUrl } from "./utils";
24
26
  const messages = {
25
27
  en: {
@@ -200,6 +202,56 @@ const organizationMessageFns = (labels) => new Proxy({}, {
200
202
  });
201
203
  const OrganizationMessagesContext = createContext(organizationMessageFns(organizationSwitcherMessages()));
202
204
  const useOrganizationMessages = () => useContext(OrganizationMessagesContext);
205
+ const userInvitationsAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make(Effect.tryPromise({
206
+ try: async () => {
207
+ const result = await authClient.organization.listUserInvitations({});
208
+ if (result.error) {
209
+ throw new Error(result.error.message ??
210
+ "Could not load organization invitations.");
211
+ }
212
+ return result.data ?? [];
213
+ },
214
+ catch: (error) => error,
215
+ }))));
216
+ const emptyUserInvitationsAtom = Atom.make(Effect.succeed([]));
217
+ const organizationMembersAtom = Atom.family((authClient) => Atom.family((organizationId) => Atom.keepAlive(Atom.make(Effect.tryPromise({
218
+ try: async () => {
219
+ const [membersResult, invitationsResult] = await Promise.all([
220
+ authClient.organization.listMembers({
221
+ query: { organizationId },
222
+ }),
223
+ authClient.organization.listInvitations({
224
+ query: { organizationId },
225
+ }),
226
+ ]);
227
+ if (membersResult.error) {
228
+ throw new Error(membersResult.error.message ?? "Could not load members.");
229
+ }
230
+ if (invitationsResult.error) {
231
+ throw new Error(invitationsResult.error.message ??
232
+ "Could not load invitations.");
233
+ }
234
+ return {
235
+ members: membersResult.data?.members ?? [],
236
+ invitations: invitationsResult.data ?? [],
237
+ };
238
+ },
239
+ catch: (error) => error,
240
+ })))));
241
+ const emptyOrganizationMembersAtom = Atom.make(Effect.succeed({ members: [], invitations: [] }));
242
+ const organizationApiKeysAtom = Atom.family((authClient) => Atom.family((organizationId) => Atom.keepAlive(Atom.make(Effect.tryPromise({
243
+ try: async () => {
244
+ const result = await authClient.apiKey.list({
245
+ query: { configId: "organization", organizationId },
246
+ });
247
+ if (result.error) {
248
+ throw new Error(result.error.message ?? "Could not load API keys.");
249
+ }
250
+ return result.data?.apiKeys ?? [];
251
+ },
252
+ catch: (error) => error,
253
+ })))));
254
+ const emptyOrganizationApiKeysAtom = Atom.make(Effect.succeed([]));
203
255
  const slugify = (value) => value
204
256
  .trim()
205
257
  .toLowerCase()
@@ -218,21 +270,17 @@ const isOrganizationSlugConflict = (error) => {
218
270
  });
219
271
  };
220
272
  const nullableString = (value) => typeof value === "string" && value.trim() ? value.trim() : null;
221
- const decodePresignedUpload = Schema.decodeUnknownPromise(ExtraPresignedUpload);
222
- const uploadOrganizationLogo = async (file, m, presignOrganizationLogo) => {
223
- const contentType = file.type || "image/png";
224
- const presigned = await decodePresignedUpload(await presignOrganizationLogo({
225
- payload: { fileName: file.name, contentType },
226
- }));
227
- const uploadResponse = await fetch(presigned.uploadUrl, {
228
- method: "PUT",
229
- headers: { "Content-Type": contentType },
230
- body: file,
231
- });
232
- if (!uploadResponse.ok) {
273
+ const decodeUploadedAsset = Schema.decodeUnknownPromise(ExtraUploadedAsset);
274
+ const uploadOrganizationLogoAsset = async (file, m, uploadOrganizationLogo) => {
275
+ const payload = new FormData();
276
+ payload.append("file", file);
277
+ try {
278
+ const uploaded = await decodeUploadedAsset(await uploadOrganizationLogo({ payload }));
279
+ return assetPath(uploaded.url);
280
+ }
281
+ catch {
233
282
  throw new Error(m.organization_logo_upload_error());
234
283
  }
235
- return assetPath(presigned.url);
236
284
  };
237
285
  const currentOrganizationLocale = () => getLocale() === "fr" ? "fr" : "en";
238
286
  const parseOrganizationMetadata = (metadata) => {
@@ -281,9 +329,9 @@ const organizationFormDefaults = (organization, baseUrl) => {
281
329
  frLocation: fr?.location ?? "",
282
330
  };
283
331
  };
284
- const organizationLogoFromForm = async (value, m, presignOrganizationLogo) => {
332
+ const organizationLogoFromForm = async (value, m, uploadOrganizationLogo) => {
285
333
  if (value instanceof File)
286
- return await uploadOrganizationLogo(value, m, presignOrganizationLogo);
334
+ return await uploadOrganizationLogoAsset(value, m, uploadOrganizationLogo);
287
335
  if (typeof value === "string")
288
336
  return assetPath(value);
289
337
  return null;
@@ -301,14 +349,14 @@ const organizationRoleLabel = (role, m) => {
301
349
  }
302
350
  };
303
351
  const formatOrganizationDate = (date) => new Intl.DateTimeFormat(getLocale(), { dateStyle: "medium" }).format(new Date(date));
304
- const organizationMetadataFromForm = async (value, m, presignOrganizationLogo) => {
352
+ const organizationMetadataFromForm = async (value, m, uploadOrganizationLogo) => {
305
353
  const translations = [];
306
354
  const enName = value.enName.trim() || value.name.trim();
307
355
  const frName = value.frName.trim();
308
- const enLogo = await organizationLogoFromForm(value.enLogo, m, presignOrganizationLogo);
309
- const enIcon = await organizationLogoFromForm(value.enIcon, m, presignOrganizationLogo);
310
- const frLogo = await organizationLogoFromForm(value.frLogo, m, presignOrganizationLogo);
311
- const frIcon = await organizationLogoFromForm(value.frIcon, m, presignOrganizationLogo);
356
+ const enLogo = await organizationLogoFromForm(value.enLogo, m, uploadOrganizationLogo);
357
+ const enIcon = await organizationLogoFromForm(value.enIcon, m, uploadOrganizationLogo);
358
+ const frLogo = await organizationLogoFromForm(value.frLogo, m, uploadOrganizationLogo);
359
+ const frIcon = await organizationLogoFromForm(value.frIcon, m, uploadOrganizationLogo);
312
360
  if (enName) {
313
361
  translations.push({
314
362
  locale: "en",
@@ -339,24 +387,22 @@ export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", cla
339
387
  const activeOrganization = authClient.useActiveOrganization();
340
388
  const [uncontrolledDialog, setUncontrolledDialog] = useState(defaultDialog);
341
389
  const dialog = controlledDialog !== undefined ? controlledDialog : uncontrolledDialog;
342
- const sessionUserId = session.data?.user.id;
343
- const [userInvitations, setUserInvitations] = useState([]);
344
- const [userInvitationsError, setUserInvitationsError] = useState(null);
345
- const [loadingUserInvitations, setLoadingUserInvitations] = useState(false);
346
- const loadUserInvitations = useEffectEvent(async () => {
347
- if (!session.data)
348
- return;
349
- setLoadingUserInvitations(true);
350
- setUserInvitationsError(null);
351
- const result = await authClient.organization.listUserInvitations({});
352
- if (result.error) {
353
- setUserInvitationsError(result.error.message ?? m.organization_invitations_load_error());
354
- setLoadingUserInvitations(false);
355
- return;
356
- }
357
- setUserInvitations(result.data ?? []);
358
- setLoadingUserInvitations(false);
390
+ const invitationsAtom = session.data
391
+ ? userInvitationsAtom(authClient)
392
+ : emptyUserInvitationsAtom;
393
+ const invitationsResult = useAtomValue(invitationsAtom);
394
+ const refreshUserInvitations = useAtomRefresh(invitationsAtom);
395
+ const userInvitations = AsyncResult.match(invitationsResult, {
396
+ onInitial: () => [],
397
+ onFailure: () => [],
398
+ onSuccess: ({ value }) => Array.from(value),
399
+ });
400
+ const userInvitationsError = AsyncResult.match(invitationsResult, {
401
+ onInitial: () => null,
402
+ onFailure: () => m.organization_invitations_load_error(),
403
+ onSuccess: () => null,
359
404
  });
405
+ const loadingUserInvitations = invitationsResult._tag === "Initial";
360
406
  const setDialog = (next) => {
361
407
  const nextDialog = typeof next === "function" ? next(dialog) : next;
362
408
  if (nextDialog === dialog)
@@ -366,11 +412,6 @@ export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", cla
366
412
  onDialogChange?.(nextDialog);
367
413
  };
368
414
  const openCreate = () => setDialog("create");
369
- useEffect(() => {
370
- if (!sessionUserId)
371
- return;
372
- void loadUserInvitations();
373
- }, [sessionUserId]);
374
415
  if (!session.data) {
375
416
  return _jsx(_Fragment, { children: renderUnauthenticated?.() });
376
417
  }
@@ -386,7 +427,7 @@ export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", cla
386
427
  await session.refetch();
387
428
  };
388
429
  const refreshAfterInvitationAction = async (previousActiveId) => {
389
- await loadUserInvitations();
430
+ refreshUserInvitations();
390
431
  await refresh();
391
432
  if (locked && previousActiveId) {
392
433
  const result = await authClient.organization.setActive({
@@ -420,7 +461,6 @@ export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", cla
420
461
  ? m.organization_switcher_no_other_organizations()
421
462
  : m.organization_switcher_empty() })) : null, _jsx(DropdownMenuSeparator, {}), !locked ? (_jsxs(DropdownMenuItem, { onClick: openCreate, children: [_jsx(Plus, {}), m.organization_create_title()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => {
422
463
  setDialog("invitations");
423
- void loadUserInvitations();
424
464
  }, children: [_jsx(Mail, {}), _jsxs("span", { className: "flex flex-1 items-center justify-between gap-3", children: [m.organization_user_invitations_title(), userInvitations.length ? (_jsx(Badge, { variant: "secondary", children: userInvitations.length })) : null] })] }), activeOrganization.data ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onClick: () => {
425
465
  void navigator.clipboard.writeText(activeOrganization.data.id);
426
466
  }, children: [_jsx(Copy, {}), m.organization_copy_id()] }), _jsxs(DropdownMenuItem, { onClick: () => setDialog("manage"), children: [_jsx(PencilIcon, {}), m.organization_switcher_manage()] }), _jsxs(DropdownMenuItem, { onClick: () => setDialog("members"), children: [_jsx(Users, {}), m.organization_members_title()] }), _jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })] })) : null] }) })] })), _jsx(Dialog, { open: dialog === "create", onOpenChange: (open) => {
@@ -439,9 +479,9 @@ export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", cla
439
479
  setDialog((current) => open ? "manage" : current === "manage" ? null : current);
440
480
  }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(EditOrganizationSection, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
441
481
  setDialog((current) => open ? "members" : current === "members" ? null : current);
442
- }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-x-hidden overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_members_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationMembersManager, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, currentUserId: session.data.user.id })) : null] }) }), _jsx(Dialog, { open: dialog === "apiKeys", onOpenChange: (open) => {
482
+ }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-x-hidden overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_members_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationMembersManager, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, currentUserId: session.data.user.id, active: dialog === "members" })) : null] }) }), _jsx(Dialog, { open: dialog === "apiKeys", onOpenChange: (open) => {
443
483
  setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
444
- }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_api_keys_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationApiKeyManager, { authClient: authClient, organization: activeOrganization.data })) : null] }) }), _jsx(Dialog, { open: dialog === "invitations", onOpenChange: (open) => {
484
+ }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_api_keys_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationApiKeyManager, { authClient: authClient, organization: activeOrganization.data, active: dialog === "apiKeys" })) : null] }) }), _jsx(Dialog, { open: dialog === "invitations", onOpenChange: (open) => {
445
485
  setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
446
486
  }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_user_invitations_title() }), _jsx(DialogDescription, { children: m.organization_user_invitations_description() })] }), _jsx(Separator, {}), _jsx(UserInvitationsManager, { authClient: authClient, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError, activeOrganizationId: activeOrganization.data?.id, onActionComplete: refreshAfterInvitationAction })] }) })] }));
447
487
  }
@@ -523,7 +563,7 @@ const userInvitationRowActions = ({ m, actingInvitationId, onAccept, onReject, }
523
563
  ];
524
564
  function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated, }) {
525
565
  const m = useOrganizationMessages();
526
- const presignOrganizationLogo = useAtomSet(authApiClient(baseUrl).mutation("authExtra", "presign"), { mode: "promise" });
566
+ const uploadOrganizationLogo = useAtomSet(authApiClient(baseUrl).mutation("authExtra", "uploadOrganizationLogo"), { mode: "promise" });
527
567
  const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
528
568
  const defaultValues = organizationFormDefaults(organization, baseUrl);
529
569
  const form = useAppForm({
@@ -533,7 +573,7 @@ function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated,
533
573
  try {
534
574
  const name = value.name.trim();
535
575
  const slug = value.slug.trim().toLowerCase();
536
- const metadata = await organizationMetadataFromForm(value, m, presignOrganizationLogo);
576
+ const metadata = await organizationMetadataFromForm(value, m, uploadOrganizationLogo);
537
577
  const result = await authClient.organization.update({
538
578
  organizationId: organization.id,
539
579
  data: { name, slug, metadata },
@@ -599,7 +639,7 @@ function CreateOrganizationSlugAutoFill({ form, }) {
599
639
  }
600
640
  function CreateOrganizationSection({ authClient, baseUrl, onCreated, }) {
601
641
  const m = useOrganizationMessages();
602
- const presignOrganizationLogo = useAtomSet(authApiClient(baseUrl).mutation("authExtra", "presign"), { mode: "promise" });
642
+ const uploadOrganizationLogo = useAtomSet(authApiClient(baseUrl).mutation("authExtra", "uploadOrganizationLogo"), { mode: "promise" });
603
643
  const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
604
644
  const defaultValues = organizationFormDefaults(undefined, baseUrl);
605
645
  const form = useAppForm({
@@ -613,7 +653,7 @@ function CreateOrganizationSection({ authClient, baseUrl, onCreated, }) {
613
653
  ...value,
614
654
  name,
615
655
  slug,
616
- }, m, presignOrganizationLogo);
656
+ }, m, uploadOrganizationLogo);
617
657
  const result = await authClient.organization.create({
618
658
  name,
619
659
  slug,
@@ -686,43 +726,30 @@ function OrganizationTranslationHeader({ locale, editingLocale, onEditingLocaleC
686
726
  : m.organization_translation_french();
687
727
  return (_jsxs("div", { className: "flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: title }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_translation_description() })] }), _jsx(EditingLocaleSwitcher, { value: editingLocale, onValueChange: onEditingLocaleChange })] }));
688
728
  }
689
- function OrganizationMembersManager({ authClient, baseUrl, organization, currentUserId, }) {
729
+ function OrganizationMembersManager({ authClient, baseUrl, organization, currentUserId, active, }) {
690
730
  const m = useOrganizationMessages();
691
- const [members, setMembers] = useState([]);
692
- const [invitations, setInvitations] = useState([]);
731
+ const hasOpened = useOpenedOnce(active);
732
+ const membersAtom = hasOpened
733
+ ? organizationMembersAtom(authClient)(organization.id)
734
+ : emptyOrganizationMembersAtom;
735
+ const membersResult = useAtomValue(membersAtom);
736
+ const refreshMembers = useAtomRefresh(membersAtom);
693
737
  const [error, setError] = useState(null);
694
- const [loading, setLoading] = useState(true);
695
738
  const [updatingMemberId, setUpdatingMemberId] = useState(null);
696
739
  const [cancellingInvitationId, setCancellingInvitationId] = useState(null);
697
- const loadMembers = useEffectEvent(async () => {
698
- setLoading(true);
699
- setError(null);
700
- const [membersResult, invitationsResult] = await Promise.all([
701
- authClient.organization.listMembers({
702
- query: { organizationId: organization.id },
703
- }),
704
- authClient.organization.listInvitations({
705
- query: { organizationId: organization.id },
706
- }),
707
- ]);
708
- if (membersResult.error) {
709
- setError(membersResult.error.message ?? m.organization_members_load_error());
710
- setLoading(false);
711
- return;
712
- }
713
- if (invitationsResult.error) {
714
- setError(invitationsResult.error.message ??
715
- m.organization_invitations_load_error());
716
- setLoading(false);
717
- return;
718
- }
719
- setMembers(membersResult.data?.members ?? []);
720
- setInvitations(invitationsResult.data ?? []);
721
- setLoading(false);
740
+ const membersData = AsyncResult.match(membersResult, {
741
+ onInitial: () => ({ members: [], invitations: [] }),
742
+ onFailure: () => ({ members: [], invitations: [] }),
743
+ onSuccess: ({ value }) => value,
722
744
  });
723
- useEffect(() => {
724
- void loadMembers();
725
- }, [organization.id]);
745
+ const members = membersData.members;
746
+ const invitations = membersData.invitations;
747
+ const membersError = AsyncResult.match(membersResult, {
748
+ onInitial: () => null,
749
+ onFailure: () => m.organization_members_load_error(),
750
+ onSuccess: () => null,
751
+ });
752
+ const loading = membersResult._tag === "Initial";
726
753
  const inviteForm = useAppForm({
727
754
  defaultValues: { email: "", role: "member" },
728
755
  onSubmit: async ({ value, formApi }) => {
@@ -742,7 +769,7 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
742
769
  return;
743
770
  }
744
771
  inviteForm.reset();
745
- await loadMembers();
772
+ refreshMembers();
746
773
  },
747
774
  });
748
775
  const updateRole = async (member, role) => {
@@ -758,7 +785,7 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
758
785
  setError(result.error.message ?? m.organization_member_role_error());
759
786
  return;
760
787
  }
761
- await loadMembers();
788
+ refreshMembers();
762
789
  };
763
790
  const removeMember = async (member) => {
764
791
  setUpdatingMemberId(member.id);
@@ -772,7 +799,7 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
772
799
  setError(result.error.message ?? m.organization_member_remove_error());
773
800
  return;
774
801
  }
775
- await loadMembers();
802
+ refreshMembers();
776
803
  };
777
804
  const cancelInvitation = async (invitation) => {
778
805
  setCancellingInvitationId(invitation.id);
@@ -785,7 +812,7 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
785
812
  setError(result.error.message ?? m.organization_invitation_cancel_error());
786
813
  return;
787
814
  }
788
- await loadMembers();
815
+ refreshMembers();
789
816
  };
790
817
  return (_jsxs("div", { className: "flex min-w-0 flex-col gap-5", children: [_jsx(inviteForm.AppForm, { children: _jsxs("form", { className: "grid gap-4 rounded-lg border p-4 sm:grid-cols-[minmax(0,1fr)_12rem_auto] sm:items-end", onSubmit: (event) => {
791
818
  event.preventDefault();
@@ -794,7 +821,7 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
794
821
  }, children: [_jsxs("div", { className: "sm:col-span-3", children: [_jsxs("div", { className: "flex items-center gap-2 font-medium", children: [_jsx(UserPlus, { className: "size-4" }), m.organization_invite_member_title()] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invite_member_description() })] }), _jsx(inviteForm.AppField, { name: "email", children: (field) => (_jsx(field.TextField, { label: m.organization_member_email(), placeholder: "teammate@example.com", type: "email", required: true })) }), _jsx(inviteForm.AppField, { name: "role", children: (field) => (_jsx(field.SelectField, { label: m.organization_member_role(), options: organizationRoles.map((role) => ({
795
822
  label: organizationRoleLabel(role, m),
796
823
  value: role,
797
- })) })) }), _jsx("div", { className: "self-end", children: _jsx(inviteForm.SubmitButton, {}) }), _jsx(inviteForm.FormError, {})] }) }), error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_members_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_members_description() })] }), _jsx("div", { className: "min-w-0 overflow-x-auto", children: _jsx(DataTable, { columns: memberColumns({
824
+ })) })) }), _jsx("div", { className: "self-end", children: _jsx(inviteForm.SubmitButton, {}) }), _jsx(inviteForm.FormError, {})] }) }), membersError ? (_jsx("p", { className: "text-destructive text-sm", children: membersError })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_members_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_members_description() })] }), _jsx("div", { className: "min-w-0 overflow-x-auto", children: _jsx(DataTable, { columns: memberColumns({
798
825
  m,
799
826
  baseUrl,
800
827
  updatingMemberId,
@@ -882,29 +909,27 @@ const invitationRowActions = ({ m, cancellingInvitationId, onCancel, }) => [
882
909
  onClick: onCancel,
883
910
  },
884
911
  ];
885
- function OrganizationApiKeyManager({ authClient, organization, }) {
912
+ function OrganizationApiKeyManager({ authClient, organization, active, }) {
886
913
  const m = useOrganizationMessages();
887
- const [keys, setKeys] = useState([]);
914
+ const hasOpened = useOpenedOnce(active);
915
+ const keysAtom = hasOpened
916
+ ? organizationApiKeysAtom(authClient)(organization.id)
917
+ : emptyOrganizationApiKeysAtom;
918
+ const keysResult = useAtomValue(keysAtom);
919
+ const refreshKeys = useAtomRefresh(keysAtom);
888
920
  const [createdKey, setCreatedKey] = useState(null);
889
921
  const [error, setError] = useState(null);
890
- const [loading, setLoading] = useState(true);
891
- const loadKeys = useEffectEvent(async () => {
892
- setLoading(true);
893
- setError(null);
894
- const result = await authClient.apiKey.list({
895
- query: { configId: "organization", organizationId: organization.id },
896
- });
897
- if (result.error) {
898
- setError(result.error.message ?? m.user_api_keys_load_error());
899
- setLoading(false);
900
- return;
901
- }
902
- setKeys(result.data?.apiKeys ?? []);
903
- setLoading(false);
922
+ const keys = AsyncResult.match(keysResult, {
923
+ onInitial: () => [],
924
+ onFailure: () => [],
925
+ onSuccess: ({ value }) => Array.from(value),
904
926
  });
905
- useEffect(() => {
906
- void loadKeys();
907
- }, [organization.id]);
927
+ const keysError = AsyncResult.match(keysResult, {
928
+ onInitial: () => null,
929
+ onFailure: () => m.user_api_keys_load_error(),
930
+ onSuccess: () => null,
931
+ });
932
+ const loading = keysResult._tag === "Initial";
908
933
  const createForm = useAppForm({
909
934
  defaultValues: { name: "" },
910
935
  onSubmit: async ({ value, formApi }) => {
@@ -918,7 +943,7 @@ function OrganizationApiKeyManager({ authClient, organization, }) {
918
943
  }, m.user_api_key_create_error());
919
944
  setCreatedKey(created.key);
920
945
  createForm.reset();
921
- await loadKeys();
946
+ refreshKeys();
922
947
  }
923
948
  catch (cause) {
924
949
  formApi.setErrorMap({
@@ -941,13 +966,13 @@ function OrganizationApiKeyManager({ authClient, organization, }) {
941
966
  setError(result.error.message ?? m.user_api_key_delete_error());
942
967
  return;
943
968
  }
944
- await loadKeys();
969
+ refreshKeys();
945
970
  };
946
971
  return (_jsxs("div", { className: "flex flex-col gap-5", children: [_jsx(createForm.AppForm, { children: _jsxs("form", { className: "flex max-w-xl flex-col gap-4", onSubmit: (event) => {
947
972
  event.preventDefault();
948
973
  event.stopPropagation();
949
974
  createForm.handleSubmit();
950
- }, children: [_jsx("p", { className: "text-muted-foreground text-sm", children: m.api_key_rate_limit_notice() }), _jsx(createForm.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.user_api_key_name(), required: true })) }), _jsx(createForm.FormError, {}), _jsx(createForm.SubmitButton, {})] }) }), createdKey ? (_jsxs("div", { className: "flex flex-col gap-2 rounded-lg border p-4", children: [_jsxs("div", { className: "flex items-center gap-2 font-medium", children: [_jsx(KeyRound, {}), m.user_api_key_created_title()] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_api_key_created_description() }), _jsx("code", { className: "bg-muted overflow-x-auto rounded-md p-3 text-sm", children: createdKey })] })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsx(Separator, {}), _jsx(DataTable, { columns: apiKeyColumns({ m }), data: keys, emptyLabel: loading ? m.user_loading() : m.table_empty(), exportFileName: `${organization.slug}-api-keys.csv`, features: { gallery: false }, rowActions: apiKeyRowActions({ m, onDelete: deleteKey }) })] }));
975
+ }, children: [_jsx("p", { className: "text-muted-foreground text-sm", children: m.api_key_rate_limit_notice() }), _jsx(createForm.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.user_api_key_name(), required: true })) }), _jsx(createForm.FormError, {}), _jsx(createForm.SubmitButton, {})] }) }), createdKey ? (_jsxs("div", { className: "flex flex-col gap-2 rounded-lg border p-4", children: [_jsxs("div", { className: "flex items-center gap-2 font-medium", children: [_jsx(KeyRound, {}), m.user_api_key_created_title()] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_api_key_created_description() }), _jsx("code", { className: "bg-muted overflow-x-auto rounded-md p-3 text-sm", children: createdKey })] })) : null, keysError ? (_jsx("p", { className: "text-destructive text-sm", children: keysError })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsx(Separator, {}), _jsx(DataTable, { columns: apiKeyColumns({ m }), data: keys, emptyLabel: loading ? m.user_loading() : m.table_empty(), exportFileName: `${organization.slug}-api-keys.csv`, features: { gallery: false }, rowActions: apiKeyRowActions({ m, onDelete: deleteKey }) })] }));
951
976
  }
952
977
  const apiKeyColumns = ({ m, }) => [
953
978
  {
@@ -76,6 +76,7 @@ declare const messages: {
76
76
  readonly user_two_factor_disabled: "Disabled";
77
77
  readonly user_two_factor_disabled_message: "Two-factor authentication is disabled.";
78
78
  readonly user_two_factor_enable_error: "Could not start two-factor setup.";
79
+ readonly user_two_factor_enable_submit: "Enable";
79
80
  readonly user_two_factor_enabled: "Enabled";
80
81
  readonly user_two_factor_enabled_message: "Two-factor authentication is enabled.";
81
82
  readonly user_two_factor_scan_description: "Add this account to your authenticator app, then enter the generated code below.";
@@ -157,6 +158,7 @@ declare const messages: {
157
158
  readonly user_two_factor_disabled: "Désactivée";
158
159
  readonly user_two_factor_disabled_message: "L'authentification à deux facteurs est désactivée.";
159
160
  readonly user_two_factor_enable_error: "Impossible de démarrer la configuration à deux facteurs.";
161
+ readonly user_two_factor_enable_submit: "Activer";
160
162
  readonly user_two_factor_enabled: "Activée";
161
163
  readonly user_two_factor_enabled_message: "L'authentification à deux facteurs est activée.";
162
164
  readonly user_two_factor_scan_description: "Ajoutez ce compte à votre application d'authentification, puis saisissez le code généré ci-dessous.";