@krak-stack/auth 0.1.40 → 0.1.42
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 +197 -0
- package/dist/admin/api.group.js +159 -0
- package/dist/admin/schema.d.ts +128 -0
- package/dist/admin/schema.js +190 -0
- package/dist/api.d.ts +264 -11
- package/dist/api.js +14 -5
- package/dist/better-auth/{index.d.ts → api.group.d.ts} +6 -8
- package/dist/better-auth/{api.js → api.group.js} +2 -4
- package/dist/components/admin-organization-form.d.ts +3 -3
- package/dist/components/admin-organization-form.js +9 -19
- package/dist/components/admin-organizations.js +16 -12
- package/dist/components/admin-users.d.ts +1 -1
- package/dist/components/admin-users.js +35 -18
- package/dist/components/{auth-api-client.d.ts → auth-client-api.d.ts} +179 -209
- package/dist/components/auth-client-api.js +29 -0
- package/dist/components/auth-forms.js +3 -3
- package/dist/components/auth-provider.js +2 -2
- package/dist/components/organization-switcher.js +15 -16
- package/dist/components/user-button.js +3 -3
- package/dist/components/utils.d.ts +11 -0
- package/dist/components/utils.js +24 -0
- package/dist/extra/api.group.d.ts +68 -0
- package/dist/extra/{api.js → api.group.js} +5 -17
- package/dist/index.d.ts +5 -3
- package/dist/index.js +5 -3
- package/dist/query.d.ts +49 -0
- package/dist/query.js +114 -0
- package/dist/server/{api.d.ts → api.group.d.ts} +0 -196
- package/dist/server/{api.js → api.group.js} +1 -6
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +2 -1
- package/dist/service.d.ts +12 -24
- package/dist/service.js +2 -2
- package/package.json +13 -5
- package/dist/better-auth/api.d.ts +0 -55
- package/dist/better-auth/index.js +0 -12
- package/dist/components/auth-api-client.js +0 -29
- package/dist/extra/api.d.ts +0 -139
- package/dist/extra/index.d.ts +0 -76
- package/dist/extra/index.js +0 -14
|
@@ -11,10 +11,9 @@ import { ErrorMessage } from "@/components/ui/form";
|
|
|
11
11
|
import { AppBrand } from "@/components/ui/app-brand";
|
|
12
12
|
import { Badge } from "@/components/ui/badge";
|
|
13
13
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog";
|
|
14
|
-
import {
|
|
15
|
-
import { assetUrl } from "@/lib/assets";
|
|
16
|
-
import { AdminApiClient } from "@/lib/admin-api-client";
|
|
14
|
+
import { authClientApi } from "./auth-client-api";
|
|
17
15
|
import { useKrakstackAuth } from "./auth-provider";
|
|
16
|
+
import { assetUrl } from "./utils";
|
|
18
17
|
const defaultMessages = {
|
|
19
18
|
en: {
|
|
20
19
|
admin_action_ban: "Ban",
|
|
@@ -80,9 +79,9 @@ const adminUsersQuery = (search, projectId) => {
|
|
|
80
79
|
key: JSON.stringify(query),
|
|
81
80
|
};
|
|
82
81
|
};
|
|
83
|
-
const usersAtom = Atom.family(({ projectId, reloadKey, search, }) => {
|
|
82
|
+
const usersAtom = Atom.family(({ baseUrl, projectId, reloadKey, search, }) => {
|
|
84
83
|
const request = adminUsersQuery(search, projectId);
|
|
85
|
-
return
|
|
84
|
+
return authClientApi(baseUrl).query("admin", "listUsers", {
|
|
86
85
|
query: request.query,
|
|
87
86
|
timeToLive: "1 minute",
|
|
88
87
|
reactivityKeys: [
|
|
@@ -92,17 +91,17 @@ const usersAtom = Atom.family(({ projectId, reloadKey, search, }) => {
|
|
|
92
91
|
serializationKey: `admin-users:${reloadKey}:${request.key}`,
|
|
93
92
|
});
|
|
94
93
|
});
|
|
95
|
-
const banUser = async (userId, m) => {
|
|
94
|
+
const banUser = async (authClient, userId, m) => {
|
|
96
95
|
const result = await authClient.admin.banUser({ userId });
|
|
97
96
|
if (result.error)
|
|
98
97
|
throw new Error(result.error.message ?? m.admin_error_ban);
|
|
99
98
|
};
|
|
100
|
-
const unbanUser = async (userId, m) => {
|
|
99
|
+
const unbanUser = async (authClient, userId, m) => {
|
|
101
100
|
const result = await authClient.admin.unbanUser({ userId });
|
|
102
101
|
if (result.error)
|
|
103
102
|
throw new Error(result.error.message ?? m.admin_error_unban);
|
|
104
103
|
};
|
|
105
|
-
const impersonateUser = async (userId, m) => {
|
|
104
|
+
const impersonateUser = async (authClient, userId, m) => {
|
|
106
105
|
const result = await authClient.admin.impersonateUser({ userId });
|
|
107
106
|
if (result.error)
|
|
108
107
|
throw new Error(result.error.message ?? m.admin_error_impersonate);
|
|
@@ -111,11 +110,18 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
|
|
|
111
110
|
const navigate = useNavigate();
|
|
112
111
|
const auth = useKrakstackAuth();
|
|
113
112
|
const m = labels(auth?.locale ?? "en");
|
|
113
|
+
const authClient = auth?.authClient;
|
|
114
|
+
const baseUrl = auth?.baseUrl;
|
|
114
115
|
const projectId = auth?.projectId;
|
|
115
116
|
const [impersonatingUserId, setImpersonatingUserId] = useState(null);
|
|
116
117
|
const [impersonateError, setImpersonateError] = useState("");
|
|
117
118
|
const [refreshKey, setRefreshKey] = useState(0);
|
|
118
|
-
const result = useAtomValue(usersAtom({
|
|
119
|
+
const result = useAtomValue(usersAtom({
|
|
120
|
+
baseUrl,
|
|
121
|
+
projectId,
|
|
122
|
+
search,
|
|
123
|
+
reloadKey: reloadKey + refreshKey,
|
|
124
|
+
}));
|
|
119
125
|
const [banningUser, setBanningUser] = useState(null);
|
|
120
126
|
const [unbanningUser, setUnbanningUser] = useState(null);
|
|
121
127
|
const users = AsyncResult.match(result, {
|
|
@@ -146,7 +152,9 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
|
|
|
146
152
|
setImpersonateError("");
|
|
147
153
|
setImpersonatingUserId(user.id);
|
|
148
154
|
try {
|
|
149
|
-
|
|
155
|
+
if (!authClient)
|
|
156
|
+
throw new Error(m.admin_error_access_required);
|
|
157
|
+
await impersonateUser(authClient, user.id, m);
|
|
150
158
|
await navigate({ to: "/" });
|
|
151
159
|
}
|
|
152
160
|
catch (cause) {
|
|
@@ -173,11 +181,16 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
|
|
|
173
181
|
onClick: (user) => setUnbanningUser(user),
|
|
174
182
|
visible: (user) => !!user.banned,
|
|
175
183
|
},
|
|
176
|
-
] }), banningUser ? (_jsx(BanUserDialog, { labels: m, user: banningUser, onBanned: () => setRefreshKey((current) => current + 1), onClose: () => setBanningUser(null) })) : null, unbanningUser ? (_jsx(UnbanUserDialog, { labels: m, user: unbanningUser, onUnbanned: () => setRefreshKey((current) => current + 1), onClose: () => setUnbanningUser(null) })) : null] }));
|
|
184
|
+
] }), banningUser ? (_jsx(BanUserDialog, { labels: m, authClient: authClient, user: banningUser, onBanned: () => setRefreshKey((current) => current + 1), onClose: () => setBanningUser(null) })) : null, unbanningUser ? (_jsx(UnbanUserDialog, { labels: m, authClient: authClient, user: unbanningUser, onUnbanned: () => setRefreshKey((current) => current + 1), onClose: () => setUnbanningUser(null) })) : null] }));
|
|
177
185
|
}
|
|
178
186
|
export function useAdminUsersTotal(search) {
|
|
179
|
-
const
|
|
180
|
-
const result = useAtomValue(usersAtom({
|
|
187
|
+
const auth = useKrakstackAuth();
|
|
188
|
+
const result = useAtomValue(usersAtom({
|
|
189
|
+
baseUrl: auth?.baseUrl,
|
|
190
|
+
projectId: auth?.projectId,
|
|
191
|
+
search,
|
|
192
|
+
reloadKey: 0,
|
|
193
|
+
}));
|
|
181
194
|
return AsyncResult.match(result, {
|
|
182
195
|
onInitial: () => 0,
|
|
183
196
|
onFailure: () => 0,
|
|
@@ -189,7 +202,7 @@ const userColumns = (m) => [
|
|
|
189
202
|
accessorKey: "email",
|
|
190
203
|
header: m.admin_column_user,
|
|
191
204
|
cell: ({ row }) => {
|
|
192
|
-
const image = assetUrl(row.original.image
|
|
205
|
+
const image = assetUrl(row.original.image);
|
|
193
206
|
return (_jsx(AppBrand, { to: null, label: row.original.email, subtitle: row.original.name, icon: UserIcon, className: "min-w-48", ...(image ? { imageSrc: image } : {}) }));
|
|
194
207
|
},
|
|
195
208
|
},
|
|
@@ -219,7 +232,7 @@ const userColumns = (m) => [
|
|
|
219
232
|
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: new Date(row.original.createdAt).toLocaleDateString() })),
|
|
220
233
|
},
|
|
221
234
|
];
|
|
222
|
-
function BanUserDialog({ labels: m, user, onBanned, onClose, }) {
|
|
235
|
+
function BanUserDialog({ labels: m, authClient, user, onBanned, onClose, }) {
|
|
223
236
|
const [isPending, setIsPending] = useState(false);
|
|
224
237
|
const [error, setError] = useState("");
|
|
225
238
|
return (_jsx(AlertDialog, { open: true, onOpenChange: (open) => !open && onClose(), children: _jsxs(AlertDialogContent, { children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: m.admin_ban_title }), _jsx(AlertDialogDescription, { children: text(m.admin_ban_description, {
|
|
@@ -229,7 +242,9 @@ function BanUserDialog({ labels: m, user, onBanned, onClose, }) {
|
|
|
229
242
|
setError("");
|
|
230
243
|
setIsPending(true);
|
|
231
244
|
try {
|
|
232
|
-
|
|
245
|
+
if (!authClient)
|
|
246
|
+
throw new Error(m.admin_error_access_required);
|
|
247
|
+
await banUser(authClient, user.id, m);
|
|
233
248
|
onBanned();
|
|
234
249
|
onClose();
|
|
235
250
|
}
|
|
@@ -241,7 +256,7 @@ function BanUserDialog({ labels: m, user, onBanned, onClose, }) {
|
|
|
241
256
|
}
|
|
242
257
|
}, disabled: isPending, children: [isPending ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, m.admin_action_ban] })] })] }) }));
|
|
243
258
|
}
|
|
244
|
-
function UnbanUserDialog({ labels: m, user, onUnbanned, onClose, }) {
|
|
259
|
+
function UnbanUserDialog({ labels: m, authClient, user, onUnbanned, onClose, }) {
|
|
245
260
|
const [isPending, setIsPending] = useState(false);
|
|
246
261
|
const [error, setError] = useState("");
|
|
247
262
|
return (_jsx(AlertDialog, { open: true, onOpenChange: (open) => !open && onClose(), children: _jsxs(AlertDialogContent, { children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: m.admin_unban_title }), _jsx(AlertDialogDescription, { children: text(m.admin_unban_description, {
|
|
@@ -251,7 +266,9 @@ function UnbanUserDialog({ labels: m, user, onUnbanned, onClose, }) {
|
|
|
251
266
|
setError("");
|
|
252
267
|
setIsPending(true);
|
|
253
268
|
try {
|
|
254
|
-
|
|
269
|
+
if (!authClient)
|
|
270
|
+
throw new Error(m.admin_error_access_required);
|
|
271
|
+
await unbanUser(authClient, user.id, m);
|
|
255
272
|
onUnbanned();
|
|
256
273
|
onClose();
|
|
257
274
|
}
|