@krak-stack/auth 0.1.42 → 0.1.44
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/admin/api.group.d.ts +5 -0
- package/dist/admin/schema.d.ts +4 -0
- package/dist/admin/schema.js +4 -0
- package/dist/api.d.ts +5 -0
- package/dist/components/admin-organizations.d.ts +1 -1
- package/dist/components/admin-organizations.js +17 -12
- package/dist/components/admin-users.d.ts +1 -1
- package/dist/components/admin-users.js +21 -2
- package/dist/components/auth-client-api.d.ts +5 -0
- package/dist/components/auth-client.d.ts +50 -4
- package/dist/components/auth-client.js +15 -1
- package/dist/components/auth-provider.d.ts +2 -1
- package/dist/components/auth-provider.js +8 -15
- package/dist/components/index.d.ts +3 -1
- package/dist/components/index.js +3 -1
- package/dist/components/organization-switcher.d.ts +2 -2
- package/dist/components/organization-switcher.js +47 -25
- package/dist/components/user-button.d.ts +2 -2
- package/dist/components/user-button.js +11 -17
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +5 -4
|
@@ -32,6 +32,7 @@ export declare const AdminApiGroup: HttpApiGroup.HttpApiGroup<"admin", HttpApiEn
|
|
|
32
32
|
readonly slug: Schema.String;
|
|
33
33
|
readonly logo: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
34
34
|
readonly metadata: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
35
|
+
readonly memberCount: Schema.optional<Schema.Number>;
|
|
35
36
|
readonly createdAt: Schema.Date;
|
|
36
37
|
}>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"dashboardStats", "GET", "/admin/dashboard-stats", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<Schema.Struct<{
|
|
37
38
|
readonly days: Schema.optional<Schema.Union<readonly [Schema.Literal<"7">, Schema.Literal<"14">, Schema.Literal<"30">, Schema.Literal<"90">]>>;
|
|
@@ -82,6 +83,7 @@ export declare const AdminApiGroup: HttpApiGroup.HttpApiGroup<"admin", HttpApiEn
|
|
|
82
83
|
readonly slug: Schema.String;
|
|
83
84
|
readonly logo: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
84
85
|
readonly metadata: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
86
|
+
readonly memberCount: Schema.optional<Schema.Number>;
|
|
85
87
|
readonly createdAt: Schema.Date;
|
|
86
88
|
}>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getDomainRecords", "GET", "/admin/domains/:id/records", HttpApiEndpoint.StringTree<Schema.Struct<{
|
|
87
89
|
readonly id: Schema.NonEmptyString;
|
|
@@ -122,6 +124,7 @@ export declare const AdminApiGroup: HttpApiGroup.HttpApiGroup<"admin", HttpApiEn
|
|
|
122
124
|
readonly slug: string;
|
|
123
125
|
readonly logo?: string | null | undefined;
|
|
124
126
|
readonly metadata?: string | null | undefined;
|
|
127
|
+
readonly memberCount?: number | undefined;
|
|
125
128
|
readonly createdAt: Date;
|
|
126
129
|
}>>;
|
|
127
130
|
readonly meta: Schema.Struct<{
|
|
@@ -147,6 +150,7 @@ export declare const AdminApiGroup: HttpApiGroup.HttpApiGroup<"admin", HttpApiEn
|
|
|
147
150
|
readonly emailVerified: Schema.Boolean;
|
|
148
151
|
readonly image: Schema.NullOr<Schema.String>;
|
|
149
152
|
readonly createdAt: Schema.Date;
|
|
153
|
+
readonly lastSignedIn: Schema.NullOr<Schema.Date>;
|
|
150
154
|
readonly role: Schema.NullOr<Schema.String>;
|
|
151
155
|
readonly banned: Schema.NullOr<Schema.Boolean>;
|
|
152
156
|
readonly banReason: Schema.NullOr<Schema.String>;
|
|
@@ -193,5 +197,6 @@ export declare const AdminApiGroup: HttpApiGroup.HttpApiGroup<"admin", HttpApiEn
|
|
|
193
197
|
readonly slug: Schema.String;
|
|
194
198
|
readonly logo: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
195
199
|
readonly metadata: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
200
|
+
readonly memberCount: Schema.optional<Schema.Number>;
|
|
196
201
|
readonly createdAt: Schema.Date;
|
|
197
202
|
}>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError>, never, never>, false>;
|
package/dist/admin/schema.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare const AdminUser: Schema.Struct<{
|
|
|
17
17
|
readonly emailVerified: Schema.Boolean;
|
|
18
18
|
readonly image: Schema.NullOr<Schema.String>;
|
|
19
19
|
readonly createdAt: Schema.Date;
|
|
20
|
+
readonly lastSignedIn: Schema.NullOr<Schema.Date>;
|
|
20
21
|
readonly role: Schema.NullOr<Schema.String>;
|
|
21
22
|
readonly banned: Schema.NullOr<Schema.Boolean>;
|
|
22
23
|
readonly banReason: Schema.NullOr<Schema.String>;
|
|
@@ -28,6 +29,7 @@ export declare const AdminOrganization: Schema.Struct<{
|
|
|
28
29
|
readonly slug: Schema.String;
|
|
29
30
|
readonly logo: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
30
31
|
readonly metadata: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
32
|
+
readonly memberCount: Schema.optional<Schema.Number>;
|
|
31
33
|
readonly createdAt: Schema.Date;
|
|
32
34
|
}>;
|
|
33
35
|
export declare const AdminOrganizationIdParams: Schema.Struct<{
|
|
@@ -91,6 +93,7 @@ export declare const PaginatedAdminUsers: Schema.Struct<{
|
|
|
91
93
|
readonly emailVerified: Schema.Boolean;
|
|
92
94
|
readonly image: Schema.NullOr<Schema.String>;
|
|
93
95
|
readonly createdAt: Schema.Date;
|
|
96
|
+
readonly lastSignedIn: Schema.NullOr<Schema.Date>;
|
|
94
97
|
readonly role: Schema.NullOr<Schema.String>;
|
|
95
98
|
readonly banned: Schema.NullOr<Schema.Boolean>;
|
|
96
99
|
readonly banReason: Schema.NullOr<Schema.String>;
|
|
@@ -110,6 +113,7 @@ export declare const PaginatedAdminOrganizations: Schema.Struct<{
|
|
|
110
113
|
readonly slug: string;
|
|
111
114
|
readonly logo?: string | null | undefined;
|
|
112
115
|
readonly metadata?: string | null | undefined;
|
|
116
|
+
readonly memberCount?: number | undefined;
|
|
113
117
|
readonly createdAt: Date;
|
|
114
118
|
}>>;
|
|
115
119
|
readonly meta: Schema.Struct<{
|
package/dist/admin/schema.js
CHANGED
|
@@ -17,6 +17,7 @@ export const AdminUser = Schema.Struct({
|
|
|
17
17
|
emailVerified: Schema.Boolean,
|
|
18
18
|
image: Schema.NullOr(Schema.String),
|
|
19
19
|
createdAt: Schema.Date,
|
|
20
|
+
lastSignedIn: Schema.NullOr(Schema.Date),
|
|
20
21
|
role: Schema.NullOr(Schema.String),
|
|
21
22
|
banned: Schema.NullOr(Schema.Boolean),
|
|
22
23
|
banReason: Schema.NullOr(Schema.String),
|
|
@@ -33,6 +34,7 @@ export const AdminUser = Schema.Struct({
|
|
|
33
34
|
emailVerified: true,
|
|
34
35
|
image: null,
|
|
35
36
|
createdAt: new Date("2026-01-01T00:00:00.000Z"),
|
|
37
|
+
lastSignedIn: new Date("2026-01-02T00:00:00.000Z"),
|
|
36
38
|
role: "admin",
|
|
37
39
|
banned: false,
|
|
38
40
|
banReason: null,
|
|
@@ -46,6 +48,7 @@ export const AdminOrganization = Schema.Struct({
|
|
|
46
48
|
slug: Schema.String,
|
|
47
49
|
logo: Schema.optional(Schema.NullOr(Schema.String)),
|
|
48
50
|
metadata: Schema.optional(Schema.NullOr(Schema.String)),
|
|
51
|
+
memberCount: Schema.optional(Schema.Number),
|
|
49
52
|
createdAt: Schema.Date,
|
|
50
53
|
}).annotate({
|
|
51
54
|
identifier: "AdminOrganization",
|
|
@@ -58,6 +61,7 @@ export const AdminOrganization = Schema.Struct({
|
|
|
58
61
|
slug: "krakstack",
|
|
59
62
|
logo: "https://example.com/logo.svg",
|
|
60
63
|
metadata: '{"tier":"internal"}',
|
|
64
|
+
memberCount: 12,
|
|
61
65
|
createdAt: new Date("2026-01-01T00:00:00.000Z"),
|
|
62
66
|
},
|
|
63
67
|
],
|
package/dist/api.d.ts
CHANGED
|
@@ -313,6 +313,7 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
|
|
|
313
313
|
readonly slug: import("effect/Schema").String;
|
|
314
314
|
readonly logo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
315
315
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
316
|
+
readonly memberCount: import("effect/Schema").optional<import("effect/Schema").Number>;
|
|
316
317
|
readonly createdAt: import("effect/Schema").Date;
|
|
317
318
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"dashboardStats", "GET", "/api/auth/admin/dashboard-stats", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
318
319
|
readonly days: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"7">, import("effect/Schema").Literal<"14">, import("effect/Schema").Literal<"30">, import("effect/Schema").Literal<"90">]>>;
|
|
@@ -363,6 +364,7 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
|
|
|
363
364
|
readonly slug: import("effect/Schema").String;
|
|
364
365
|
readonly logo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
365
366
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
367
|
+
readonly memberCount: import("effect/Schema").optional<import("effect/Schema").Number>;
|
|
366
368
|
readonly createdAt: import("effect/Schema").Date;
|
|
367
369
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getDomainRecords", "GET", "/api/auth/admin/domains/:id/records", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
368
370
|
readonly id: import("effect/Schema").NonEmptyString;
|
|
@@ -403,6 +405,7 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
|
|
|
403
405
|
readonly slug: string;
|
|
404
406
|
readonly logo?: string | null | undefined;
|
|
405
407
|
readonly metadata?: string | null | undefined;
|
|
408
|
+
readonly memberCount?: number | undefined;
|
|
406
409
|
readonly createdAt: Date;
|
|
407
410
|
}>>;
|
|
408
411
|
readonly meta: import("effect/Schema").Struct<{
|
|
@@ -428,6 +431,7 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
|
|
|
428
431
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
429
432
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
430
433
|
readonly createdAt: import("effect/Schema").Date;
|
|
434
|
+
readonly lastSignedIn: import("effect/Schema").NullOr<import("effect/Schema").Date>;
|
|
431
435
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
432
436
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
433
437
|
readonly banReason: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
@@ -474,6 +478,7 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
|
|
|
474
478
|
readonly slug: import("effect/Schema").String;
|
|
475
479
|
readonly logo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
476
480
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
481
|
+
readonly memberCount: import("effect/Schema").optional<import("effect/Schema").Number>;
|
|
477
482
|
readonly createdAt: import("effect/Schema").Date;
|
|
478
483
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never>, false> | import("effect/unstable/httpapi/HttpApiGroup").HttpApiGroup<"authExtra", import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"createApiKey", "POST", "/api/auth/create-api-key", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
479
484
|
readonly configId: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>;
|
|
@@ -3,5 +3,5 @@ import { type TableParams } from "@/components/ui/data-table";
|
|
|
3
3
|
export declare function AdminOrganizationsTable({ from, reloadKey, search, }: {
|
|
4
4
|
from?: ValidateFromPath;
|
|
5
5
|
reloadKey?: number;
|
|
6
|
-
search
|
|
6
|
+
search?: TableParams;
|
|
7
7
|
}): import("react").JSX.Element;
|
|
@@ -8,26 +8,21 @@ import { useState } from "react";
|
|
|
8
8
|
import { DataTable } from "@/components/ui/data-table";
|
|
9
9
|
import { ErrorMessage } from "@/components/ui/form";
|
|
10
10
|
import { AppBrand } from "@/components/ui/app-brand";
|
|
11
|
-
import { Badge } from "@/components/ui/badge";
|
|
12
11
|
import { authClientApi } from "./auth-client-api";
|
|
13
12
|
import { useKrakstackAuth } from "./auth-provider";
|
|
14
13
|
import { assetUrl, organizationBranding } from "./utils";
|
|
15
14
|
const defaultMessages = {
|
|
16
15
|
en: {
|
|
17
16
|
admin_column_created: "Created",
|
|
17
|
+
admin_column_members: "Members",
|
|
18
18
|
admin_column_organization: "Organization",
|
|
19
|
-
admin_none: "None",
|
|
20
|
-
oauth_client_logo_configured: "Configured",
|
|
21
19
|
organization_fetch_error: "Unable to load organizations.",
|
|
22
|
-
organization_field_logo_url: "Logo",
|
|
23
20
|
},
|
|
24
21
|
fr: {
|
|
25
22
|
admin_column_created: "Créé",
|
|
23
|
+
admin_column_members: "Membres",
|
|
26
24
|
admin_column_organization: "Organisation",
|
|
27
|
-
admin_none: "Aucun",
|
|
28
|
-
oauth_client_logo_configured: "Configuré",
|
|
29
25
|
organization_fetch_error: "Impossible de charger les organisations.",
|
|
30
|
-
organization_field_logo_url: "Logo",
|
|
31
26
|
},
|
|
32
27
|
};
|
|
33
28
|
const labels = (locale) => ({
|
|
@@ -72,11 +67,15 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
|
|
|
72
67
|
const baseUrl = auth?.baseUrl;
|
|
73
68
|
const projectId = auth?.projectId;
|
|
74
69
|
const [refreshKey, setRefreshKey] = useState(0);
|
|
70
|
+
const [localSearch, setLocalSearch] = useState({
|
|
71
|
+
globalFilter: "",
|
|
72
|
+
});
|
|
73
|
+
const tableSearch = search ?? localSearch;
|
|
75
74
|
const result = useAtomValue(organizationsAtom({
|
|
76
75
|
baseUrl,
|
|
77
76
|
projectId,
|
|
78
77
|
reloadKey: reloadKey + refreshKey,
|
|
79
|
-
search,
|
|
78
|
+
search: tableSearch,
|
|
80
79
|
}));
|
|
81
80
|
const organizations = AsyncResult.match(result, {
|
|
82
81
|
onInitial: () => [],
|
|
@@ -98,7 +97,13 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
|
|
|
98
97
|
onFailure: () => false,
|
|
99
98
|
onSuccess: () => false,
|
|
100
99
|
});
|
|
101
|
-
return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, _jsx(DataTable, { columns: organizationColumns(m, locale, baseUrl), data: organizations, exportFileName: "organizations.csv", features: { gallery: false }, ...(from ? { from } : {}),
|
|
100
|
+
return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, _jsx(DataTable, { columns: organizationColumns(m, locale, baseUrl), data: organizations, exportFileName: "organizations.csv", features: { gallery: false }, ...(from ? { from } : {}), ...(!search
|
|
101
|
+
? {
|
|
102
|
+
search: tableSearch,
|
|
103
|
+
onSearchChange: setLocalSearch,
|
|
104
|
+
searchState: "local",
|
|
105
|
+
}
|
|
106
|
+
: {}), isLoading: isLoading, onRefresh: () => setRefreshKey((current) => current + 1), serverPagination: { rowCount: total } })] }));
|
|
102
107
|
}
|
|
103
108
|
const organizationColumns = (m, locale, baseUrl) => [
|
|
104
109
|
{
|
|
@@ -110,9 +115,9 @@ const organizationColumns = (m, locale, baseUrl) => [
|
|
|
110
115
|
},
|
|
111
116
|
},
|
|
112
117
|
{
|
|
113
|
-
accessorKey: "
|
|
114
|
-
header: m.
|
|
115
|
-
cell: ({ row }) =>
|
|
118
|
+
accessorKey: "memberCount",
|
|
119
|
+
header: m.admin_column_members,
|
|
120
|
+
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm tabular-nums", children: (row.original.memberCount ?? 0).toLocaleString() })),
|
|
116
121
|
},
|
|
117
122
|
{
|
|
118
123
|
accessorKey: "createdAt",
|
|
@@ -3,6 +3,6 @@ import { type TableParams } from "@/components/ui/data-table";
|
|
|
3
3
|
export declare function AdminUsersTable({ from, reloadKey, search, }: {
|
|
4
4
|
from?: ValidateFromPath;
|
|
5
5
|
reloadKey?: number;
|
|
6
|
-
search
|
|
6
|
+
search?: TableParams;
|
|
7
7
|
}): import("react").JSX.Element;
|
|
8
8
|
export declare function useAdminUsersTotal(search: TableParams): number;
|
|
@@ -22,6 +22,7 @@ const defaultMessages = {
|
|
|
22
22
|
admin_ban_description: "Are you sure you want to ban {name} ({email})? They will not be able to sign in.",
|
|
23
23
|
admin_ban_title: "Ban user",
|
|
24
24
|
admin_column_created: "Created",
|
|
25
|
+
admin_column_last_signed_in: "Last signed in",
|
|
25
26
|
admin_column_role: "Role",
|
|
26
27
|
admin_column_status: "Status",
|
|
27
28
|
admin_column_unverified: "Unverified",
|
|
@@ -45,6 +46,7 @@ const defaultMessages = {
|
|
|
45
46
|
admin_ban_description: "Êtes-vous sûr de vouloir bannir {name} ({email}) ? Il ne pourra plus se connecter.",
|
|
46
47
|
admin_ban_title: "Bannir l'utilisateur",
|
|
47
48
|
admin_column_created: "Créé",
|
|
49
|
+
admin_column_last_signed_in: "Dernière connexion",
|
|
48
50
|
admin_column_role: "Rôle",
|
|
49
51
|
admin_column_status: "Statut",
|
|
50
52
|
admin_column_unverified: "Non vérifié",
|
|
@@ -116,10 +118,14 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
|
|
|
116
118
|
const [impersonatingUserId, setImpersonatingUserId] = useState(null);
|
|
117
119
|
const [impersonateError, setImpersonateError] = useState("");
|
|
118
120
|
const [refreshKey, setRefreshKey] = useState(0);
|
|
121
|
+
const [localSearch, setLocalSearch] = useState({
|
|
122
|
+
globalFilter: "",
|
|
123
|
+
});
|
|
124
|
+
const tableSearch = search ?? localSearch;
|
|
119
125
|
const result = useAtomValue(usersAtom({
|
|
120
126
|
baseUrl,
|
|
121
127
|
projectId,
|
|
122
|
-
search,
|
|
128
|
+
search: tableSearch,
|
|
123
129
|
reloadKey: reloadKey + refreshKey,
|
|
124
130
|
}));
|
|
125
131
|
const [banningUser, setBanningUser] = useState(null);
|
|
@@ -144,7 +150,13 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
|
|
|
144
150
|
onFailure: () => false,
|
|
145
151
|
onSuccess: () => false,
|
|
146
152
|
});
|
|
147
|
-
return (_jsxs(_Fragment, { children: [error ? _jsx(ErrorMessage, { text: error }) : null, impersonateError ? _jsx(ErrorMessage, { text: impersonateError }) : null, _jsx(DataTable, { columns: userColumns(m), data: users, exportFileName: "users.csv", features: { gallery: false }, ...(from ? { from } : {}),
|
|
153
|
+
return (_jsxs(_Fragment, { children: [error ? _jsx(ErrorMessage, { text: error }) : null, impersonateError ? _jsx(ErrorMessage, { text: impersonateError }) : null, _jsx(DataTable, { columns: userColumns(m), data: users, exportFileName: "users.csv", features: { gallery: false }, ...(from ? { from } : {}), ...(!search
|
|
154
|
+
? {
|
|
155
|
+
search: tableSearch,
|
|
156
|
+
onSearchChange: setLocalSearch,
|
|
157
|
+
searchState: "local",
|
|
158
|
+
}
|
|
159
|
+
: {}), isLoading: isLoading, onRefresh: () => setRefreshKey((current) => current + 1), serverPagination: { rowCount: total }, rowActions: [
|
|
148
160
|
{
|
|
149
161
|
name: m.admin_action_impersonate,
|
|
150
162
|
icon: impersonatingUserId ? (_jsx(Loader2, { className: "size-4 animate-spin" })) : (_jsx(UserCog, { className: "size-4" })),
|
|
@@ -226,6 +238,13 @@ const userColumns = (m) => [
|
|
|
226
238
|
header: m.admin_column_status,
|
|
227
239
|
cell: ({ row }) => row.original.banned ? (_jsx(Badge, { variant: "destructive", children: m.admin_status_banned })) : (_jsx(Badge, { variant: "outline", children: m.admin_status_active })),
|
|
228
240
|
},
|
|
241
|
+
{
|
|
242
|
+
accessorKey: "lastSignedIn",
|
|
243
|
+
header: m.admin_column_last_signed_in,
|
|
244
|
+
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: row.original.lastSignedIn
|
|
245
|
+
? new Date(row.original.lastSignedIn).toLocaleString()
|
|
246
|
+
: "-" })),
|
|
247
|
+
},
|
|
229
248
|
{
|
|
230
249
|
accessorKey: "createdAt",
|
|
231
250
|
header: m.admin_column_created,
|
|
@@ -30,6 +30,7 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
30
30
|
readonly slug: import("effect/Schema").String;
|
|
31
31
|
readonly logo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
32
32
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
33
|
+
readonly memberCount: import("effect/Schema").optional<import("effect/Schema").Number>;
|
|
33
34
|
readonly createdAt: import("effect/Schema").Date;
|
|
34
35
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"dashboardStats", "GET", "/api/auth/admin/dashboard-stats", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
35
36
|
readonly days: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"7">, import("effect/Schema").Literal<"14">, import("effect/Schema").Literal<"30">, import("effect/Schema").Literal<"90">]>>;
|
|
@@ -80,6 +81,7 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
80
81
|
readonly slug: import("effect/Schema").String;
|
|
81
82
|
readonly logo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
82
83
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
84
|
+
readonly memberCount: import("effect/Schema").optional<import("effect/Schema").Number>;
|
|
83
85
|
readonly createdAt: import("effect/Schema").Date;
|
|
84
86
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getDomainRecords", "GET", "/api/auth/admin/domains/:id/records", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
85
87
|
readonly id: import("effect/Schema").NonEmptyString;
|
|
@@ -120,6 +122,7 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
120
122
|
readonly slug: string;
|
|
121
123
|
readonly logo?: string | null | undefined;
|
|
122
124
|
readonly metadata?: string | null | undefined;
|
|
125
|
+
readonly memberCount?: number | undefined;
|
|
123
126
|
readonly createdAt: Date;
|
|
124
127
|
}>>;
|
|
125
128
|
readonly meta: import("effect/Schema").Struct<{
|
|
@@ -145,6 +148,7 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
145
148
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
146
149
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
147
150
|
readonly createdAt: import("effect/Schema").Date;
|
|
151
|
+
readonly lastSignedIn: import("effect/Schema").NullOr<import("effect/Schema").Date>;
|
|
148
152
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
149
153
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
150
154
|
readonly banReason: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
@@ -191,6 +195,7 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
191
195
|
readonly slug: import("effect/Schema").String;
|
|
192
196
|
readonly logo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
193
197
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
198
|
+
readonly memberCount: import("effect/Schema").optional<import("effect/Schema").Number>;
|
|
194
199
|
readonly createdAt: import("effect/Schema").Date;
|
|
195
200
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never>, false> | import("effect/unstable/httpapi/HttpApiGroup").HttpApiGroup<"authExtra", import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"createApiKey", "POST", "/api/auth/create-api-key", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
196
201
|
readonly configId: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>;
|
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { apiKeyClient } from "@better-auth/api-key/client";
|
|
2
|
+
import { adminClient, emailOTPClient, genericOAuthClient, lastLoginMethodClient, organizationClient, twoFactorClient } from "better-auth/client/plugins";
|
|
3
|
+
import { createAuthClient } from "better-auth/react";
|
|
4
|
+
type Session = {
|
|
5
|
+
session: {
|
|
6
|
+
activeOrganizationId?: string | null | undefined;
|
|
7
|
+
impersonatedBy?: string | null | undefined;
|
|
8
|
+
};
|
|
9
|
+
user: {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
email: string;
|
|
13
|
+
image?: string | null | undefined;
|
|
14
|
+
role?: string | null | undefined;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
type Query<T> = {
|
|
18
|
+
data: T | null | undefined;
|
|
19
|
+
isPending: boolean;
|
|
20
|
+
refetch: () => Promise<unknown>;
|
|
21
|
+
};
|
|
22
|
+
type BaseAuthUiClient = ReturnType<typeof createAuthClient<{
|
|
5
23
|
plugins: [
|
|
6
24
|
ReturnType<typeof adminClient>,
|
|
7
25
|
ReturnType<typeof emailOTPClient>,
|
|
@@ -12,3 +30,31 @@ export type AuthUiClient = ReturnType<typeof createAuthClient<{
|
|
|
12
30
|
ReturnType<typeof genericOAuthClient>
|
|
13
31
|
];
|
|
14
32
|
}>>;
|
|
33
|
+
export type AuthUiClient = Omit<BaseAuthUiClient, "getSession" | "organization" | "useSession" | "useActiveOrganization" | "useActiveMemberRole"> & {
|
|
34
|
+
getSession: () => Promise<{
|
|
35
|
+
data: Session | null;
|
|
36
|
+
error: unknown;
|
|
37
|
+
}>;
|
|
38
|
+
organization: {
|
|
39
|
+
setActive: (input: {
|
|
40
|
+
organizationId: string;
|
|
41
|
+
}) => Promise<{
|
|
42
|
+
data: unknown;
|
|
43
|
+
error: unknown;
|
|
44
|
+
}>;
|
|
45
|
+
};
|
|
46
|
+
useSession: () => Query<Session>;
|
|
47
|
+
useActiveOrganization: () => Query<{
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
slug: string;
|
|
51
|
+
createdAt: Date | string;
|
|
52
|
+
members: unknown[];
|
|
53
|
+
invitations: unknown[];
|
|
54
|
+
}>;
|
|
55
|
+
useActiveMemberRole: () => Query<{
|
|
56
|
+
role: string;
|
|
57
|
+
}>;
|
|
58
|
+
};
|
|
59
|
+
export declare const createAuthUiClient: (baseUrl?: string | undefined) => AuthUiClient;
|
|
60
|
+
export {};
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { apiKeyClient } from "@better-auth/api-key/client";
|
|
2
|
+
import { adminClient, emailOTPClient, genericOAuthClient, lastLoginMethodClient, organizationClient, twoFactorClient, } from "better-auth/client/plugins";
|
|
3
|
+
import { createAuthClient } from "better-auth/react";
|
|
4
|
+
export const createAuthUiClient = (baseUrl) => createAuthClient({
|
|
5
|
+
...(baseUrl ? { baseURL: baseUrl } : {}),
|
|
6
|
+
plugins: [
|
|
7
|
+
adminClient(),
|
|
8
|
+
emailOTPClient(),
|
|
9
|
+
lastLoginMethodClient(),
|
|
10
|
+
organizationClient(),
|
|
11
|
+
twoFactorClient(),
|
|
12
|
+
apiKeyClient(),
|
|
13
|
+
genericOAuthClient(),
|
|
14
|
+
],
|
|
15
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
-
import type
|
|
2
|
+
import { type AuthUiClient } from "./auth-client";
|
|
3
3
|
import type { ExtraProjectPublicConfig } from "../extra/schema";
|
|
4
4
|
export type KrakstackAuthLocale = "en" | "fr";
|
|
5
5
|
export type KrakstackAuthProviderProps = {
|
|
@@ -18,6 +18,7 @@ export type KrakstackAuthContextValue = {
|
|
|
18
18
|
};
|
|
19
19
|
export declare function KrakstackAuthProvider({ children, locale, baseUrl, projectId, authClient, }: KrakstackAuthProviderProps): import("react").JSX.Element;
|
|
20
20
|
export declare const useKrakstackAuth: () => KrakstackAuthContextValue | null;
|
|
21
|
+
export declare const useAuthClient: () => AuthUiClient;
|
|
21
22
|
export declare const useKrakstackAuthProjectConfig: () => import("effect/Schema").Struct.ReadonlySide<{
|
|
22
23
|
readonly projectKey: import("effect/Schema").String;
|
|
23
24
|
readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { apiKeyClient } from "@better-auth/api-key/client";
|
|
3
2
|
import { useAtomSuspense } from "@effect/atom-react";
|
|
4
3
|
import { useRouterState } from "@tanstack/react-router";
|
|
5
|
-
import { adminClient, emailOTPClient, genericOAuthClient, lastLoginMethodClient, organizationClient, twoFactorClient, } from "better-auth/client/plugins";
|
|
6
|
-
import { createAuthClient } from "better-auth/react";
|
|
7
4
|
import { createContext, useContext, useEffect, useMemo, } from "react";
|
|
5
|
+
import { createAuthUiClient } from "./auth-client";
|
|
8
6
|
import { authClientApi } from "./auth-client-api";
|
|
9
7
|
const KrakstackAuthContext = createContext(null);
|
|
10
8
|
const PROJECT_CONTEXT_COOKIE = "krakstack-auth.project_context";
|
|
@@ -18,18 +16,6 @@ const setProjectContextCookie = (projectId) => {
|
|
|
18
16
|
}
|
|
19
17
|
document.cookie = `${PROJECT_CONTEXT_COOKIE}=${encodeURIComponent(projectId)}; Path=/; Max-Age=600; SameSite=Lax${secure}`;
|
|
20
18
|
};
|
|
21
|
-
const createAuthUiClient = (baseUrl) => createAuthClient({
|
|
22
|
-
...(baseUrl ? { baseURL: baseUrl } : {}),
|
|
23
|
-
plugins: [
|
|
24
|
-
adminClient(),
|
|
25
|
-
emailOTPClient(),
|
|
26
|
-
lastLoginMethodClient(),
|
|
27
|
-
organizationClient(),
|
|
28
|
-
twoFactorClient(),
|
|
29
|
-
apiKeyClient(),
|
|
30
|
-
genericOAuthClient(),
|
|
31
|
-
],
|
|
32
|
-
});
|
|
33
19
|
const getSearchParam = (searchString, key) => {
|
|
34
20
|
if (!searchString)
|
|
35
21
|
return null;
|
|
@@ -101,4 +87,11 @@ export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projec
|
|
|
101
87
|
return (_jsx(KrakstackAuthContext.Provider, { value: value, children: children }));
|
|
102
88
|
}
|
|
103
89
|
export const useKrakstackAuth = () => useContext(KrakstackAuthContext);
|
|
90
|
+
export const useAuthClient = () => {
|
|
91
|
+
const auth = useKrakstackAuth();
|
|
92
|
+
if (!auth?.authClient) {
|
|
93
|
+
throw new Error("KrakstackAuthProvider is required to use authClient.");
|
|
94
|
+
}
|
|
95
|
+
return auth.authClient;
|
|
96
|
+
};
|
|
104
97
|
export const useKrakstackAuthProjectConfig = () => useKrakstackAuth()?.projectConfig ?? null;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
export { KrakstackAuthProvider, useKrakstackAuth, useKrakstackAuthProjectConfig, } from "./auth-provider";
|
|
1
|
+
export { KrakstackAuthProvider, useAuthClient, useKrakstackAuth, useKrakstackAuthProjectConfig, } from "./auth-provider";
|
|
2
|
+
export { createAuthUiClient } from "./auth-client";
|
|
2
3
|
export { OrganizationSwitcher } from "./organization-switcher";
|
|
3
4
|
export { ResetPassword, Signin, Signup, TwoFactor } from "./auth-forms";
|
|
4
5
|
export { UserButton } from "./user-button";
|
|
5
6
|
export { AdminOrganizationsTable } from "./admin-organizations";
|
|
6
7
|
export { AdminOrganizationForm } from "./admin-organization-form";
|
|
7
8
|
export { AdminUsersTable, useAdminUsersTotal } from "./admin-users";
|
|
9
|
+
export { assetUrl } from "./utils";
|
|
8
10
|
export type { KrakstackAuthContextValue, KrakstackAuthLocale, KrakstackAuthProviderProps, } from "./auth-provider";
|
|
9
11
|
export type { OrganizationSwitcherDialog } from "./organization-switcher";
|
|
10
12
|
export type { UserButtonDialog } from "./user-button";
|
package/dist/components/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export { KrakstackAuthProvider, useKrakstackAuth, useKrakstackAuthProjectConfig, } from "./auth-provider";
|
|
1
|
+
export { KrakstackAuthProvider, useAuthClient, useKrakstackAuth, useKrakstackAuthProjectConfig, } from "./auth-provider";
|
|
2
|
+
export { createAuthUiClient } from "./auth-client";
|
|
2
3
|
export { OrganizationSwitcher } from "./organization-switcher";
|
|
3
4
|
export { ResetPassword, Signin, Signup, TwoFactor } from "./auth-forms";
|
|
4
5
|
export { UserButton } from "./user-button";
|
|
5
6
|
export { AdminOrganizationsTable } from "./admin-organizations";
|
|
6
7
|
export { AdminOrganizationForm } from "./admin-organization-form";
|
|
7
8
|
export { AdminUsersTable, useAdminUsersTotal } from "./admin-users";
|
|
9
|
+
export { assetUrl } from "./utils";
|
|
@@ -164,7 +164,7 @@ declare const messages: {
|
|
|
164
164
|
type OrganizationSwitcherMessageKey = keyof (typeof messages)["en"];
|
|
165
165
|
export type OrganizationSwitcherMessages = Partial<Record<OrganizationSwitcherMessageKey, string>>;
|
|
166
166
|
type OrganizationSwitcherProps = {
|
|
167
|
-
authClient
|
|
167
|
+
authClient?: AuthUiClient;
|
|
168
168
|
baseUrl?: string | undefined;
|
|
169
169
|
side?: ComponentProps<typeof DropdownMenuContent>["side"];
|
|
170
170
|
className?: string;
|
|
@@ -185,5 +185,5 @@ type OrganizationSummary = {
|
|
|
185
185
|
metadata?: unknown;
|
|
186
186
|
};
|
|
187
187
|
export type OrganizationSwitcherDialog = "create" | "manage" | "members" | "apiKeys" | "invitations";
|
|
188
|
-
export declare function OrganizationSwitcher({ authClient, baseUrl, side, className, defaultDialog, hideTrigger, renderUnauthenticated, locked, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }: OrganizationSwitcherProps): import("react").JSX.Element;
|
|
188
|
+
export declare function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl, side, className, defaultDialog, hideTrigger, renderUnauthenticated, locked, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }: OrganizationSwitcherProps): import("react").JSX.Element;
|
|
189
189
|
export {};
|
|
@@ -6,7 +6,7 @@ import { Effect, Schema } from "effect";
|
|
|
6
6
|
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
7
7
|
import { Building2, Check, ChevronsUpDown, Copy, KeyRound, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
|
|
8
8
|
import { createContext, useContext, useEffect, useState, } from "react";
|
|
9
|
-
import { DataTable } from "@/components/ui/data-table";
|
|
9
|
+
import { DataTable, DataTableRelationshipCell, } from "@/components/ui/data-table";
|
|
10
10
|
import { EditingLocaleSwitcher } from "@/components/ui/editing-locale-switcher";
|
|
11
11
|
import { AppBrand } from "@/components/ui/app-brand";
|
|
12
12
|
import { useAppForm } from "@/components/ui/form";
|
|
@@ -14,10 +14,10 @@ import { Badge } from "@/components/ui/badge";
|
|
|
14
14
|
import { Button } from "@/components/ui/button";
|
|
15
15
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
|
16
16
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
17
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
|
|
18
17
|
import { Separator } from "@/components/ui/separator";
|
|
19
18
|
import { OrganizationMetadata, } from "@krak-stack/auth/schema";
|
|
20
19
|
import { authClientApi } from "./auth-client-api";
|
|
20
|
+
import { useKrakstackAuth } from "./auth-provider";
|
|
21
21
|
import { createApiKey } from "./api-key";
|
|
22
22
|
import { useOpenedOnce } from "./hooks";
|
|
23
23
|
import { ExtraUploadedAsset } from "../extra/schema";
|
|
@@ -208,7 +208,7 @@ const userInvitationsAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make
|
|
|
208
208
|
throw new Error(result.error.message ??
|
|
209
209
|
"Could not load organization invitations.");
|
|
210
210
|
}
|
|
211
|
-
return result.data ?? [];
|
|
211
|
+
return (result.data ?? []).filter((invitation) => invitation.status === "pending");
|
|
212
212
|
},
|
|
213
213
|
catch: (error) => error,
|
|
214
214
|
}))));
|
|
@@ -232,7 +232,7 @@ const organizationMembersAtom = Atom.family((authClient) => Atom.family((organiz
|
|
|
232
232
|
}
|
|
233
233
|
return {
|
|
234
234
|
members: membersResult.data?.members ?? [],
|
|
235
|
-
invitations: invitationsResult.data ?? [],
|
|
235
|
+
invitations: (invitationsResult.data ?? []).filter((invitation) => invitation.status === "pending"),
|
|
236
236
|
};
|
|
237
237
|
},
|
|
238
238
|
catch: (error) => error,
|
|
@@ -378,7 +378,12 @@ const organizationMetadataFromForm = async (value, m, uploadImage) => {
|
|
|
378
378
|
}
|
|
379
379
|
return { translations };
|
|
380
380
|
};
|
|
381
|
-
export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", className, defaultDialog = null, hideTrigger = false, renderUnauthenticated, locked = false, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }) {
|
|
381
|
+
export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl, side = "bottom", className, defaultDialog = null, hideTrigger = false, renderUnauthenticated, locked = false, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }) {
|
|
382
|
+
const auth = useKrakstackAuth();
|
|
383
|
+
const authClient = providedAuthClient ?? auth?.authClient;
|
|
384
|
+
if (!authClient) {
|
|
385
|
+
throw new Error("KrakstackAuthProvider is required to use authClient.");
|
|
386
|
+
}
|
|
382
387
|
const labels = organizationSwitcherMessages(messages);
|
|
383
388
|
const m = organizationMessageFns(labels);
|
|
384
389
|
const session = authClient.useSession();
|
|
@@ -402,6 +407,8 @@ export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", cla
|
|
|
402
407
|
onSuccess: () => null,
|
|
403
408
|
});
|
|
404
409
|
const loadingUserInvitations = invitationsResult._tag === "Initial";
|
|
410
|
+
const activeMemberRole = normalizeOrganizationRole(activeOrganization.data?.members.find((member) => member.userId === session.data?.user.id)?.role);
|
|
411
|
+
const canManageApiKeys = activeMemberRole === "owner" || activeMemberRole === "admin";
|
|
405
412
|
const setDialog = (next) => {
|
|
406
413
|
const nextDialog = typeof next === "function" ? next(dialog) : next;
|
|
407
414
|
if (nextDialog === dialog)
|
|
@@ -458,11 +465,11 @@ export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", cla
|
|
|
458
465
|
}, children: _jsx(AppBrand, { to: null, label: display.name, subtitle: display.subtitle, icon: Building2, className: "w-full text-left [&>div:first-child]:size-7", ...(display.image ? { imageSrc: display.image } : {}) }) }, organization.id));
|
|
459
466
|
})) : !locked && !organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: active
|
|
460
467
|
? m.organization_switcher_no_other_organizations()
|
|
461
|
-
: m.organization_switcher_empty() })) : null, _jsx(DropdownMenuSeparator, {}),
|
|
462
|
-
|
|
463
|
-
|
|
468
|
+
: m.organization_switcher_empty() })) : null, !locked ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onClick: openCreate, children: [_jsx(Plus, {}), m.organization_create_title()] }), _jsxs(DropdownMenuItem, { onClick: () => {
|
|
469
|
+
setDialog("invitations");
|
|
470
|
+
}, 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] })] })] })) : null, activeOrganization.data ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onClick: () => {
|
|
464
471
|
void navigator.clipboard.writeText(activeOrganization.data.id);
|
|
465
|
-
}, 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) => {
|
|
472
|
+
}, 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()] }), canManageApiKeys ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })) : null] })) : null] }) })] })), _jsx(Dialog, { open: dialog === "create", onOpenChange: (open) => {
|
|
466
473
|
setDialog((current) => open ? "create" : current === "create" ? null : current);
|
|
467
474
|
}, 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, baseUrl: baseUrl, onCreated: async (organization) => {
|
|
468
475
|
setDialog(null);
|
|
@@ -478,9 +485,9 @@ export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", cla
|
|
|
478
485
|
setDialog((current) => open ? "manage" : current === "manage" ? null : current);
|
|
479
486
|
}, 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) => {
|
|
480
487
|
setDialog((current) => open ? "members" : current === "members" ? null : current);
|
|
481
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-
|
|
488
|
+
}, 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, baseUrl: baseUrl, organization: activeOrganization.data, currentUserId: session.data.user.id, active: dialog === "members" })) : null] }) }), _jsx(Dialog, { open: dialog === "apiKeys" && canManageApiKeys, onOpenChange: (open) => {
|
|
482
489
|
setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
483
|
-
}, 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) => {
|
|
490
|
+
}, 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" && canManageApiKeys })) : null] }) }), _jsx(Dialog, { open: dialog === "invitations" && !locked, onOpenChange: (open) => {
|
|
484
491
|
setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
|
|
485
492
|
}, 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 })] }) })] }));
|
|
486
493
|
}
|
|
@@ -516,7 +523,7 @@ function UserInvitationsManager({ authClient, invitations, loading, error, activ
|
|
|
516
523
|
};
|
|
517
524
|
return (_jsxs("section", { className: "flex flex-col gap-4", children: [error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, actionError ? (_jsx("p", { className: "text-destructive text-sm", children: actionError })) : null, _jsx(DataTable, { columns: userInvitationColumns({
|
|
518
525
|
m,
|
|
519
|
-
}), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_user_invitations_empty(), exportFileName: "organization-invitations.csv", features: { gallery: false }, rowActions: userInvitationRowActions({
|
|
526
|
+
}), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_user_invitations_empty(), exportFileName: "organization-invitations.csv", features: { gallery: false }, searchState: "local", rowActions: userInvitationRowActions({
|
|
520
527
|
m,
|
|
521
528
|
actingInvitationId,
|
|
522
529
|
onAccept: acceptInvitation,
|
|
@@ -749,6 +756,9 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
749
756
|
onSuccess: () => null,
|
|
750
757
|
});
|
|
751
758
|
const loading = membersResult._tag === "Initial";
|
|
759
|
+
const currentMemberRole = normalizeOrganizationRole(members.find((member) => member.userId === currentUserId)?.role);
|
|
760
|
+
const canChangeMemberRoles = currentMemberRole === "owner" || currentMemberRole === "admin";
|
|
761
|
+
const canRemoveMembers = canChangeMemberRoles;
|
|
752
762
|
const inviteForm = useAppForm({
|
|
753
763
|
defaultValues: { email: "", role: "member" },
|
|
754
764
|
onSubmit: async ({ value, formApi }) => {
|
|
@@ -820,24 +830,26 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
820
830
|
}, 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) => ({
|
|
821
831
|
label: organizationRoleLabel(role, m),
|
|
822
832
|
value: role,
|
|
823
|
-
})) })) }), _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({
|
|
833
|
+
})) })) }), _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: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: memberColumns({
|
|
824
834
|
m,
|
|
825
835
|
baseUrl,
|
|
836
|
+
canChangeRoles: canChangeMemberRoles,
|
|
826
837
|
updatingMemberId,
|
|
827
838
|
onRoleChange: updateRole,
|
|
828
|
-
}), data: members, emptyLabel: loading ? m.user_loading() : m.organization_members_empty(), exportFileName: `${organization.slug}-members.csv`, features: { gallery: false }, rowActions: memberRowActions({
|
|
839
|
+
}), data: members, emptyLabel: loading ? m.user_loading() : m.organization_members_empty(), exportFileName: `${organization.slug}-members.csv`, features: { gallery: false }, searchState: "local", rowActions: memberRowActions({
|
|
829
840
|
m,
|
|
841
|
+
canRemoveMembers,
|
|
830
842
|
currentUserId,
|
|
831
843
|
onRemove: removeMember,
|
|
832
|
-
}) }) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_invitations_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invitations_description() })] }), _jsx("div", { className: "min-w-0 overflow-x-auto", children: _jsx(DataTable, { columns: invitationColumns({
|
|
844
|
+
}) }) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_invitations_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invitations_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: invitationColumns({
|
|
833
845
|
m,
|
|
834
|
-
}), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_invitations_empty(), exportFileName: `${organization.slug}-invitations.csv`, features: { gallery: false }, rowActions: invitationRowActions({
|
|
846
|
+
}), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_invitations_empty(), exportFileName: `${organization.slug}-invitations.csv`, features: { gallery: false }, searchState: "local", rowActions: invitationRowActions({
|
|
835
847
|
m,
|
|
836
848
|
cancellingInvitationId,
|
|
837
849
|
onCancel: cancelInvitation,
|
|
838
850
|
}) }) })] })] }));
|
|
839
851
|
}
|
|
840
|
-
const memberColumns = ({ m, baseUrl, updatingMemberId, onRoleChange, }) => [
|
|
852
|
+
const memberColumns = ({ m, baseUrl, canChangeRoles, updatingMemberId, onRoleChange, }) => [
|
|
841
853
|
{
|
|
842
854
|
id: "user",
|
|
843
855
|
header: m.organization_member_user(),
|
|
@@ -851,15 +863,23 @@ const memberColumns = ({ m, baseUrl, updatingMemberId, onRoleChange, }) => [
|
|
|
851
863
|
header: m.organization_member_role(),
|
|
852
864
|
cell: ({ row }) => {
|
|
853
865
|
const member = row.original;
|
|
854
|
-
const
|
|
855
|
-
|
|
866
|
+
const role = normalizeOrganizationRole(member.role);
|
|
867
|
+
if (!canChangeRoles || updatingMemberId === member.id) {
|
|
868
|
+
return _jsx(Badge, { variant: "secondary", children: organizationRoleLabel(role, m) });
|
|
869
|
+
}
|
|
870
|
+
return (_jsx(DataTableRelationshipCell, { emptyLabel: m.organization_member_role(), manageLabel: m.organization_member_role(), options: organizationRoles.map((role) => ({
|
|
856
871
|
label: organizationRoleLabel(role, m),
|
|
857
872
|
value: role,
|
|
858
|
-
})), value:
|
|
859
|
-
|
|
873
|
+
})), value: [
|
|
874
|
+
{
|
|
875
|
+
label: organizationRoleLabel(role, m),
|
|
876
|
+
value: role,
|
|
877
|
+
},
|
|
878
|
+
], onAdd: (value) => {
|
|
879
|
+
if ((value === "owner" || value === "admin" || value === "member")) {
|
|
860
880
|
onRoleChange(member, value);
|
|
861
881
|
}
|
|
862
|
-
}
|
|
882
|
+
} }));
|
|
863
883
|
},
|
|
864
884
|
},
|
|
865
885
|
{
|
|
@@ -868,12 +888,14 @@ const memberColumns = ({ m, baseUrl, updatingMemberId, onRoleChange, }) => [
|
|
|
868
888
|
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(row.original.createdAt) })),
|
|
869
889
|
},
|
|
870
890
|
];
|
|
871
|
-
const memberRowActions = ({ m, currentUserId, onRemove, }) => [
|
|
891
|
+
const memberRowActions = ({ m, canRemoveMembers, currentUserId, onRemove, }) => [
|
|
872
892
|
{
|
|
873
893
|
name: m.organization_member_remove(),
|
|
874
894
|
icon: _jsx(Trash2, {}),
|
|
875
895
|
variant: "destructive",
|
|
876
|
-
visible: (member) =>
|
|
896
|
+
visible: (member) => canRemoveMembers &&
|
|
897
|
+
member.userId !== currentUserId &&
|
|
898
|
+
normalizeOrganizationRole(member.role) !== "owner",
|
|
877
899
|
onClick: onRemove,
|
|
878
900
|
},
|
|
879
901
|
];
|
|
@@ -971,7 +993,7 @@ function OrganizationApiKeyManager({ authClient, organization, active, }) {
|
|
|
971
993
|
event.preventDefault();
|
|
972
994
|
event.stopPropagation();
|
|
973
995
|
createForm.handleSubmit();
|
|
974
|
-
}, 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 }) })] }));
|
|
996
|
+
}, 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 }, searchState: "local", rowActions: apiKeyRowActions({ m, onDelete: deleteKey }) })] }));
|
|
975
997
|
}
|
|
976
998
|
const apiKeyColumns = ({ m, }) => [
|
|
977
999
|
{
|
|
@@ -180,7 +180,7 @@ declare const messages: {
|
|
|
180
180
|
type UserButtonMessageKey = keyof (typeof messages)["en"];
|
|
181
181
|
export type UserButtonMessages = Partial<Record<UserButtonMessageKey, string>>;
|
|
182
182
|
type UserDropdownProps = {
|
|
183
|
-
authClient
|
|
183
|
+
authClient?: AuthUiClient;
|
|
184
184
|
baseUrl?: string | undefined;
|
|
185
185
|
signOutRedirect?: string;
|
|
186
186
|
side?: ComponentProps<typeof DropdownMenuContent>["side"];
|
|
@@ -193,5 +193,5 @@ type UserDropdownProps = {
|
|
|
193
193
|
onDialogChange?: (dialog: UserButtonDialog | null) => void;
|
|
194
194
|
};
|
|
195
195
|
export type UserButtonDialog = "account" | "security" | "apiKeys" | "adminUsers" | "adminOrganizations";
|
|
196
|
-
export declare const UserButton: ({ authClient, baseUrl, signOutRedirect, side, defaultDialog, hideTrigger, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }: UserDropdownProps) => import("react").JSX.Element;
|
|
196
|
+
export declare const UserButton: ({ authClient: providedAuthClient, baseUrl, signOutRedirect, side, defaultDialog, hideTrigger, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }: UserDropdownProps) => import("react").JSX.Element;
|
|
197
197
|
export {};
|
|
@@ -18,18 +18,13 @@ import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldLeg
|
|
|
18
18
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
19
19
|
import { Separator } from "@/components/ui/separator";
|
|
20
20
|
import { authClientApi } from "./auth-client-api";
|
|
21
|
-
import {
|
|
21
|
+
import { useKrakstackAuth } from "./auth-provider";
|
|
22
22
|
import { createApiKey } from "./api-key";
|
|
23
23
|
import { useOpenedOnce } from "./hooks";
|
|
24
24
|
import { ExtraUploadedAsset } from "../extra/schema";
|
|
25
25
|
import { assetPath, assetUrl } from "./utils";
|
|
26
26
|
import { AdminOrganizationsTable } from "./admin-organizations";
|
|
27
27
|
import { AdminUsersTable } from "./admin-users";
|
|
28
|
-
const defaultAdminTableSearch = {
|
|
29
|
-
page: 0,
|
|
30
|
-
pageSize: 10,
|
|
31
|
-
globalFilter: "",
|
|
32
|
-
};
|
|
33
28
|
const messages = {
|
|
34
29
|
en: {
|
|
35
30
|
api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
|
|
@@ -268,20 +263,19 @@ const userApiKeysAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make(Eff
|
|
|
268
263
|
catch: (error) => error,
|
|
269
264
|
}))));
|
|
270
265
|
const emptyApiKeysAtom = Atom.make(Effect.succeed([]));
|
|
271
|
-
export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side = "bottom", defaultDialog = null, hideTrigger = false, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }) => {
|
|
266
|
+
export const UserButton = ({ authClient: providedAuthClient, baseUrl, signOutRedirect = "/", side = "bottom", defaultDialog = null, hideTrigger = false, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }) => {
|
|
267
|
+
const auth = useKrakstackAuth();
|
|
268
|
+
const authClient = providedAuthClient ?? auth?.authClient;
|
|
269
|
+
if (!authClient) {
|
|
270
|
+
throw new Error("KrakstackAuthProvider is required to use authClient.");
|
|
271
|
+
}
|
|
272
272
|
const labels = userButtonMessages(messages);
|
|
273
273
|
const m = userButtonMessageFns(labels);
|
|
274
|
-
const projectConfig =
|
|
274
|
+
const projectConfig = auth?.projectConfig ?? null;
|
|
275
275
|
const navigate = useNavigate();
|
|
276
276
|
const currentSiteHref = useRouterState({
|
|
277
277
|
select: (state) => `${import.meta.env.VITE_SITE_URL}${state.location.href}`,
|
|
278
278
|
});
|
|
279
|
-
const adminTableSearch = useRouterState({
|
|
280
|
-
select: (state) => ({
|
|
281
|
-
...defaultAdminTableSearch,
|
|
282
|
-
...state.location.search,
|
|
283
|
-
}),
|
|
284
|
-
});
|
|
285
279
|
const { data: session, isPending, refetch } = authClient.useSession();
|
|
286
280
|
const [uncontrolledDialog, setUncontrolledDialog] = useState(defaultDialog);
|
|
287
281
|
const [isStoppingImpersonation, setIsStoppingImpersonation] = useState(false);
|
|
@@ -383,13 +377,13 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
|
|
|
383
377
|
setSettingsDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
384
378
|
}, 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, active: settingsDialog === "apiKeys", permissions: apiKeyPermissions ?? {} })] }) }), isAdmin ? (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: settingsDialog === "adminUsers", onOpenChange: (open) => {
|
|
385
379
|
setSettingsDialog((current) => open ? "adminUsers" : current === "adminUsers" ? null : current);
|
|
386
|
-
}, children: _jsxs(DialogContent, { className: "flex h-[85vh] flex-col overflow-y-auto sm:max-w-6xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_button_admin_users() }), _jsx(DialogDescription, { children: m.user_button_admin_users_description() })] }), _jsx(Separator, {}), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(AdminUsersTable, {
|
|
380
|
+
}, children: _jsxs(DialogContent, { className: "flex h-[85vh] flex-col overflow-y-auto sm:max-w-6xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_button_admin_users() }), _jsx(DialogDescription, { children: m.user_button_admin_users_description() })] }), _jsx(Separator, {}), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(AdminUsersTable, {}) })] }) }), _jsx(Dialog, { open: settingsDialog === "adminOrganizations", onOpenChange: (open) => {
|
|
387
381
|
setSettingsDialog((current) => open
|
|
388
382
|
? "adminOrganizations"
|
|
389
383
|
: current === "adminOrganizations"
|
|
390
384
|
? null
|
|
391
385
|
: current);
|
|
392
|
-
}, children: _jsxs(DialogContent, { className: "flex h-[85vh] flex-col overflow-y-auto sm:max-w-6xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_button_admin_organizations() }), _jsx(DialogDescription, { children: m.user_button_admin_organizations_description() })] }), _jsx(Separator, {}), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(AdminOrganizationsTable, {
|
|
386
|
+
}, children: _jsxs(DialogContent, { className: "flex h-[85vh] flex-col overflow-y-auto sm:max-w-6xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_button_admin_organizations() }), _jsx(DialogDescription, { children: m.user_button_admin_organizations_description() })] }), _jsx(Separator, {}), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(AdminOrganizationsTable, {}) })] }) })] })) : null] }));
|
|
393
387
|
};
|
|
394
388
|
function ConnectedAccounts({ authClient, baseUrl, accountCache, googleEnabled, currentSiteHref, navigate, }) {
|
|
395
389
|
const m = useUserButtonMessages();
|
|
@@ -767,7 +761,7 @@ function ApiKeyManager({ authClient, active, permissions = {}, }) {
|
|
|
767
761
|
event.preventDefault();
|
|
768
762
|
event.stopPropagation();
|
|
769
763
|
createForm.handleSubmit();
|
|
770
|
-
}, 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 })) }), permissionOptions.length > 0 ? (_jsxs(FieldSet, { children: [_jsx(FieldLegend, { children: m.user_api_key_permissions() }), _jsx(FieldDescription, { children: m.user_api_key_permissions_description() }), _jsx(FieldGroup, { "data-slot": "checkbox-group", className: "gap-3", children: permissionOptions.map((permission) => (_jsxs(Field, { orientation: "horizontal", children: [_jsx(Checkbox, { id: permission.id, checked: selectedPermissions[permission.id] ?? false, onCheckedChange: (checked) => togglePermission(permission.id, checked) }), _jsx(FieldContent, { children: _jsx(FieldLabel, { htmlFor: permission.id, children: permission.id }) })] }, permission.id))) })] })) : null, _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() }), _jsxs("div", { className: "grid min-w-0 gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center", children: [_jsx("code", { className: "bg-muted block max-w-full overflow-x-auto rounded-md p-3 text-sm whitespace-nowrap", children: createdKey }), _jsxs(Button, { type: "button", variant: "outline", onClick: copyCreatedKey, className: "self-start sm:self-auto", children: [copiedKey ? _jsx(Check, {}) : _jsx(Copy, {}), copiedKey ? m.user_api_key_copied() : m.user_api_key_copy()] })] })] })) : 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: m.user_api_keys_export_file_name(), features: { gallery: false }, rowActions: apiKeyRowActions({ m, onDelete: deleteKey }) })] }));
|
|
764
|
+
}, 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 })) }), permissionOptions.length > 0 ? (_jsxs(FieldSet, { children: [_jsx(FieldLegend, { children: m.user_api_key_permissions() }), _jsx(FieldDescription, { children: m.user_api_key_permissions_description() }), _jsx(FieldGroup, { "data-slot": "checkbox-group", className: "gap-3", children: permissionOptions.map((permission) => (_jsxs(Field, { orientation: "horizontal", children: [_jsx(Checkbox, { id: permission.id, checked: selectedPermissions[permission.id] ?? false, onCheckedChange: (checked) => togglePermission(permission.id, checked) }), _jsx(FieldContent, { children: _jsx(FieldLabel, { htmlFor: permission.id, children: permission.id }) })] }, permission.id))) })] })) : null, _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() }), _jsxs("div", { className: "grid min-w-0 gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center", children: [_jsx("code", { className: "bg-muted block max-w-full overflow-x-auto rounded-md p-3 text-sm whitespace-nowrap", children: createdKey }), _jsxs(Button, { type: "button", variant: "outline", onClick: copyCreatedKey, className: "self-start sm:self-auto", children: [copiedKey ? _jsx(Check, {}) : _jsx(Copy, {}), copiedKey ? m.user_api_key_copied() : m.user_api_key_copy()] })] })] })) : 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: m.user_api_keys_export_file_name(), features: { gallery: false }, searchState: "local", rowActions: apiKeyRowActions({ m, onDelete: deleteKey }) })] }));
|
|
771
765
|
}
|
|
772
766
|
const apiKeyColumns = ({ m, }) => [
|
|
773
767
|
{
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { AuthClientApi, AuthServiceApi } from "./api";
|
|
|
4
4
|
export { AuthService, type AuthServiceLayerOptions } from "./service";
|
|
5
5
|
export { AuthClientConfig } from "./config";
|
|
6
6
|
export { proxyAuthRequest } from "./server/proxy";
|
|
7
|
-
export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, type AuthUiClient, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type UserButtonDialog, useAdminUsersTotal, } from "./components";
|
|
7
|
+
export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, type AuthUiClient, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type UserButtonDialog, useAuthClient, useAdminUsersTotal, } from "./components";
|
|
8
8
|
export * as BetterAuth from "./better-auth/api.group";
|
|
9
9
|
export * as Extra from "./extra/api.group";
|
|
10
10
|
export * as Server from "./server";
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export { AuthClientApi, AuthServiceApi } from "./api";
|
|
|
4
4
|
export { AuthService } from "./service";
|
|
5
5
|
export { AuthClientConfig } from "./config";
|
|
6
6
|
export { proxyAuthRequest } from "./server/proxy";
|
|
7
|
-
export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, useAdminUsersTotal, } from "./components";
|
|
7
|
+
export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, useAuthClient, useAdminUsersTotal, } from "./components";
|
|
8
8
|
export * as BetterAuth from "./better-auth/api.group";
|
|
9
9
|
export * as Extra from "./extra/api.group";
|
|
10
10
|
export * as Server from "./server";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.44",
|
|
4
4
|
"description": "Effect HttpApi clients and schemas for KrakStack Auth.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -62,7 +62,9 @@
|
|
|
62
62
|
"prepack": "bun run build",
|
|
63
63
|
"type:check": "tsc -p tsconfig.json --noEmit"
|
|
64
64
|
},
|
|
65
|
-
"dependencies": {
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"react-qr-code": "^2.2.0"
|
|
67
|
+
},
|
|
66
68
|
"peerDependencies": {
|
|
67
69
|
"@better-auth/api-key": "^1.6.14",
|
|
68
70
|
"@tanstack/react-router": "^1.170.15",
|
|
@@ -71,7 +73,6 @@
|
|
|
71
73
|
"effect": "^4.0.0-beta.78",
|
|
72
74
|
"input-otp": "^1.4.2",
|
|
73
75
|
"lucide-react": "^1.17.0",
|
|
74
|
-
"react": "^19.2.7"
|
|
75
|
-
"react-qr-code": "^2.1.1"
|
|
76
|
+
"react": "^19.2.7"
|
|
76
77
|
}
|
|
77
78
|
}
|