@krak-stack/auth 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/auth-client.d.ts +10 -0
- package/dist/components/auth-client.js +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/organization-switcher.d.ts +3 -1
- package/dist/components/organization-switcher.js +24 -25
- package/dist/components/user-button.d.ts +3 -1
- package/dist/components/user-button.js +44 -65
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { apiKeyClient } from "@better-auth/api-key/client";
|
|
2
|
+
import type { organizationClient, twoFactorClient } from "better-auth/client/plugins";
|
|
3
|
+
import type { createAuthClient } from "better-auth/react";
|
|
4
|
+
export type AuthUiClient = ReturnType<typeof createAuthClient<{
|
|
5
|
+
plugins: [
|
|
6
|
+
ReturnType<typeof organizationClient>,
|
|
7
|
+
ReturnType<typeof twoFactorClient>,
|
|
8
|
+
ReturnType<typeof apiKeyClient>
|
|
9
|
+
];
|
|
10
|
+
}>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type ComponentProps, type ReactNode } from "react";
|
|
2
2
|
import { DropdownMenuContent } from "@/components/ui/dropdown-menu";
|
|
3
|
+
import type { AuthUiClient } from "./auth-client";
|
|
3
4
|
type OrganizationSwitcherProps = {
|
|
5
|
+
authClient: AuthUiClient;
|
|
4
6
|
side?: ComponentProps<typeof DropdownMenuContent>["side"];
|
|
5
7
|
className?: string;
|
|
6
8
|
renderUnauthenticated?: () => ReactNode;
|
|
7
9
|
locked?: boolean;
|
|
8
10
|
};
|
|
9
|
-
export declare function OrganizationSwitcher({ side, className, renderUnauthenticated, locked, }: OrganizationSwitcherProps): import("react").JSX.Element;
|
|
11
|
+
export declare function OrganizationSwitcher({ authClient, side, className, renderUnauthenticated, locked, }: OrganizationSwitcherProps): import("react").JSX.Element;
|
|
10
12
|
export {};
|
|
@@ -16,7 +16,6 @@ import { Separator } from "@/components/ui/separator";
|
|
|
16
16
|
import { cn } from "@/lib/utils";
|
|
17
17
|
import { m } from "@/paraglide/messages";
|
|
18
18
|
import { getLocale } from "@/paraglide/runtime";
|
|
19
|
-
import { centralAuthClient } from "@/services/auth/client/central";
|
|
20
19
|
import { OrganizationMetadata, } from "@krak-stack/auth/schema";
|
|
21
20
|
const slugify = (value) => value
|
|
22
21
|
.trim()
|
|
@@ -149,10 +148,10 @@ const organizationMetadataFromForm = async (value) => {
|
|
|
149
148
|
}
|
|
150
149
|
return { translations };
|
|
151
150
|
};
|
|
152
|
-
export function OrganizationSwitcher({ side = "bottom", className, renderUnauthenticated, locked = false, }) {
|
|
153
|
-
const session =
|
|
154
|
-
const organizations =
|
|
155
|
-
const activeOrganization =
|
|
151
|
+
export function OrganizationSwitcher({ authClient, side = "bottom", className, renderUnauthenticated, locked = false, }) {
|
|
152
|
+
const session = authClient.useSession();
|
|
153
|
+
const organizations = authClient.useListOrganizations();
|
|
154
|
+
const activeOrganization = authClient.useActiveOrganization();
|
|
156
155
|
const [dialog, setDialog] = useState(null);
|
|
157
156
|
if (!session.data) {
|
|
158
157
|
return _jsx(_Fragment, { children: renderUnauthenticated?.() });
|
|
@@ -177,7 +176,7 @@ export function OrganizationSwitcher({ side = "bottom", className, renderUnauthe
|
|
|
177
176
|
: {}) }) }), hasOrganizationListItems ? _jsx(DropdownMenuSeparator, {}) : null, organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: m.organization_loading() })) : null, organizations.error ? (_jsx(DropdownMenuItem, { disabled: true, children: organizations.error.message })) : null, !locked && selectableOrganizations.length ? (selectableOrganizations.map((organization) => {
|
|
178
177
|
const display = organizationDisplay(organization);
|
|
179
178
|
return (_jsx(DropdownMenuItem, { onClick: async () => {
|
|
180
|
-
const result = await
|
|
179
|
+
const result = await authClient.organization.setActive({
|
|
181
180
|
organizationId: organization.id,
|
|
182
181
|
});
|
|
183
182
|
if (!result.error)
|
|
@@ -187,18 +186,18 @@ export function OrganizationSwitcher({ side = "bottom", className, renderUnauthe
|
|
|
187
186
|
? m.organization_switcher_no_other_organizations()
|
|
188
187
|
: m.organization_switcher_empty() })) : null, !locked ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onClick: () => setDialog("create"), children: [_jsx(Building2, {}), m.organization_create_title()] })] })) : null, activeOrganization.data ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _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) => {
|
|
189
188
|
setDialog((current) => open ? "create" : current === "create" ? null : current);
|
|
190
|
-
}, 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_create_title() }), _jsx(DialogDescription, { children: m.organization_create_description() })] }), _jsx(Separator, {}), _jsx(CreateOrganizationSection, { onCreated: async () => {
|
|
189
|
+
}, 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_create_title() }), _jsx(DialogDescription, { children: m.organization_create_description() })] }), _jsx(Separator, {}), _jsx(CreateOrganizationSection, { authClient: authClient, onCreated: async () => {
|
|
191
190
|
await refresh();
|
|
192
191
|
setDialog(null);
|
|
193
192
|
} })] }) }), _jsx(Dialog, { open: dialog === "manage", onOpenChange: (open) => {
|
|
194
193
|
setDialog((current) => open ? "manage" : current === "manage" ? null : current);
|
|
195
|
-
}, 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, { organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
|
|
194
|
+
}, 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, organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
|
|
196
195
|
setDialog((current) => open ? "members" : current === "members" ? null : current);
|
|
197
|
-
}, 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_members_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationMembersManager, { organization: activeOrganization.data, currentUserId: session.data.user.id })) : null] }) }), _jsx(Dialog, { open: dialog === "apiKeys", onOpenChange: (open) => {
|
|
196
|
+
}, 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_members_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationMembersManager, { authClient: authClient, organization: activeOrganization.data, currentUserId: session.data.user.id })) : null] }) }), _jsx(Dialog, { open: dialog === "apiKeys", onOpenChange: (open) => {
|
|
198
197
|
setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
199
|
-
}, 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, { organization: activeOrganization.data })) : null] }) })] }));
|
|
198
|
+
}, 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] }) })] }));
|
|
200
199
|
}
|
|
201
|
-
function EditOrganizationSection({ organization, onUpdated, }) {
|
|
200
|
+
function EditOrganizationSection({ authClient, organization, onUpdated, }) {
|
|
202
201
|
const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
|
|
203
202
|
const defaultValues = organizationFormDefaults(organization);
|
|
204
203
|
const form = useAppForm({
|
|
@@ -208,7 +207,7 @@ function EditOrganizationSection({ organization, onUpdated, }) {
|
|
|
208
207
|
const name = value.name.trim();
|
|
209
208
|
const slug = value.slug.trim().toLowerCase();
|
|
210
209
|
const metadata = await organizationMetadataFromForm(value);
|
|
211
|
-
const result = await
|
|
210
|
+
const result = await authClient.organization.update({
|
|
212
211
|
organizationId: organization.id,
|
|
213
212
|
data: { name, slug, metadata },
|
|
214
213
|
});
|
|
@@ -240,7 +239,7 @@ function EditOrganizationSection({ organization, onUpdated, }) {
|
|
|
240
239
|
suggestedHeight: 512,
|
|
241
240
|
} })) }), _jsx(form.AppField, { name: "frContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "frLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }) }));
|
|
242
241
|
}
|
|
243
|
-
function CreateOrganizationSection({ onCreated, }) {
|
|
242
|
+
function CreateOrganizationSection({ authClient, onCreated, }) {
|
|
244
243
|
const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
|
|
245
244
|
const defaultValues = organizationFormDefaults();
|
|
246
245
|
const form = useAppForm({
|
|
@@ -254,7 +253,7 @@ function CreateOrganizationSection({ onCreated, }) {
|
|
|
254
253
|
name,
|
|
255
254
|
slug,
|
|
256
255
|
});
|
|
257
|
-
const result = await
|
|
256
|
+
const result = await authClient.organization.create({
|
|
258
257
|
name,
|
|
259
258
|
slug,
|
|
260
259
|
metadata,
|
|
@@ -294,7 +293,7 @@ function OrganizationTranslationHeader({ locale, editingLocale, onEditingLocaleC
|
|
|
294
293
|
: m.organization_translation_french();
|
|
295
294
|
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 })] }));
|
|
296
295
|
}
|
|
297
|
-
function OrganizationMembersManager({ organization, currentUserId, }) {
|
|
296
|
+
function OrganizationMembersManager({ authClient, organization, currentUserId, }) {
|
|
298
297
|
const [members, setMembers] = useState([]);
|
|
299
298
|
const [invitations, setInvitations] = useState([]);
|
|
300
299
|
const [error, setError] = useState(null);
|
|
@@ -305,10 +304,10 @@ function OrganizationMembersManager({ organization, currentUserId, }) {
|
|
|
305
304
|
setLoading(true);
|
|
306
305
|
setError(null);
|
|
307
306
|
const [membersResult, invitationsResult] = await Promise.all([
|
|
308
|
-
|
|
307
|
+
authClient.organization.listMembers({
|
|
309
308
|
query: { organizationId: organization.id },
|
|
310
309
|
}),
|
|
311
|
-
|
|
310
|
+
authClient.organization.listInvitations({
|
|
312
311
|
query: { organizationId: organization.id },
|
|
313
312
|
}),
|
|
314
313
|
]);
|
|
@@ -334,7 +333,7 @@ function OrganizationMembersManager({ organization, currentUserId, }) {
|
|
|
334
333
|
defaultValues: { email: "", role: "member" },
|
|
335
334
|
onSubmit: async ({ value, formApi }) => {
|
|
336
335
|
formApi.setErrorMap({ onSubmit: undefined });
|
|
337
|
-
const result = await
|
|
336
|
+
const result = await authClient.organization.inviteMember({
|
|
338
337
|
email: value.email.trim(),
|
|
339
338
|
role: normalizeOrganizationRole(value.role),
|
|
340
339
|
organizationId: organization.id,
|
|
@@ -355,7 +354,7 @@ function OrganizationMembersManager({ organization, currentUserId, }) {
|
|
|
355
354
|
const updateRole = async (member, role) => {
|
|
356
355
|
setUpdatingMemberId(member.id);
|
|
357
356
|
setError(null);
|
|
358
|
-
const result = await
|
|
357
|
+
const result = await authClient.organization.updateMemberRole({
|
|
359
358
|
memberId: member.id,
|
|
360
359
|
role,
|
|
361
360
|
organizationId: organization.id,
|
|
@@ -370,7 +369,7 @@ function OrganizationMembersManager({ organization, currentUserId, }) {
|
|
|
370
369
|
const removeMember = async (member) => {
|
|
371
370
|
setUpdatingMemberId(member.id);
|
|
372
371
|
setError(null);
|
|
373
|
-
const result = await
|
|
372
|
+
const result = await authClient.organization.removeMember({
|
|
374
373
|
memberIdOrEmail: member.id,
|
|
375
374
|
organizationId: organization.id,
|
|
376
375
|
});
|
|
@@ -384,7 +383,7 @@ function OrganizationMembersManager({ organization, currentUserId, }) {
|
|
|
384
383
|
const cancelInvitation = async (invitation) => {
|
|
385
384
|
setCancellingInvitationId(invitation.id);
|
|
386
385
|
setError(null);
|
|
387
|
-
const result = await
|
|
386
|
+
const result = await authClient.organization.cancelInvitation({
|
|
388
387
|
invitationId: invitation.id,
|
|
389
388
|
});
|
|
390
389
|
setCancellingInvitationId(null);
|
|
@@ -479,7 +478,7 @@ const invitationColumns = ({ cancellingInvitationId, onCancel, }) => [
|
|
|
479
478
|
},
|
|
480
479
|
]),
|
|
481
480
|
];
|
|
482
|
-
function OrganizationApiKeyManager({ organization, }) {
|
|
481
|
+
function OrganizationApiKeyManager({ authClient, organization, }) {
|
|
483
482
|
const [keys, setKeys] = useState([]);
|
|
484
483
|
const [createdKey, setCreatedKey] = useState(null);
|
|
485
484
|
const [error, setError] = useState(null);
|
|
@@ -487,7 +486,7 @@ function OrganizationApiKeyManager({ organization, }) {
|
|
|
487
486
|
const loadKeys = useEffectEvent(async () => {
|
|
488
487
|
setLoading(true);
|
|
489
488
|
setError(null);
|
|
490
|
-
const result = await
|
|
489
|
+
const result = await authClient.apiKey.list({
|
|
491
490
|
query: { configId: "organization", organizationId: organization.id },
|
|
492
491
|
});
|
|
493
492
|
if (result.error) {
|
|
@@ -506,7 +505,7 @@ function OrganizationApiKeyManager({ organization, }) {
|
|
|
506
505
|
onSubmit: async ({ value, formApi }) => {
|
|
507
506
|
formApi.setErrorMap({ onSubmit: undefined });
|
|
508
507
|
setCreatedKey(null);
|
|
509
|
-
const result = await
|
|
508
|
+
const result = await authClient.apiKey.create({
|
|
510
509
|
configId: "organization",
|
|
511
510
|
organizationId: organization.id,
|
|
512
511
|
name: value.name.trim(),
|
|
@@ -526,7 +525,7 @@ function OrganizationApiKeyManager({ organization, }) {
|
|
|
526
525
|
},
|
|
527
526
|
});
|
|
528
527
|
const deleteKey = async (key) => {
|
|
529
|
-
const result = await
|
|
528
|
+
const result = await authClient.apiKey.delete({
|
|
530
529
|
configId: "organization",
|
|
531
530
|
keyId: key.id,
|
|
532
531
|
});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type ComponentProps, type ReactNode } from "react";
|
|
2
2
|
import { DropdownMenuContent } from "@/components/ui/dropdown-menu";
|
|
3
|
+
import type { AuthUiClient } from "./auth-client";
|
|
3
4
|
type UserDropdownProps = {
|
|
5
|
+
authClient: AuthUiClient;
|
|
4
6
|
signOutRedirect?: string;
|
|
5
7
|
side?: ComponentProps<typeof DropdownMenuContent>["side"];
|
|
6
8
|
renderUnauthenticated?: () => ReactNode;
|
|
7
9
|
apiKeyPermissions?: Record<string, string[]>;
|
|
8
10
|
};
|
|
9
|
-
export declare const UserButton: ({ signOutRedirect, side, renderUnauthenticated, apiKeyPermissions, }: UserDropdownProps) => import("react").JSX.Element;
|
|
11
|
+
export declare const UserButton: ({ authClient, signOutRedirect, side, renderUnauthenticated, apiKeyPermissions, }: UserDropdownProps) => import("react").JSX.Element;
|
|
10
12
|
export {};
|
|
@@ -3,7 +3,7 @@ import {} from "@tanstack/react-table";
|
|
|
3
3
|
import { useNavigate, useRouterState, } from "@tanstack/react-router";
|
|
4
4
|
import { Check, Copy, KeyRound, LogOutIcon, ShieldCheck, Trash2, UserCircleIcon, UserIcon, } from "lucide-react";
|
|
5
5
|
import { QRCode } from "react-qr-code";
|
|
6
|
-
import { useEffect, useState, } from "react";
|
|
6
|
+
import { useEffect, useEffectEvent, useState, } from "react";
|
|
7
7
|
import { createDataTableActionsColumn, DataTable, } from "@/components/ui/data-table";
|
|
8
8
|
import { AppBrand } from "@/components/ui/app-brand";
|
|
9
9
|
import { useAppForm } from "@/components/ui/form";
|
|
@@ -15,8 +15,6 @@ import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldLeg
|
|
|
15
15
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
16
16
|
import { Separator } from "@/components/ui/separator";
|
|
17
17
|
import { m } from "@/paraglide/messages";
|
|
18
|
-
import { authClient } from "@/services/auth/client";
|
|
19
|
-
import { centralAuthClient } from "@/services/auth/client/central";
|
|
20
18
|
const isFile = (value) => value instanceof File;
|
|
21
19
|
const authUrl = (path) => new URL(path, import.meta.env.VITE_KRAKSTACK_AUTH_URL ??
|
|
22
20
|
globalThis.location?.origin ??
|
|
@@ -42,16 +40,14 @@ const presignUserImageUpload = async (file) => {
|
|
|
42
40
|
}
|
|
43
41
|
return { uploadUrl, url };
|
|
44
42
|
};
|
|
45
|
-
export const UserButton = ({ signOutRedirect = "/", side = "bottom", renderUnauthenticated, apiKeyPermissions, }) => {
|
|
43
|
+
export const UserButton = ({ authClient, signOutRedirect = "/", side = "bottom", renderUnauthenticated, apiKeyPermissions, }) => {
|
|
46
44
|
const navigate = useNavigate();
|
|
47
45
|
const currentSiteHref = useRouterState({
|
|
48
46
|
select: (state) => `${import.meta.env.VITE_SITE_URL}${state.location.href}`,
|
|
49
47
|
});
|
|
50
48
|
const { data: session, isPending, refetch } = authClient.useSession();
|
|
51
|
-
const centralSession = centralAuthClient.useSession();
|
|
52
49
|
const [settingsDialog, setSettingsDialog] = useState(null);
|
|
53
50
|
const [formError, setFormError] = useState(null);
|
|
54
|
-
const [centralAuthError, setCentralAuthError] = useState(null);
|
|
55
51
|
if (!session) {
|
|
56
52
|
return _jsx(_Fragment, { children: renderUnauthenticated?.() });
|
|
57
53
|
}
|
|
@@ -64,10 +60,7 @@ export const UserButton = ({ signOutRedirect = "/", side = "bottom", renderUnaut
|
|
|
64
60
|
const redirectUrl = signOutRedirect.startsWith("http")
|
|
65
61
|
? signOutRedirect
|
|
66
62
|
: `${import.meta.env.VITE_SITE_URL}${signOutRedirect.startsWith("/") ? signOutRedirect : `/${signOutRedirect}`}`;
|
|
67
|
-
await
|
|
68
|
-
authClient.signOut(),
|
|
69
|
-
centralAuthClient.signOut(),
|
|
70
|
-
]);
|
|
63
|
+
await authClient.signOut();
|
|
71
64
|
await navigate({ href: redirectUrl });
|
|
72
65
|
};
|
|
73
66
|
const updateUser = async (values) => {
|
|
@@ -89,33 +82,19 @@ export const UserButton = ({ signOutRedirect = "/", side = "bottom", renderUnaut
|
|
|
89
82
|
: typeof values.image === "string"
|
|
90
83
|
? values.image
|
|
91
84
|
: null;
|
|
92
|
-
const result = await
|
|
85
|
+
const result = await authClient.updateUser({
|
|
93
86
|
name: values.name.trim(),
|
|
94
87
|
image: image?.trim() ?? "",
|
|
95
88
|
});
|
|
96
89
|
if (isAuthErrorResult(result)) {
|
|
97
90
|
throw new Error(result.error.message || m.user_form_update_error());
|
|
98
91
|
}
|
|
99
|
-
await centralSession.refetch();
|
|
100
92
|
await refetch();
|
|
101
93
|
setSettingsDialog(null);
|
|
102
94
|
};
|
|
103
|
-
const reconnectCentralAuth = async () => {
|
|
104
|
-
setCentralAuthError(null);
|
|
105
|
-
const result = await authClient.signIn.oauth2({
|
|
106
|
-
providerId: "krakstack-auth",
|
|
107
|
-
callbackURL: currentSiteHref,
|
|
108
|
-
});
|
|
109
|
-
if (result.error) {
|
|
110
|
-
setCentralAuthError(result.error.message ?? m.user_central_auth_reconnect_error());
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
if (result.data?.url)
|
|
114
|
-
await navigate({ href: result.data.url });
|
|
115
|
-
};
|
|
116
95
|
return (_jsxs(_Fragment, { children: [_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "outline", size: "icon", children: [_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: [_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(DropdownMenuSeparator, {}), _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, {}), _jsxs(DropdownMenuItem, { onClick: signOut, children: [_jsx(LogOutIcon, {}), m.user_button_logout()] })] }) })] }), _jsx(Dialog, { open: settingsDialog === "account", onOpenChange: (open) => {
|
|
117
96
|
setSettingsDialog((current) => open ? "account" : current === "account" ? null : current);
|
|
118
|
-
}, 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_form_title() }), _jsx(DialogDescription, { children: m.user_form_description() })] }), _jsx(Separator, {}),
|
|
97
|
+
}, 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_form_title() }), _jsx(DialogDescription, { children: m.user_form_description() })] }), _jsx(Separator, {}), isPending ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : (_jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(UserForm, { defaultValues: {
|
|
119
98
|
name: displayName ?? "",
|
|
120
99
|
image: displayImage || null,
|
|
121
100
|
}, error: formError, onSubmit: async (data) => {
|
|
@@ -127,22 +106,22 @@ export const UserButton = ({ signOutRedirect = "/", side = "bottom", renderUnaut
|
|
|
127
106
|
? error.message
|
|
128
107
|
: m.user_form_update_error());
|
|
129
108
|
}
|
|
130
|
-
} }), _jsx(Separator, {}), _jsx(ConnectedAccounts, { currentSiteHref: currentSiteHref, navigate: navigate }), _jsx(Separator, {}), _jsx(PasswordSettings, {})] }))] }) }), _jsx(Dialog, { open: settingsDialog === "security", onOpenChange: (open) => {
|
|
109
|
+
} }), _jsx(Separator, {}), _jsx(ConnectedAccounts, { authClient: authClient, currentSiteHref: currentSiteHref, navigate: navigate }), _jsx(Separator, {}), _jsx(PasswordSettings, { authClient: authClient })] }))] }) }), _jsx(Dialog, { open: settingsDialog === "security", onOpenChange: (open) => {
|
|
131
110
|
setSettingsDialog((current) => open ? "security" : current === "security" ? null : current);
|
|
132
|
-
}, 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_security_title() }), _jsx(DialogDescription, { children: m.user_security_description() })] }), _jsx(Separator, {}), _jsx(AccountSecuritySettings, {})] }) }), _jsx(Dialog, { open: settingsDialog === "apiKeys", onOpenChange: (open) => {
|
|
111
|
+
}, 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_security_title() }), _jsx(DialogDescription, { children: m.user_security_description() })] }), _jsx(Separator, {}), _jsx(AccountSecuritySettings, { authClient: authClient })] }) }), _jsx(Dialog, { open: settingsDialog === "apiKeys", onOpenChange: (open) => {
|
|
133
112
|
setSettingsDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
134
|
-
}, 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: m.user_api_keys_description() })] }), _jsx(Separator, {}), _jsx(ApiKeyManager, { permissions: apiKeyPermissions ?? {} })] }) })] }));
|
|
113
|
+
}, 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: m.user_api_keys_description() })] }), _jsx(Separator, {}), _jsx(ApiKeyManager, { authClient: authClient, permissions: apiKeyPermissions ?? {} })] }) })] }));
|
|
135
114
|
};
|
|
136
|
-
function ConnectedAccounts({ currentSiteHref, navigate, }) {
|
|
115
|
+
function ConnectedAccounts({ authClient, currentSiteHref, navigate, }) {
|
|
137
116
|
const [accounts, setAccounts] = useState([]);
|
|
138
117
|
const [error, setError] = useState(null);
|
|
139
118
|
const [loading, setLoading] = useState(true);
|
|
140
119
|
const [isLinking, setIsLinking] = useState(false);
|
|
141
120
|
const [revokingAccount, setRevokingAccount] = useState(null);
|
|
142
|
-
const loadAccounts = async () => {
|
|
121
|
+
const loadAccounts = useEffectEvent(async () => {
|
|
143
122
|
setLoading(true);
|
|
144
123
|
setError(null);
|
|
145
|
-
const result = await
|
|
124
|
+
const result = await authClient.listAccounts();
|
|
146
125
|
if (result.error) {
|
|
147
126
|
setError(result.error.message ?? m.user_accounts_load_error());
|
|
148
127
|
setLoading(false);
|
|
@@ -150,7 +129,7 @@ function ConnectedAccounts({ currentSiteHref, navigate, }) {
|
|
|
150
129
|
}
|
|
151
130
|
setAccounts(result.data ?? []);
|
|
152
131
|
setLoading(false);
|
|
153
|
-
};
|
|
132
|
+
});
|
|
154
133
|
useEffect(() => {
|
|
155
134
|
void loadAccounts();
|
|
156
135
|
}, []);
|
|
@@ -160,7 +139,7 @@ function ConnectedAccounts({ currentSiteHref, navigate, }) {
|
|
|
160
139
|
const linkGoogle = async () => {
|
|
161
140
|
setError(null);
|
|
162
141
|
setIsLinking(true);
|
|
163
|
-
const result = await
|
|
142
|
+
const result = await authClient.linkSocial({
|
|
164
143
|
provider: "google",
|
|
165
144
|
callbackURL: currentSiteHref,
|
|
166
145
|
});
|
|
@@ -177,7 +156,7 @@ function ConnectedAccounts({ currentSiteHref, navigate, }) {
|
|
|
177
156
|
};
|
|
178
157
|
const revokeAccount = async (account) => {
|
|
179
158
|
setError(null);
|
|
180
|
-
const result = await
|
|
159
|
+
const result = await authClient.unlinkAccount({
|
|
181
160
|
providerId: account.providerId,
|
|
182
161
|
accountId: account.accountId,
|
|
183
162
|
});
|
|
@@ -188,22 +167,22 @@ function ConnectedAccounts({ currentSiteHref, navigate, }) {
|
|
|
188
167
|
setRevokingAccount(null);
|
|
189
168
|
await loadAccounts();
|
|
190
169
|
};
|
|
191
|
-
return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_accounts_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_accounts_description() })] }), loading ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : null, _jsx(AccountProviderRow, { initial: "G", title: m.user_account_google_title(), description: m.user_account_google_description(), account: googleAccount, connected: Boolean(googleAccount), canRevoke: canRevokeAccount, connectLabel: m.user_account_google_connect(), revokeLabel: m.user_account_revoke(), onlyMethodLabel: m.user_account_only_method(), isConnecting: isLinking, renderDisconnected: undefined, onConnect: linkGoogle, onRevoke: (account) => setRevokingAccount(account) }), revokingAccount ? (_jsx(RevokeAccountForm, { account: revokingAccount, requirePassword: hasPassword, onCancel: () => setRevokingAccount(null), onRevoke: revokeAccount })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }));
|
|
170
|
+
return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_accounts_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_accounts_description() })] }), loading ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : null, _jsx(AccountProviderRow, { initial: "G", title: m.user_account_google_title(), description: m.user_account_google_description(), account: googleAccount, connected: Boolean(googleAccount), canRevoke: canRevokeAccount, connectLabel: m.user_account_google_connect(), revokeLabel: m.user_account_revoke(), onlyMethodLabel: m.user_account_only_method(), isConnecting: isLinking, renderDisconnected: undefined, onConnect: linkGoogle, onRevoke: (account) => setRevokingAccount(account) }), revokingAccount ? (_jsx(RevokeAccountForm, { authClient: authClient, account: revokingAccount, requirePassword: hasPassword, onCancel: () => setRevokingAccount(null), onRevoke: revokeAccount })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }));
|
|
192
171
|
}
|
|
193
172
|
function AccountProviderRow({ initial, title, description, account, connected, canRevoke, connectLabel, revokeLabel, onlyMethodLabel, isConnecting, renderDisconnected, onConnect, onRevoke, }) {
|
|
194
173
|
return (_jsx("div", { className: "flex flex-col gap-3 rounded-lg border p-4", children: _jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [_jsxs("div", { className: "flex min-w-0 items-center gap-3", children: [_jsx("span", { className: "bg-background flex size-9 shrink-0 items-center justify-center rounded-full border text-sm font-semibold", children: initial }), _jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("p", { className: "font-medium", children: title }), _jsx(Badge, { variant: connected ? "default" : "secondary", children: connected
|
|
195
174
|
? m.user_account_connected()
|
|
196
175
|
: m.user_account_not_connected() })] }), _jsx("p", { className: "text-muted-foreground text-sm", children: description })] })] }), connected && account ? (_jsx(Button, { type: "button", variant: "outline", disabled: !canRevoke, onClick: () => onRevoke(account), children: canRevoke ? revokeLabel : onlyMethodLabel })) : renderDisconnected ? (renderDisconnected) : (_jsx(Button, { type: "button", variant: "outline", disabled: isConnecting, onClick: onConnect, children: connectLabel }))] }) }));
|
|
197
176
|
}
|
|
198
|
-
function PasswordSettings() {
|
|
177
|
+
function PasswordSettings({ authClient }) {
|
|
199
178
|
const [accounts, setAccounts] = useState([]);
|
|
200
179
|
const [error, setError] = useState(null);
|
|
201
180
|
const [loading, setLoading] = useState(true);
|
|
202
181
|
const [revokingAccount, setRevokingAccount] = useState(null);
|
|
203
|
-
const loadAccounts = async () => {
|
|
182
|
+
const loadAccounts = useEffectEvent(async () => {
|
|
204
183
|
setLoading(true);
|
|
205
184
|
setError(null);
|
|
206
|
-
const result = await
|
|
185
|
+
const result = await authClient.listAccounts();
|
|
207
186
|
if (result.error) {
|
|
208
187
|
setError(result.error.message ?? m.user_accounts_load_error());
|
|
209
188
|
setLoading(false);
|
|
@@ -211,7 +190,7 @@ function PasswordSettings() {
|
|
|
211
190
|
}
|
|
212
191
|
setAccounts(result.data ?? []);
|
|
213
192
|
setLoading(false);
|
|
214
|
-
};
|
|
193
|
+
});
|
|
215
194
|
useEffect(() => {
|
|
216
195
|
void loadAccounts();
|
|
217
196
|
}, []);
|
|
@@ -220,7 +199,7 @@ function PasswordSettings() {
|
|
|
220
199
|
const canRevokeAccount = accounts.length > 1;
|
|
221
200
|
const revokePassword = async (account) => {
|
|
222
201
|
setError(null);
|
|
223
|
-
const result = await
|
|
202
|
+
const result = await authClient.unlinkAccount({
|
|
224
203
|
providerId: account.providerId,
|
|
225
204
|
accountId: account.accountId,
|
|
226
205
|
});
|
|
@@ -233,16 +212,16 @@ function PasswordSettings() {
|
|
|
233
212
|
};
|
|
234
213
|
return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_account_password_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_account_password_description() })] }), loading ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : null, hasPassword && passwordAccount ? (_jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3 rounded-lg border p-4", children: [_jsxs("div", { className: "flex flex-col gap-1", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("p", { className: "font-medium", children: m.user_account_password_title() }), _jsx(Badge, { children: m.user_account_connected() })] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_account_password_connected_description() })] }), _jsx(Button, { type: "button", variant: "outline", disabled: !canRevokeAccount, onClick: () => setRevokingAccount(passwordAccount), children: canRevokeAccount
|
|
235
214
|
? m.user_account_revoke()
|
|
236
|
-
: m.user_account_only_method() })] }), revokingAccount ? (_jsx(RevokeAccountForm, { account: revokingAccount, requirePassword: true, onCancel: () => setRevokingAccount(null), onRevoke: revokePassword })) : null, _jsx(Separator, {}), _jsx(ChangePasswordForm, {})] })) : (_jsx(SetPasswordForm, { onSaved: loadAccounts })), error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }));
|
|
215
|
+
: m.user_account_only_method() })] }), revokingAccount ? (_jsx(RevokeAccountForm, { authClient: authClient, account: revokingAccount, requirePassword: true, onCancel: () => setRevokingAccount(null), onRevoke: revokePassword })) : null, _jsx(Separator, {}), _jsx(ChangePasswordForm, { authClient: authClient })] })) : (_jsx(SetPasswordForm, { authClient: authClient, onSaved: loadAccounts })), error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }));
|
|
237
216
|
}
|
|
238
|
-
function ChangePasswordForm() {
|
|
217
|
+
function ChangePasswordForm({ authClient }) {
|
|
239
218
|
const [saved, setSaved] = useState(false);
|
|
240
219
|
const form = useAppForm({
|
|
241
220
|
defaultValues: { currentPassword: "", newPassword: "" },
|
|
242
221
|
onSubmit: async ({ value, formApi }) => {
|
|
243
222
|
setSaved(false);
|
|
244
223
|
formApi.setErrorMap({ onSubmit: undefined });
|
|
245
|
-
const result = await
|
|
224
|
+
const result = await authClient.changePassword({
|
|
246
225
|
currentPassword: value.currentPassword,
|
|
247
226
|
newPassword: value.newPassword,
|
|
248
227
|
});
|
|
@@ -265,12 +244,12 @@ function ChangePasswordForm() {
|
|
|
265
244
|
form.handleSubmit();
|
|
266
245
|
}, children: [_jsxs("div", { className: "flex flex-col gap-1", children: [_jsx("h3", { className: "text-sm font-medium", children: m.user_account_password_change_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_account_password_change_description() })] }), _jsx(form.AppField, { name: "currentPassword", children: (field) => (_jsx(field.TextField, { label: m.user_account_current_password(), type: "password", autoComplete: "current-password", required: true })) }), _jsx(form.AppField, { name: "newPassword", children: (field) => (_jsx(field.TextField, { label: m.user_account_new_password(), type: "password", autoComplete: "new-password", required: true })) }), _jsx(form.FormError, {}), saved ? (_jsx("p", { className: "text-sm text-green-600", children: m.user_account_password_change_success() })) : null, _jsx(Button, { type: "submit", className: "self-start", children: m.user_account_password_change_submit() })] }) }));
|
|
267
246
|
}
|
|
268
|
-
function SetPasswordForm({ onSaved }) {
|
|
247
|
+
function SetPasswordForm({ authClient, onSaved, }) {
|
|
269
248
|
const form = useAppForm({
|
|
270
249
|
defaultValues: { password: "" },
|
|
271
250
|
onSubmit: async ({ value, formApi }) => {
|
|
272
251
|
formApi.setErrorMap({ onSubmit: undefined });
|
|
273
|
-
const result = await
|
|
252
|
+
const result = await authClient.$fetch("/set-password", {
|
|
274
253
|
method: "POST",
|
|
275
254
|
body: { newPassword: value.password },
|
|
276
255
|
});
|
|
@@ -293,13 +272,13 @@ function SetPasswordForm({ onSaved }) {
|
|
|
293
272
|
form.handleSubmit();
|
|
294
273
|
}, children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.user_account_new_password(), type: "password", autoComplete: "new-password", required: true })) }), _jsx(form.FormError, {}), _jsx(Button, { type: "submit", className: "self-start", children: m.user_account_password_set() })] }) }));
|
|
295
274
|
}
|
|
296
|
-
function RevokeAccountForm({ account, requirePassword, onCancel, onRevoke, }) {
|
|
275
|
+
function RevokeAccountForm({ authClient, account, requirePassword, onCancel, onRevoke, }) {
|
|
297
276
|
const form = useAppForm({
|
|
298
277
|
defaultValues: { password: "" },
|
|
299
278
|
onSubmit: async ({ value, formApi }) => {
|
|
300
279
|
formApi.setErrorMap({ onSubmit: undefined });
|
|
301
280
|
if (requirePassword) {
|
|
302
|
-
const verified = await
|
|
281
|
+
const verified = await authClient.$fetch("/verify-password", {
|
|
303
282
|
method: "POST",
|
|
304
283
|
body: { password: value.password },
|
|
305
284
|
});
|
|
@@ -347,28 +326,28 @@ const UserForm = ({ defaultValues, error, onSubmit, }) => {
|
|
|
347
326
|
suggestedHeight: 512,
|
|
348
327
|
} })) }), _jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.user_form_name_label(), autoComplete: "name", required: true })) }), error && (_jsx("p", { role: "alert", className: "text-destructive text-sm", children: error })), _jsx(form.SubmitButton, {})] }) })] }));
|
|
349
328
|
};
|
|
350
|
-
function AccountSecuritySettings() {
|
|
351
|
-
const session =
|
|
329
|
+
function AccountSecuritySettings({ authClient }) {
|
|
330
|
+
const session = authClient.useSession();
|
|
352
331
|
const [setup, setSetup] = useState(null);
|
|
353
332
|
const [message, setMessage] = useState(null);
|
|
354
333
|
const twoFactorEnabled = hasTwoFactorEnabled(session.data?.user);
|
|
355
334
|
return (_jsxs("div", { className: "flex flex-col gap-6", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_two_factor_title() }), _jsx("p", { className: "text-muted-foreground text-xs", children: m.user_two_factor_description() })] }), _jsx(Badge, { variant: twoFactorEnabled ? "default" : "secondary", children: twoFactorEnabled
|
|
356
335
|
? m.user_two_factor_enabled()
|
|
357
|
-
: m.user_two_factor_disabled() })] }), twoFactorEnabled ? (_jsx(DisableTotpForm, { onDisabled: async () => {
|
|
336
|
+
: m.user_two_factor_disabled() })] }), twoFactorEnabled ? (_jsx(DisableTotpForm, { authClient: authClient, onDisabled: async () => {
|
|
358
337
|
setMessage(m.user_two_factor_disabled_message());
|
|
359
338
|
await session.refetch();
|
|
360
|
-
} })) : setup ? (_jsx(VerifyTotpSetup, { setup: setup, onVerified: async () => {
|
|
339
|
+
} })) : setup ? (_jsx(VerifyTotpSetup, { authClient: authClient, setup: setup, onVerified: async () => {
|
|
361
340
|
setSetup(null);
|
|
362
341
|
setMessage(m.user_two_factor_enabled_message());
|
|
363
342
|
await session.refetch();
|
|
364
|
-
} })) : (_jsx(EnableTotpForm, { onEnabled: setSetup })), message ? (_jsx("p", { className: "text-muted-foreground text-sm", children: message })) : null] }));
|
|
343
|
+
} })) : (_jsx(EnableTotpForm, { authClient: authClient, onEnabled: setSetup })), message ? (_jsx("p", { className: "text-muted-foreground text-sm", children: message })) : null] }));
|
|
365
344
|
}
|
|
366
|
-
function EnableTotpForm({ onEnabled, }) {
|
|
345
|
+
function EnableTotpForm({ authClient, onEnabled, }) {
|
|
367
346
|
const form = useAppForm({
|
|
368
347
|
defaultValues: { password: "" },
|
|
369
348
|
onSubmit: async ({ value, formApi }) => {
|
|
370
349
|
formApi.setErrorMap({ onSubmit: undefined });
|
|
371
|
-
const result = await
|
|
350
|
+
const result = await authClient.twoFactor.enable({
|
|
372
351
|
password: value.password,
|
|
373
352
|
});
|
|
374
353
|
if (result.error || !result.data) {
|
|
@@ -392,12 +371,12 @@ function EnableTotpForm({ onEnabled, }) {
|
|
|
392
371
|
form.handleSubmit();
|
|
393
372
|
}, children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.user_field_password(), type: "password", autoComplete: "current-password", required: true })) }), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }));
|
|
394
373
|
}
|
|
395
|
-
function VerifyTotpSetup({ setup, onVerified, }) {
|
|
374
|
+
function VerifyTotpSetup({ authClient, setup, onVerified, }) {
|
|
396
375
|
const form = useAppForm({
|
|
397
376
|
defaultValues: { code: "" },
|
|
398
377
|
onSubmit: async ({ value, formApi }) => {
|
|
399
378
|
formApi.setErrorMap({ onSubmit: undefined });
|
|
400
|
-
const result = await
|
|
379
|
+
const result = await authClient.twoFactor.verifyTotp({
|
|
401
380
|
code: value.code.trim(),
|
|
402
381
|
});
|
|
403
382
|
if (result.error) {
|
|
@@ -418,12 +397,12 @@ function VerifyTotpSetup({ setup, onVerified, }) {
|
|
|
418
397
|
form.handleSubmit();
|
|
419
398
|
}, children: [_jsx(form.AppField, { name: "code", children: (field) => (_jsx(field.TextField, { label: m.user_two_factor_code(), autoComplete: "one-time-code", inputMode: "numeric", required: true })) }), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) })] }));
|
|
420
399
|
}
|
|
421
|
-
function DisableTotpForm({ onDisabled }) {
|
|
400
|
+
function DisableTotpForm({ authClient, onDisabled, }) {
|
|
422
401
|
const form = useAppForm({
|
|
423
402
|
defaultValues: { password: "" },
|
|
424
403
|
onSubmit: async ({ value, formApi }) => {
|
|
425
404
|
formApi.setErrorMap({ onSubmit: undefined });
|
|
426
|
-
const result = await
|
|
405
|
+
const result = await authClient.twoFactor.disable({
|
|
427
406
|
password: value.password,
|
|
428
407
|
});
|
|
429
408
|
if (result.error) {
|
|
@@ -444,7 +423,7 @@ function DisableTotpForm({ onDisabled }) {
|
|
|
444
423
|
form.handleSubmit();
|
|
445
424
|
}, children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.user_field_password(), type: "password", autoComplete: "current-password", required: true })) }), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }));
|
|
446
425
|
}
|
|
447
|
-
function ApiKeyManager({ permissions = {}, }) {
|
|
426
|
+
function ApiKeyManager({ authClient, permissions = {}, }) {
|
|
448
427
|
const [keys, setKeys] = useState([]);
|
|
449
428
|
const [createdKey, setCreatedKey] = useState(null);
|
|
450
429
|
const [copiedKey, setCopiedKey] = useState(false);
|
|
@@ -452,10 +431,10 @@ function ApiKeyManager({ permissions = {}, }) {
|
|
|
452
431
|
const [loading, setLoading] = useState(true);
|
|
453
432
|
const permissionOptions = getPermissionOptions(permissions);
|
|
454
433
|
const [selectedPermissions, setSelectedPermissions] = useState({});
|
|
455
|
-
const loadKeys = async () => {
|
|
434
|
+
const loadKeys = useEffectEvent(async () => {
|
|
456
435
|
setLoading(true);
|
|
457
436
|
setError(null);
|
|
458
|
-
const result = await
|
|
437
|
+
const result = await authClient.apiKey.list({
|
|
459
438
|
query: { configId: "user" },
|
|
460
439
|
});
|
|
461
440
|
if (result.error) {
|
|
@@ -465,7 +444,7 @@ function ApiKeyManager({ permissions = {}, }) {
|
|
|
465
444
|
}
|
|
466
445
|
setKeys(result.data?.apiKeys ?? []);
|
|
467
446
|
setLoading(false);
|
|
468
|
-
};
|
|
447
|
+
});
|
|
469
448
|
useEffect(() => {
|
|
470
449
|
void loadKeys();
|
|
471
450
|
}, []);
|
|
@@ -476,7 +455,7 @@ function ApiKeyManager({ permissions = {}, }) {
|
|
|
476
455
|
setCreatedKey(null);
|
|
477
456
|
setCopiedKey(false);
|
|
478
457
|
const selectedPermissionObject = getSelectedPermissionObject(permissionOptions, selectedPermissions);
|
|
479
|
-
const result = await
|
|
458
|
+
const result = await authClient.$fetch("/create-api-key", {
|
|
480
459
|
method: "POST",
|
|
481
460
|
body: {
|
|
482
461
|
configId: "user",
|
|
@@ -511,7 +490,7 @@ function ApiKeyManager({ permissions = {}, }) {
|
|
|
511
490
|
window.setTimeout(() => setCopiedKey(false), 2000);
|
|
512
491
|
};
|
|
513
492
|
const deleteKey = async (key) => {
|
|
514
|
-
const result = await
|
|
493
|
+
const result = await authClient.apiKey.delete({
|
|
515
494
|
configId: "user",
|
|
516
495
|
keyId: key.id,
|
|
517
496
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "./schema";
|
|
2
2
|
export { AuthClient, AuthClientConfig } from "./client";
|
|
3
|
-
export { OrganizationSwitcher, UserButton } from "./components";
|
|
3
|
+
export { OrganizationSwitcher, UserButton, type AuthUiClient, } from "./components";
|
|
4
4
|
export * as Backend from "./backend";
|
|
5
5
|
export * as Frontend from "./frontend";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "./schema";
|
|
2
2
|
export { AuthClient, AuthClientConfig } from "./client";
|
|
3
|
-
export { OrganizationSwitcher, UserButton } from "./components";
|
|
3
|
+
export { OrganizationSwitcher, UserButton, } from "./components";
|
|
4
4
|
export * as Backend from "./backend";
|
|
5
5
|
export * as Frontend from "./frontend";
|