@strapi-community/plugin-better-auth-dashboard 1.0.0-beta.1 → 1.0.0-beta.2
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/Avatar-CdT7eBCh.js +39 -0
- package/dist/admin/Avatar-zlMTAZh3.mjs +40 -0
- package/dist/admin/{Root-2FMy-qQg.mjs → Root-CgVBJuoM.mjs} +12 -4
- package/dist/admin/{Root-DDi0mtve.js → Root-CsiOnzlB.js} +12 -4
- package/dist/admin/cs-C_jSgeON.js +416 -0
- package/dist/admin/cs-wtnknvBC.mjs +416 -0
- package/dist/admin/de-Cg5HyoCY.js +416 -0
- package/dist/admin/de-DnnVdUxk.mjs +416 -0
- package/dist/admin/en-B3utEgMT.mjs +416 -0
- package/dist/admin/en-Cz1IJEvp.js +416 -0
- package/dist/admin/es-CGA0Tslt.js +416 -0
- package/dist/admin/es-RoCEriJL.mjs +416 -0
- package/dist/admin/fr-Ca74t21t.js +416 -0
- package/dist/admin/fr-CtmuSfiQ.mjs +416 -0
- package/dist/admin/{index-BHfYu0uA.js → index-BCBu-0nr.js} +65 -10
- package/dist/admin/{index-D9CiI8Yr.mjs → index-BI2WIsds.mjs} +73 -18
- package/dist/admin/index-CPSoAbZt.js +2321 -0
- package/dist/admin/index-D9ttdrT3.js +2716 -0
- package/dist/admin/index-DQdn5s8q.js +1184 -0
- package/dist/admin/index-DvfwvCj0.mjs +1182 -0
- package/dist/admin/index-VyHXoQ6p.mjs +2321 -0
- package/dist/admin/index-gFqHlMLP.mjs +2716 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/it-BAB9hDdp.mjs +416 -0
- package/dist/admin/it-dYT2_ERV.js +416 -0
- package/dist/admin/nl-CVqSbUU9.js +416 -0
- package/dist/admin/nl-CYv26PHv.mjs +416 -0
- package/dist/admin/pl-Bc0cS2mD.mjs +416 -0
- package/dist/admin/pl-HYF4BxRv.js +416 -0
- package/dist/admin/pt-DDUGyLtb.js +416 -0
- package/dist/admin/pt-DZyyK3EG.mjs +416 -0
- package/dist/admin/{useModelSchema-CqOTI7P1.js → useModelSchema-BogQah8f.js} +309 -287
- package/dist/admin/{useModelSchema-B2tmzlwQ.mjs → useModelSchema-C6bxNjW4.mjs} +320 -298
- package/dist/server/index.js +15 -15
- package/dist/server/index.mjs +15 -15
- package/package.json +4 -4
- package/dist/admin/Avatar-Cvk89aMx.js +0 -67
- package/dist/admin/Avatar-DNczJU0i.mjs +0 -66
- package/dist/admin/index-BQi_BUi6.mjs +0 -1968
- package/dist/admin/index-BV-4M_Fp.js +0 -1970
- package/dist/admin/index-CANDPUGD.mjs +0 -1215
- package/dist/admin/index-CqR8WpOa.js +0 -1217
- package/dist/admin/index-D6ktNZcj.js +0 -1685
- package/dist/admin/index-DszX3ibA.mjs +0 -1683
|
@@ -1,1968 +0,0 @@
|
|
|
1
|
-
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Button, Flex, Field, TextInput, Checkbox, Box, Typography, Badge, Alert, Tabs, Grid, Loader, IconButton, Modal, SearchForm, Searchbar } from "@strapi/design-system";
|
|
3
|
-
import { Trash, Plus, Pencil } from "@strapi/icons";
|
|
4
|
-
import { useNotification, useFetchClient, Page, useRBAC } from "@strapi/strapi/admin";
|
|
5
|
-
import { useState } from "react";
|
|
6
|
-
import { useQuery, useQueryClient, useMutation } from "react-query";
|
|
7
|
-
import styled, { keyframes } from "styled-components";
|
|
8
|
-
import { c as client, d as getAuthHeaders, u as useDashConfig, b as PERMISSIONS, P as PLUGIN_ID, h as hasPlugin } from "./index-D9CiI8Yr.mjs";
|
|
9
|
-
import { A as Avatar } from "./Avatar-DNczJU0i.mjs";
|
|
10
|
-
import { D as Drawer, F as FormSection, S as SectionLabel, M as MediaPickerField, u as useModelSchema, w as withContext, E as EditLayout, C as CustomFieldsSection, a as EditSidebar, b as MetaItem, c as MetaKey, d as MonoChip, e as MetaVal, f as EditViewSidePanels, A as AccountRow, P as ProviderBadge, g as DangerRow, W as WarnCard, h as PreviewPill, R as RoleBadge, i as ConfirmDialog } from "./useModelSchema-B2tmzlwQ.mjs";
|
|
11
|
-
function useUsers(options = {}) {
|
|
12
|
-
const { limit = 25, offset = 0, search } = options;
|
|
13
|
-
return useQuery({
|
|
14
|
-
queryKey: ["dash-users", limit, offset, search],
|
|
15
|
-
queryFn: async () => {
|
|
16
|
-
const whereClause = search ? JSON.stringify([
|
|
17
|
-
{
|
|
18
|
-
field: "email",
|
|
19
|
-
operator: "contains",
|
|
20
|
-
value: search,
|
|
21
|
-
connector: "OR"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
field: "name",
|
|
25
|
-
operator: "contains",
|
|
26
|
-
value: search,
|
|
27
|
-
connector: "OR"
|
|
28
|
-
}
|
|
29
|
-
]) : void 0;
|
|
30
|
-
const result = await client.dash.listUsers({
|
|
31
|
-
query: {
|
|
32
|
-
limit,
|
|
33
|
-
offset,
|
|
34
|
-
sortBy: "createdAt",
|
|
35
|
-
sortOrder: "desc",
|
|
36
|
-
...whereClause ? { where: whereClause } : {}
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
if (result.error) {
|
|
40
|
-
throw new Error(result.error.message ?? "Failed to load users");
|
|
41
|
-
}
|
|
42
|
-
return result.data;
|
|
43
|
-
},
|
|
44
|
-
keepPreviousData: true
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
function CreateUserDialog({ onClose }) {
|
|
48
|
-
const qc = useQueryClient();
|
|
49
|
-
const { toggleNotification } = useNotification();
|
|
50
|
-
const [name, setName] = useState("");
|
|
51
|
-
const [email, setEmail] = useState("");
|
|
52
|
-
const [image, setImage] = useState("");
|
|
53
|
-
const [password, setPassword] = useState("");
|
|
54
|
-
const [generatePassword, setGeneratePassword] = useState(false);
|
|
55
|
-
const [emailVerified, setEmailVerified] = useState(false);
|
|
56
|
-
const [sendVerificationEmail, setSendVerificationEmail] = useState(false);
|
|
57
|
-
const createMutation = useMutation({
|
|
58
|
-
mutationFn: async () => {
|
|
59
|
-
const result = await client.dash.createUser({
|
|
60
|
-
name,
|
|
61
|
-
email,
|
|
62
|
-
...image ? { image } : {},
|
|
63
|
-
...generatePassword ? { generatePassword: true } : password ? { password } : {},
|
|
64
|
-
emailVerified,
|
|
65
|
-
sendVerificationEmail
|
|
66
|
-
});
|
|
67
|
-
if (result.error)
|
|
68
|
-
throw new Error(result.error.message ?? "Create failed");
|
|
69
|
-
return result.data;
|
|
70
|
-
},
|
|
71
|
-
onSuccess: () => {
|
|
72
|
-
qc.invalidateQueries({ queryKey: ["dash-users"] });
|
|
73
|
-
qc.invalidateQueries({ queryKey: ["dash-user-stats"] });
|
|
74
|
-
toggleNotification({
|
|
75
|
-
type: "success",
|
|
76
|
-
message: "User created successfully"
|
|
77
|
-
});
|
|
78
|
-
onClose();
|
|
79
|
-
},
|
|
80
|
-
onError: (err) => {
|
|
81
|
-
toggleNotification({
|
|
82
|
-
type: "danger",
|
|
83
|
-
message: err.message ?? "Failed to create user"
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
const footer = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
88
|
-
/* @__PURE__ */ jsx(Button, { variant: "tertiary", onClick: onClose, children: "Cancel" }),
|
|
89
|
-
/* @__PURE__ */ jsx(
|
|
90
|
-
Button,
|
|
91
|
-
{
|
|
92
|
-
loading: createMutation.isLoading,
|
|
93
|
-
onClick: () => createMutation.mutate(),
|
|
94
|
-
disabled: !name || !email,
|
|
95
|
-
"data-testid": "create-user-submit",
|
|
96
|
-
children: "Create user"
|
|
97
|
-
}
|
|
98
|
-
)
|
|
99
|
-
] });
|
|
100
|
-
return /* @__PURE__ */ jsx(
|
|
101
|
-
Drawer,
|
|
102
|
-
{
|
|
103
|
-
title: "Create user",
|
|
104
|
-
footer,
|
|
105
|
-
onClose,
|
|
106
|
-
"data-testid": "create-user-drawer",
|
|
107
|
-
children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 5, children: [
|
|
108
|
-
/* @__PURE__ */ jsxs(FormSection, { children: [
|
|
109
|
-
/* @__PURE__ */ jsx(SectionLabel, { children: "Personal information" }),
|
|
110
|
-
/* @__PURE__ */ jsxs(Field.Root, { style: { width: "100%" }, required: true, children: [
|
|
111
|
-
/* @__PURE__ */ jsx(Field.Label, { children: "Full name" }),
|
|
112
|
-
/* @__PURE__ */ jsx(
|
|
113
|
-
TextInput,
|
|
114
|
-
{
|
|
115
|
-
name: "name",
|
|
116
|
-
value: name,
|
|
117
|
-
onChange: (e) => setName(e.target.value),
|
|
118
|
-
placeholder: "Jane Smith",
|
|
119
|
-
"data-testid": "new-user-name"
|
|
120
|
-
}
|
|
121
|
-
)
|
|
122
|
-
] }),
|
|
123
|
-
/* @__PURE__ */ jsxs(Field.Root, { style: { width: "100%" }, required: true, children: [
|
|
124
|
-
/* @__PURE__ */ jsx(Field.Label, { children: "Email address" }),
|
|
125
|
-
/* @__PURE__ */ jsx(
|
|
126
|
-
TextInput,
|
|
127
|
-
{
|
|
128
|
-
name: "email",
|
|
129
|
-
type: "email",
|
|
130
|
-
value: email,
|
|
131
|
-
onChange: (e) => setEmail(e.target.value),
|
|
132
|
-
placeholder: "jane@example.com",
|
|
133
|
-
"data-testid": "new-user-email"
|
|
134
|
-
}
|
|
135
|
-
)
|
|
136
|
-
] }),
|
|
137
|
-
/* @__PURE__ */ jsx(
|
|
138
|
-
MediaPickerField,
|
|
139
|
-
{
|
|
140
|
-
label: "Avatar URL",
|
|
141
|
-
name: "image",
|
|
142
|
-
value: image,
|
|
143
|
-
onChange: setImage,
|
|
144
|
-
placeholder: "https://example.com/avatar.png",
|
|
145
|
-
hint: "Optional — publicly accessible image URL"
|
|
146
|
-
}
|
|
147
|
-
)
|
|
148
|
-
] }),
|
|
149
|
-
/* @__PURE__ */ jsxs(FormSection, { children: [
|
|
150
|
-
/* @__PURE__ */ jsx(SectionLabel, { children: "Password" }),
|
|
151
|
-
/* @__PURE__ */ jsx(
|
|
152
|
-
Checkbox,
|
|
153
|
-
{
|
|
154
|
-
name: "generatePassword",
|
|
155
|
-
checked: generatePassword,
|
|
156
|
-
onCheckedChange: (checked) => {
|
|
157
|
-
setGeneratePassword(checked);
|
|
158
|
-
if (checked) setPassword("");
|
|
159
|
-
},
|
|
160
|
-
children: "Generate a random password"
|
|
161
|
-
}
|
|
162
|
-
),
|
|
163
|
-
!generatePassword && /* @__PURE__ */ jsxs(Field.Root, { style: { width: "100%" }, children: [
|
|
164
|
-
/* @__PURE__ */ jsx(Field.Label, { children: "Password" }),
|
|
165
|
-
/* @__PURE__ */ jsx(
|
|
166
|
-
TextInput,
|
|
167
|
-
{
|
|
168
|
-
name: "password",
|
|
169
|
-
type: "password",
|
|
170
|
-
value: password,
|
|
171
|
-
onChange: (e) => setPassword(e.target.value),
|
|
172
|
-
placeholder: "Leave blank for a passwordless account"
|
|
173
|
-
}
|
|
174
|
-
)
|
|
175
|
-
] })
|
|
176
|
-
] }),
|
|
177
|
-
/* @__PURE__ */ jsxs(FormSection, { children: [
|
|
178
|
-
/* @__PURE__ */ jsx(SectionLabel, { children: "Email verification" }),
|
|
179
|
-
/* @__PURE__ */ jsx(
|
|
180
|
-
Checkbox,
|
|
181
|
-
{
|
|
182
|
-
name: "emailVerified",
|
|
183
|
-
checked: emailVerified,
|
|
184
|
-
onCheckedChange: (checked) => {
|
|
185
|
-
setEmailVerified(checked);
|
|
186
|
-
if (checked) setSendVerificationEmail(false);
|
|
187
|
-
},
|
|
188
|
-
children: "Mark email as already verified"
|
|
189
|
-
}
|
|
190
|
-
),
|
|
191
|
-
!emailVerified && /* @__PURE__ */ jsx(
|
|
192
|
-
Checkbox,
|
|
193
|
-
{
|
|
194
|
-
name: "sendVerificationEmail",
|
|
195
|
-
checked: sendVerificationEmail,
|
|
196
|
-
onCheckedChange: (checked) => setSendVerificationEmail(checked),
|
|
197
|
-
children: "Send a verification email to the user"
|
|
198
|
-
}
|
|
199
|
-
),
|
|
200
|
-
emailVerified && /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "success600", children: "The user will be able to sign in immediately without verifying their email." }) })
|
|
201
|
-
] })
|
|
202
|
-
] })
|
|
203
|
-
}
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
function usePluginSettings() {
|
|
207
|
-
const { get } = useFetchClient();
|
|
208
|
-
return useQuery({
|
|
209
|
-
queryKey: ["dash-plugin-settings"],
|
|
210
|
-
queryFn: async () => {
|
|
211
|
-
const { data } = await get(
|
|
212
|
-
"/better-auth-dashboard/settings"
|
|
213
|
-
);
|
|
214
|
-
return data;
|
|
215
|
-
},
|
|
216
|
-
staleTime: 5 * 60 * 1e3
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
const TwoFaChip = styled.span`
|
|
220
|
-
display: inline-flex;
|
|
221
|
-
align-items: center;
|
|
222
|
-
gap: 5px;
|
|
223
|
-
padding: 3px 10px;
|
|
224
|
-
border-radius: 20px;
|
|
225
|
-
font-size: 11px;
|
|
226
|
-
font-weight: 700;
|
|
227
|
-
background: ${(p) => p.$enabled ? "#eafbe7" : "#f0f0ff"};
|
|
228
|
-
color: ${(p) => p.$enabled ? "#5cb176" : "#8e8ea9"};
|
|
229
|
-
&::before {
|
|
230
|
-
content: '';
|
|
231
|
-
display: inline-block;
|
|
232
|
-
width: 5px;
|
|
233
|
-
height: 5px;
|
|
234
|
-
border-radius: 50%;
|
|
235
|
-
background: ${(p) => p.$enabled ? "#5cb176" : "#b8b8c7"};
|
|
236
|
-
}
|
|
237
|
-
`;
|
|
238
|
-
const BackupCodeGrid = styled.div`
|
|
239
|
-
display: grid;
|
|
240
|
-
grid-template-columns: repeat(2, 1fr);
|
|
241
|
-
gap: 6px;
|
|
242
|
-
`;
|
|
243
|
-
const BackupCodeItem = styled.span`
|
|
244
|
-
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
|
|
245
|
-
font-size: 12px;
|
|
246
|
-
font-weight: 600;
|
|
247
|
-
padding: 6px 10px;
|
|
248
|
-
background: white;
|
|
249
|
-
border: 1px solid #eaeaef;
|
|
250
|
-
border-radius: 6px;
|
|
251
|
-
color: #32324d;
|
|
252
|
-
letter-spacing: 0.05em;
|
|
253
|
-
text-align: center;
|
|
254
|
-
`;
|
|
255
|
-
const ReadOnlyCodeInput = styled.div`
|
|
256
|
-
display: flex;
|
|
257
|
-
align-items: center;
|
|
258
|
-
gap: 8px;
|
|
259
|
-
padding: 8px 12px;
|
|
260
|
-
background: white;
|
|
261
|
-
border: 1px solid #eaeaef;
|
|
262
|
-
border-radius: 6px;
|
|
263
|
-
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
|
|
264
|
-
font-size: 11px;
|
|
265
|
-
color: #32324d;
|
|
266
|
-
word-break: break-all;
|
|
267
|
-
overflow-wrap: anywhere;
|
|
268
|
-
`;
|
|
269
|
-
const SessionCard = styled.div`
|
|
270
|
-
display: flex;
|
|
271
|
-
align-items: flex-start;
|
|
272
|
-
justify-content: space-between;
|
|
273
|
-
gap: 12px;
|
|
274
|
-
padding: 10px 14px;
|
|
275
|
-
background: white;
|
|
276
|
-
border: 1px solid #eaeaef;
|
|
277
|
-
border-radius: 8px;
|
|
278
|
-
`;
|
|
279
|
-
const SessionMeta = styled.div`
|
|
280
|
-
display: flex;
|
|
281
|
-
flex-direction: column;
|
|
282
|
-
gap: 3px;
|
|
283
|
-
flex: 1;
|
|
284
|
-
min-width: 0;
|
|
285
|
-
`;
|
|
286
|
-
const IpChip = styled.span`
|
|
287
|
-
display: inline-block;
|
|
288
|
-
background: #f0f0ff;
|
|
289
|
-
color: #4945ff;
|
|
290
|
-
border-radius: 5px;
|
|
291
|
-
padding: 2px 6px;
|
|
292
|
-
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
|
|
293
|
-
font-size: 11px;
|
|
294
|
-
font-weight: 600;
|
|
295
|
-
`;
|
|
296
|
-
const TimestampText = styled.span`
|
|
297
|
-
font-size: 11px;
|
|
298
|
-
color: #8e8ea9;
|
|
299
|
-
`;
|
|
300
|
-
const AgentText = styled.span`
|
|
301
|
-
font-size: 11px;
|
|
302
|
-
color: #b8b8c7;
|
|
303
|
-
overflow: hidden;
|
|
304
|
-
text-overflow: ellipsis;
|
|
305
|
-
white-space: nowrap;
|
|
306
|
-
display: block;
|
|
307
|
-
`;
|
|
308
|
-
const STANDARD_FIELDS = /* @__PURE__ */ new Set([
|
|
309
|
-
"id",
|
|
310
|
-
"name",
|
|
311
|
-
"email",
|
|
312
|
-
"emailVerified",
|
|
313
|
-
"image",
|
|
314
|
-
"banned",
|
|
315
|
-
"banReason",
|
|
316
|
-
"banExpires",
|
|
317
|
-
"createdAt",
|
|
318
|
-
"updatedAt"
|
|
319
|
-
]);
|
|
320
|
-
function UserDetailDrawer({
|
|
321
|
-
userId,
|
|
322
|
-
banEnabled,
|
|
323
|
-
emailVerificationEnabled,
|
|
324
|
-
twoFactorEnabled,
|
|
325
|
-
onClose
|
|
326
|
-
}) {
|
|
327
|
-
const qc = useQueryClient();
|
|
328
|
-
const { toggleNotification } = useNotification();
|
|
329
|
-
const { get, put } = useFetchClient();
|
|
330
|
-
const schemaQuery = useModelSchema("user");
|
|
331
|
-
const settingsQuery = usePluginSettings();
|
|
332
|
-
const emailCallbackUrl = settingsQuery.data?.email_callback_url ?? null;
|
|
333
|
-
const userQuery = useQuery({
|
|
334
|
-
queryKey: ["dash-user", userId],
|
|
335
|
-
queryFn: async () => {
|
|
336
|
-
const result = await client.dash.user(
|
|
337
|
-
{},
|
|
338
|
-
withContext({ userId }, getAuthHeaders())
|
|
339
|
-
);
|
|
340
|
-
if (result.error)
|
|
341
|
-
throw new Error(result.error.message ?? "Failed to load user");
|
|
342
|
-
return result.data;
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
const orgsQuery = useQuery({
|
|
346
|
-
queryKey: ["dash-user-orgs", userId],
|
|
347
|
-
queryFn: async () => {
|
|
348
|
-
const result = await client.dash.userOrganizations(
|
|
349
|
-
{},
|
|
350
|
-
withContext({ userId }, getAuthHeaders())
|
|
351
|
-
);
|
|
352
|
-
if (result.error) throw new Error(result.error.message ?? "Failed");
|
|
353
|
-
return result.data?.organizations ?? [];
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
const sessionsQuery = useQuery({
|
|
357
|
-
queryKey: ["dash-user-sessions", userId],
|
|
358
|
-
queryFn: async () => {
|
|
359
|
-
const { data } = await get(
|
|
360
|
-
`/better-auth-dashboard/db?uid=plugin::better-auth.session&filters[userId][$eq]=${userId}&sort[0]=createdAt:desc&pagination[pageSize]=50`
|
|
361
|
-
);
|
|
362
|
-
return data.results ?? [];
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
const strapiUserQuery = useQuery({
|
|
366
|
-
queryKey: ["dash-strapi-user", userId],
|
|
367
|
-
enabled: !!schemaQuery.data,
|
|
368
|
-
queryFn: async () => {
|
|
369
|
-
const relationFields = Object.entries(schemaQuery.data).filter(([, attr]) => attr.type === "relation").map(([fieldName]) => fieldName);
|
|
370
|
-
const populateParam = relationFields.length > 0 ? `&populate=${encodeURIComponent(relationFields.join(","))}` : "";
|
|
371
|
-
const { data } = await get(
|
|
372
|
-
`/better-auth-dashboard/db?uid=plugin::better-auth.user&filters[id][$eq]=${userId}&pagination[pageSize]=1${populateParam}`
|
|
373
|
-
);
|
|
374
|
-
return data.results?.[0] ?? null;
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
const [activeTab, setActiveTab] = useState("profile");
|
|
378
|
-
const [editName, setEditName] = useState(void 0);
|
|
379
|
-
const [editEmail, setEditEmail] = useState(void 0);
|
|
380
|
-
const [editEmailVerified, setEditEmailVerified] = useState(void 0);
|
|
381
|
-
const [editImage, setEditImage] = useState(void 0);
|
|
382
|
-
const [editExtra, setEditExtra] = useState({});
|
|
383
|
-
const [newPassword, setNewPassword] = useState("");
|
|
384
|
-
const [banReason, setBanReason] = useState("");
|
|
385
|
-
const [banExpiresDays, setBanExpiresDays] = useState("");
|
|
386
|
-
const [confirmRevokeAll, setConfirmRevokeAll] = useState(false);
|
|
387
|
-
const [confirmRevokeSessionId, setConfirmRevokeSessionId] = useState(null);
|
|
388
|
-
const [confirmBan, setConfirmBan] = useState(false);
|
|
389
|
-
const [confirmUnban, setConfirmUnban] = useState(false);
|
|
390
|
-
const [confirmUnlinkAccountId, setConfirmUnlinkAccountId] = useState(null);
|
|
391
|
-
const [confirmDisable2FA, setConfirmDisable2FA] = useState(false);
|
|
392
|
-
const [showTotpModal, setShowTotpModal] = useState(false);
|
|
393
|
-
const [showBackupCodesModal, setShowBackupCodesModal] = useState(false);
|
|
394
|
-
const [confirmRegenerateBackupCodes, setConfirmRegenerateBackupCodes] = useState(false);
|
|
395
|
-
const [twoFactorData, setTwoFactorData] = useState(null);
|
|
396
|
-
const [totpUriData, setTotpUriData] = useState(null);
|
|
397
|
-
const [backupCodesData, setBackupCodesData] = useState(null);
|
|
398
|
-
const user = userQuery.data;
|
|
399
|
-
const displayName = editName ?? user?.name ?? "";
|
|
400
|
-
const displayEmail = editEmail ?? user?.email ?? "";
|
|
401
|
-
const displayEmailVerified = editEmailVerified ?? user?.emailVerified ?? false;
|
|
402
|
-
const displayImage = editImage ?? user?.image ?? "";
|
|
403
|
-
const handleExtraChange = (name, value) => {
|
|
404
|
-
setEditExtra((prev) => ({ ...prev, [name]: value }));
|
|
405
|
-
};
|
|
406
|
-
const extraData = {
|
|
407
|
-
...strapiUserQuery.data ?? {},
|
|
408
|
-
...editExtra
|
|
409
|
-
};
|
|
410
|
-
const updateMutation = useMutation({
|
|
411
|
-
mutationFn: async () => {
|
|
412
|
-
const body = {};
|
|
413
|
-
if (editName !== void 0) body.name = editName;
|
|
414
|
-
if (editEmail !== void 0) body.email = editEmail;
|
|
415
|
-
if (editEmailVerified !== void 0)
|
|
416
|
-
body.emailVerified = editEmailVerified;
|
|
417
|
-
if (editImage !== void 0) body.image = editImage;
|
|
418
|
-
const documentId = strapiUserQuery.data?.documentId;
|
|
419
|
-
if (!documentId) throw new Error("Could not resolve documentId for user");
|
|
420
|
-
const updateUser = await client.dash.updateUser(
|
|
421
|
-
{ userId, ...body },
|
|
422
|
-
withContext({ userId }, getAuthHeaders())
|
|
423
|
-
);
|
|
424
|
-
if (!updateUser.data) throw new Error("Update failed");
|
|
425
|
-
if (Object.keys(editExtra).length > 0) {
|
|
426
|
-
await put(
|
|
427
|
-
`/better-auth-dashboard/db/${documentId}?uid=plugin::better-auth.user`,
|
|
428
|
-
editExtra
|
|
429
|
-
);
|
|
430
|
-
}
|
|
431
|
-
},
|
|
432
|
-
onSuccess: async () => {
|
|
433
|
-
await qc.invalidateQueries({ queryKey: ["dash-strapi-user", userId] });
|
|
434
|
-
qc.invalidateQueries({ queryKey: ["dash-user", userId] });
|
|
435
|
-
qc.invalidateQueries({ queryKey: ["dash-users"] });
|
|
436
|
-
setEditName(void 0);
|
|
437
|
-
setEditEmail(void 0);
|
|
438
|
-
setEditEmailVerified(void 0);
|
|
439
|
-
setEditImage(void 0);
|
|
440
|
-
setEditExtra({});
|
|
441
|
-
toggleNotification({
|
|
442
|
-
type: "success",
|
|
443
|
-
message: "User updated successfully"
|
|
444
|
-
});
|
|
445
|
-
onClose();
|
|
446
|
-
},
|
|
447
|
-
onError: (err) => {
|
|
448
|
-
toggleNotification({
|
|
449
|
-
type: "danger",
|
|
450
|
-
message: err.message ?? "Update failed"
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
const revokeSessionMutation = useMutation({
|
|
455
|
-
mutationFn: async (sessionId) => {
|
|
456
|
-
const result = await client.dash.sessions.revoke(
|
|
457
|
-
{},
|
|
458
|
-
withContext({ sessionId, userId }, getAuthHeaders())
|
|
459
|
-
);
|
|
460
|
-
if (result.error)
|
|
461
|
-
throw new Error(result.error.message ?? "Revoke failed");
|
|
462
|
-
},
|
|
463
|
-
onSuccess: () => {
|
|
464
|
-
setConfirmRevokeSessionId(null);
|
|
465
|
-
qc.invalidateQueries({ queryKey: ["dash-user-sessions", userId] });
|
|
466
|
-
toggleNotification({ type: "success", message: "Session revoked" });
|
|
467
|
-
},
|
|
468
|
-
onError: (err) => {
|
|
469
|
-
toggleNotification({
|
|
470
|
-
type: "danger",
|
|
471
|
-
message: err.message ?? "Failed to revoke session"
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
});
|
|
475
|
-
const passwordMutation = useMutation({
|
|
476
|
-
mutationFn: async () => {
|
|
477
|
-
const result = await client.dash.setPassword(
|
|
478
|
-
{ password: newPassword },
|
|
479
|
-
withContext({ userId }, getAuthHeaders())
|
|
480
|
-
);
|
|
481
|
-
if (result.error)
|
|
482
|
-
throw new Error(result.error.message ?? "Password update failed");
|
|
483
|
-
return result.data;
|
|
484
|
-
},
|
|
485
|
-
onSuccess: () => {
|
|
486
|
-
setNewPassword("");
|
|
487
|
-
toggleNotification({
|
|
488
|
-
type: "success",
|
|
489
|
-
message: "Password updated successfully"
|
|
490
|
-
});
|
|
491
|
-
},
|
|
492
|
-
onError: (err) => {
|
|
493
|
-
toggleNotification({
|
|
494
|
-
type: "danger",
|
|
495
|
-
message: err.message ?? "Password update failed"
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
});
|
|
499
|
-
const banMutation = useMutation({
|
|
500
|
-
mutationFn: async () => {
|
|
501
|
-
const body = {};
|
|
502
|
-
if (banReason) body.banReason = banReason;
|
|
503
|
-
if (banExpiresDays) {
|
|
504
|
-
const days = parseInt(banExpiresDays, 10);
|
|
505
|
-
if (!Number.isNaN(days)) body.banExpires = Date.now() + days * 864e5;
|
|
506
|
-
}
|
|
507
|
-
const result = await client.dash.banUser(
|
|
508
|
-
body,
|
|
509
|
-
withContext({ userId }, getAuthHeaders())
|
|
510
|
-
);
|
|
511
|
-
if (result.error) throw new Error(result.error.message ?? "Ban failed");
|
|
512
|
-
return result.data;
|
|
513
|
-
},
|
|
514
|
-
onSuccess: () => {
|
|
515
|
-
setConfirmBan(false);
|
|
516
|
-
qc.invalidateQueries({ queryKey: ["dash-user", userId] });
|
|
517
|
-
qc.invalidateQueries({ queryKey: ["dash-users"] });
|
|
518
|
-
setBanReason("");
|
|
519
|
-
setBanExpiresDays("");
|
|
520
|
-
toggleNotification({ type: "success", message: "User has been banned" });
|
|
521
|
-
},
|
|
522
|
-
onError: (err) => {
|
|
523
|
-
toggleNotification({
|
|
524
|
-
type: "danger",
|
|
525
|
-
message: err.message ?? "Ban failed"
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
const unbanMutation = useMutation({
|
|
530
|
-
mutationFn: async () => {
|
|
531
|
-
const result = await client.dash.unbanUser(
|
|
532
|
-
{},
|
|
533
|
-
withContext({ userId }, getAuthHeaders())
|
|
534
|
-
);
|
|
535
|
-
if (result.error) throw new Error(result.error.message ?? "Unban failed");
|
|
536
|
-
return result.data;
|
|
537
|
-
},
|
|
538
|
-
onSuccess: () => {
|
|
539
|
-
setConfirmUnban(false);
|
|
540
|
-
qc.invalidateQueries({ queryKey: ["dash-user", userId] });
|
|
541
|
-
qc.invalidateQueries({ queryKey: ["dash-users"] });
|
|
542
|
-
toggleNotification({ type: "success", message: "Ban has been lifted" });
|
|
543
|
-
},
|
|
544
|
-
onError: (err) => {
|
|
545
|
-
toggleNotification({
|
|
546
|
-
type: "danger",
|
|
547
|
-
message: err.message ?? "Unban failed"
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
const unlinkAccountMutation = useMutation({
|
|
552
|
-
mutationFn: async (providerId) => {
|
|
553
|
-
const result = await client.dash.unlinkAccount(
|
|
554
|
-
{ providerId },
|
|
555
|
-
withContext({ userId }, getAuthHeaders())
|
|
556
|
-
);
|
|
557
|
-
if (result.error)
|
|
558
|
-
throw new Error(result.error.message ?? "Failed to unlink account");
|
|
559
|
-
},
|
|
560
|
-
onSuccess: () => {
|
|
561
|
-
setConfirmUnlinkAccountId(null);
|
|
562
|
-
qc.invalidateQueries({ queryKey: ["dash-user", userId] });
|
|
563
|
-
toggleNotification({ type: "success", message: "Account unlinked" });
|
|
564
|
-
},
|
|
565
|
-
onError: (err) => {
|
|
566
|
-
toggleNotification({
|
|
567
|
-
type: "danger",
|
|
568
|
-
message: err.message ?? "Failed to unlink account"
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
});
|
|
572
|
-
const revokeAllMutation = useMutation({
|
|
573
|
-
mutationFn: async () => {
|
|
574
|
-
const result = await client.dash.sessions.revokeAll(
|
|
575
|
-
{ userId },
|
|
576
|
-
withContext({}, getAuthHeaders())
|
|
577
|
-
);
|
|
578
|
-
if (result.error)
|
|
579
|
-
throw new Error(result.error.message ?? "Revoke failed");
|
|
580
|
-
return result.data;
|
|
581
|
-
},
|
|
582
|
-
onSuccess: () => {
|
|
583
|
-
setConfirmRevokeAll(false);
|
|
584
|
-
toggleNotification({ type: "success", message: "All sessions revoked" });
|
|
585
|
-
},
|
|
586
|
-
onError: (err) => {
|
|
587
|
-
toggleNotification({
|
|
588
|
-
type: "danger",
|
|
589
|
-
message: err.message ?? "Failed to revoke sessions"
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
});
|
|
593
|
-
const sendVerificationMutation = useMutation({
|
|
594
|
-
mutationFn: async () => {
|
|
595
|
-
if (!emailCallbackUrl) {
|
|
596
|
-
throw new Error(
|
|
597
|
-
"Set `email_callback_url` in the better-auth-dashboard plugin config to enable this action."
|
|
598
|
-
);
|
|
599
|
-
}
|
|
600
|
-
const result = await client.dash.sendVerificationEmail(
|
|
601
|
-
{ callbackUrl: emailCallbackUrl },
|
|
602
|
-
withContext({ userId }, getAuthHeaders())
|
|
603
|
-
);
|
|
604
|
-
if (result.error) throw new Error(result.error.message ?? "Failed");
|
|
605
|
-
return result.data;
|
|
606
|
-
},
|
|
607
|
-
onSuccess: () => {
|
|
608
|
-
toggleNotification({
|
|
609
|
-
type: "success",
|
|
610
|
-
message: "Verification email sent"
|
|
611
|
-
});
|
|
612
|
-
},
|
|
613
|
-
onError: (err) => {
|
|
614
|
-
toggleNotification({
|
|
615
|
-
type: "danger",
|
|
616
|
-
message: err.message ?? "Failed to send email"
|
|
617
|
-
});
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
const sendResetPasswordMutation = useMutation({
|
|
621
|
-
mutationFn: async () => {
|
|
622
|
-
if (!emailCallbackUrl) {
|
|
623
|
-
throw new Error(
|
|
624
|
-
"Set `email_callback_url` in the better-auth-dashboard plugin config to enable this action."
|
|
625
|
-
);
|
|
626
|
-
}
|
|
627
|
-
const result = await client.dash.sendResetPasswordEmail(
|
|
628
|
-
{ callbackUrl: emailCallbackUrl },
|
|
629
|
-
withContext({ userId }, getAuthHeaders())
|
|
630
|
-
);
|
|
631
|
-
if (result.error) throw new Error(result.error.message ?? "Failed");
|
|
632
|
-
return result.data;
|
|
633
|
-
},
|
|
634
|
-
onSuccess: () => {
|
|
635
|
-
toggleNotification({
|
|
636
|
-
type: "success",
|
|
637
|
-
message: "Password reset email sent"
|
|
638
|
-
});
|
|
639
|
-
},
|
|
640
|
-
onError: (err) => {
|
|
641
|
-
toggleNotification({
|
|
642
|
-
type: "danger",
|
|
643
|
-
message: err.message ?? "Failed to send email"
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
const enableTwoFactorMutation = useMutation({
|
|
648
|
-
mutationFn: async () => {
|
|
649
|
-
const result = await client.dash.enableTwoFactor(
|
|
650
|
-
{},
|
|
651
|
-
withContext({ userId }, getAuthHeaders())
|
|
652
|
-
);
|
|
653
|
-
if (result.error)
|
|
654
|
-
throw new Error(result.error.message ?? "Failed to enable 2FA");
|
|
655
|
-
return result.data;
|
|
656
|
-
},
|
|
657
|
-
onSuccess: (data) => {
|
|
658
|
-
if (data) setTwoFactorData(data);
|
|
659
|
-
qc.invalidateQueries({ queryKey: ["dash-user", userId] });
|
|
660
|
-
toggleNotification({
|
|
661
|
-
type: "success",
|
|
662
|
-
message: "Two-factor authentication enabled"
|
|
663
|
-
});
|
|
664
|
-
},
|
|
665
|
-
onError: (err) => {
|
|
666
|
-
toggleNotification({
|
|
667
|
-
type: "danger",
|
|
668
|
-
message: err.message ?? "Failed to enable 2FA"
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
});
|
|
672
|
-
const disableTwoFactorMutation = useMutation({
|
|
673
|
-
mutationFn: async () => {
|
|
674
|
-
const result = await client.dash.disableTwoFactor(
|
|
675
|
-
{},
|
|
676
|
-
withContext({ userId }, getAuthHeaders())
|
|
677
|
-
);
|
|
678
|
-
if (result.error)
|
|
679
|
-
throw new Error(result.error.message ?? "Failed to disable 2FA");
|
|
680
|
-
return result.data;
|
|
681
|
-
},
|
|
682
|
-
onSuccess: () => {
|
|
683
|
-
setConfirmDisable2FA(false);
|
|
684
|
-
setTwoFactorData(null);
|
|
685
|
-
setTotpUriData(null);
|
|
686
|
-
setBackupCodesData(null);
|
|
687
|
-
qc.invalidateQueries({ queryKey: ["dash-user", userId] });
|
|
688
|
-
toggleNotification({
|
|
689
|
-
type: "success",
|
|
690
|
-
message: "Two-factor authentication disabled"
|
|
691
|
-
});
|
|
692
|
-
},
|
|
693
|
-
onError: (err) => {
|
|
694
|
-
toggleNotification({
|
|
695
|
-
type: "danger",
|
|
696
|
-
message: err.message ?? "Failed to disable 2FA"
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
});
|
|
700
|
-
const viewTotpUriMutation = useMutation({
|
|
701
|
-
mutationFn: async () => {
|
|
702
|
-
const result = await client.dash.viewTwoFactorTotpUri(
|
|
703
|
-
{},
|
|
704
|
-
withContext({ userId }, getAuthHeaders())
|
|
705
|
-
);
|
|
706
|
-
if (result.error)
|
|
707
|
-
throw new Error(result.error.message ?? "Failed to load TOTP URI");
|
|
708
|
-
return result.data;
|
|
709
|
-
},
|
|
710
|
-
onSuccess: (data) => {
|
|
711
|
-
if (data) {
|
|
712
|
-
setTotpUriData(data);
|
|
713
|
-
setShowTotpModal(true);
|
|
714
|
-
}
|
|
715
|
-
},
|
|
716
|
-
onError: (err) => {
|
|
717
|
-
toggleNotification({
|
|
718
|
-
type: "danger",
|
|
719
|
-
message: err.message ?? "Failed to load TOTP URI"
|
|
720
|
-
});
|
|
721
|
-
}
|
|
722
|
-
});
|
|
723
|
-
const viewBackupCodesMutation = useMutation({
|
|
724
|
-
mutationFn: async () => {
|
|
725
|
-
const result = await client.dash.viewBackupCodes(
|
|
726
|
-
{},
|
|
727
|
-
withContext({ userId }, getAuthHeaders())
|
|
728
|
-
);
|
|
729
|
-
if (result.error)
|
|
730
|
-
throw new Error(result.error.message ?? "Failed to load backup codes");
|
|
731
|
-
return result.data;
|
|
732
|
-
},
|
|
733
|
-
onSuccess: (data) => {
|
|
734
|
-
if (data) {
|
|
735
|
-
setBackupCodesData(data.backupCodes);
|
|
736
|
-
setShowBackupCodesModal(true);
|
|
737
|
-
}
|
|
738
|
-
},
|
|
739
|
-
onError: (err) => {
|
|
740
|
-
toggleNotification({
|
|
741
|
-
type: "danger",
|
|
742
|
-
message: err.message ?? "Failed to load backup codes"
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
});
|
|
746
|
-
const generateBackupCodesMutation = useMutation({
|
|
747
|
-
mutationFn: async () => {
|
|
748
|
-
const result = await client.dash.generateBackupCodes(
|
|
749
|
-
{},
|
|
750
|
-
withContext({ userId }, getAuthHeaders())
|
|
751
|
-
);
|
|
752
|
-
if (result.error)
|
|
753
|
-
throw new Error(
|
|
754
|
-
result.error.message ?? "Failed to generate backup codes"
|
|
755
|
-
);
|
|
756
|
-
return result.data;
|
|
757
|
-
},
|
|
758
|
-
onSuccess: (data) => {
|
|
759
|
-
setConfirmRegenerateBackupCodes(false);
|
|
760
|
-
if (data) {
|
|
761
|
-
setBackupCodesData(data.backupCodes);
|
|
762
|
-
setShowBackupCodesModal(true);
|
|
763
|
-
}
|
|
764
|
-
toggleNotification({
|
|
765
|
-
type: "success",
|
|
766
|
-
message: "New backup codes generated"
|
|
767
|
-
});
|
|
768
|
-
},
|
|
769
|
-
onError: (err) => {
|
|
770
|
-
toggleNotification({
|
|
771
|
-
type: "danger",
|
|
772
|
-
message: err.message ?? "Failed to generate backup codes"
|
|
773
|
-
});
|
|
774
|
-
}
|
|
775
|
-
});
|
|
776
|
-
const hasEdits = editName !== void 0 || editEmail !== void 0 || editEmailVerified !== void 0 || editImage !== void 0 || Object.keys(editExtra).length > 0;
|
|
777
|
-
const customFields = Object.entries(schemaQuery.data ?? {}).filter(([name]) => !STANDARD_FIELDS.has(name)).map(([name, attribute]) => ({ name, attribute }));
|
|
778
|
-
const banExpiryPreview = banExpiresDays && !Number.isNaN(parseInt(banExpiresDays, 10)) ? new Date(
|
|
779
|
-
Date.now() + parseInt(banExpiresDays, 10) * 864e5
|
|
780
|
-
).toLocaleDateString(void 0, {
|
|
781
|
-
weekday: "long",
|
|
782
|
-
year: "numeric",
|
|
783
|
-
month: "long",
|
|
784
|
-
day: "numeric"
|
|
785
|
-
}) : null;
|
|
786
|
-
const drawerTitle = /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
|
|
787
|
-
/* @__PURE__ */ jsx(Avatar, { name: user?.name ?? "?", src: user?.image, size: 30 }),
|
|
788
|
-
/* @__PURE__ */ jsxs(Box, { children: [
|
|
789
|
-
/* @__PURE__ */ jsx(Typography, { variant: "beta", tag: "span", children: user?.name ?? "User" }),
|
|
790
|
-
user?.email && /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: user.email }) })
|
|
791
|
-
] }),
|
|
792
|
-
user?.banned && /* @__PURE__ */ jsx(Badge, { backgroundColor: "danger100", textColor: "danger600", children: "Banned" })
|
|
793
|
-
] });
|
|
794
|
-
const profileFooter = activeTab === "profile" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
795
|
-
/* @__PURE__ */ jsx(
|
|
796
|
-
Button,
|
|
797
|
-
{
|
|
798
|
-
variant: "tertiary",
|
|
799
|
-
onClick: () => {
|
|
800
|
-
setEditName(void 0);
|
|
801
|
-
setEditEmail(void 0);
|
|
802
|
-
setEditEmailVerified(void 0);
|
|
803
|
-
setEditImage(void 0);
|
|
804
|
-
setEditExtra({});
|
|
805
|
-
},
|
|
806
|
-
children: "Discard"
|
|
807
|
-
}
|
|
808
|
-
),
|
|
809
|
-
/* @__PURE__ */ jsx(
|
|
810
|
-
Button,
|
|
811
|
-
{
|
|
812
|
-
disabled: !hasEdits,
|
|
813
|
-
loading: updateMutation.isLoading,
|
|
814
|
-
onClick: () => updateMutation.mutate(),
|
|
815
|
-
"data-testid": "save-user-btn",
|
|
816
|
-
children: "Save changes"
|
|
817
|
-
}
|
|
818
|
-
)
|
|
819
|
-
] }) : void 0;
|
|
820
|
-
return /* @__PURE__ */ jsxs(
|
|
821
|
-
Drawer,
|
|
822
|
-
{
|
|
823
|
-
title: drawerTitle,
|
|
824
|
-
footer: profileFooter,
|
|
825
|
-
onClose,
|
|
826
|
-
"data-testid": "user-detail-drawer",
|
|
827
|
-
children: [
|
|
828
|
-
userQuery.isLoading ? /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral500", children: "Loading user…" }) }) : userQuery.isError ? /* @__PURE__ */ jsx(Alert, { closeLabel: "Close", title: "Failed to load user", variant: "danger", children: userQuery.error instanceof Error ? userQuery.error.message : "An error occurred" }) : /* @__PURE__ */ jsxs(Tabs.Root, { defaultValue: "profile", onValueChange: setActiveTab, children: [
|
|
829
|
-
/* @__PURE__ */ jsxs(Tabs.List, { children: [
|
|
830
|
-
/* @__PURE__ */ jsx(Tabs.Trigger, { value: "profile", children: "Profile" }),
|
|
831
|
-
/* @__PURE__ */ jsx(Tabs.Trigger, { value: "security", children: "Security" }),
|
|
832
|
-
banEnabled && /* @__PURE__ */ jsx(Tabs.Trigger, { value: "ban", children: "Ban" }),
|
|
833
|
-
/* @__PURE__ */ jsx(Tabs.Trigger, { value: "sessions", children: "Sessions" }),
|
|
834
|
-
/* @__PURE__ */ jsx(Tabs.Trigger, { value: "organizations", children: "Organizations" })
|
|
835
|
-
] }),
|
|
836
|
-
/* @__PURE__ */ jsx(Tabs.Content, { value: "profile", children: /* @__PURE__ */ jsxs(EditLayout, { children: [
|
|
837
|
-
/* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 5, children: [
|
|
838
|
-
/* @__PURE__ */ jsxs(FormSection, { children: [
|
|
839
|
-
/* @__PURE__ */ jsx(SectionLabel, { children: "Personal information" }),
|
|
840
|
-
/* @__PURE__ */ jsxs(Field.Root, { style: { width: "100%" }, children: [
|
|
841
|
-
/* @__PURE__ */ jsx(Field.Label, { children: "Full name" }),
|
|
842
|
-
/* @__PURE__ */ jsx(
|
|
843
|
-
TextInput,
|
|
844
|
-
{
|
|
845
|
-
value: displayName,
|
|
846
|
-
onChange: (e) => setEditName(e.target.value),
|
|
847
|
-
"data-testid": "user-name-input"
|
|
848
|
-
}
|
|
849
|
-
)
|
|
850
|
-
] }),
|
|
851
|
-
/* @__PURE__ */ jsxs(Field.Root, { style: { width: "100%" }, children: [
|
|
852
|
-
/* @__PURE__ */ jsx(Field.Label, { children: "Email address" }),
|
|
853
|
-
/* @__PURE__ */ jsx(
|
|
854
|
-
TextInput,
|
|
855
|
-
{
|
|
856
|
-
type: "email",
|
|
857
|
-
value: displayEmail,
|
|
858
|
-
onChange: (e) => setEditEmail(e.target.value)
|
|
859
|
-
}
|
|
860
|
-
)
|
|
861
|
-
] }),
|
|
862
|
-
/* @__PURE__ */ jsx(
|
|
863
|
-
Checkbox,
|
|
864
|
-
{
|
|
865
|
-
checked: displayEmailVerified,
|
|
866
|
-
onCheckedChange: (checked) => setEditEmailVerified(checked),
|
|
867
|
-
children: "Mark email as verified"
|
|
868
|
-
}
|
|
869
|
-
),
|
|
870
|
-
/* @__PURE__ */ jsx(
|
|
871
|
-
MediaPickerField,
|
|
872
|
-
{
|
|
873
|
-
label: "Avatar URL",
|
|
874
|
-
name: "image",
|
|
875
|
-
value: displayImage,
|
|
876
|
-
onChange: setEditImage,
|
|
877
|
-
placeholder: "https://example.com/avatar.png",
|
|
878
|
-
hint: "Optional — publicly accessible image URL"
|
|
879
|
-
}
|
|
880
|
-
)
|
|
881
|
-
] }),
|
|
882
|
-
/* @__PURE__ */ jsx(
|
|
883
|
-
CustomFieldsSection,
|
|
884
|
-
{
|
|
885
|
-
fields: customFields,
|
|
886
|
-
data: extraData,
|
|
887
|
-
onChange: handleExtraChange
|
|
888
|
-
}
|
|
889
|
-
)
|
|
890
|
-
] }),
|
|
891
|
-
/* @__PURE__ */ jsxs(EditSidebar, { children: [
|
|
892
|
-
/* @__PURE__ */ jsxs(FormSection, { children: [
|
|
893
|
-
/* @__PURE__ */ jsx(SectionLabel, { children: "Details" }),
|
|
894
|
-
/* @__PURE__ */ jsxs(
|
|
895
|
-
"div",
|
|
896
|
-
{
|
|
897
|
-
style: {
|
|
898
|
-
display: "grid",
|
|
899
|
-
gridTemplateColumns: "1fr 1fr",
|
|
900
|
-
gap: 12
|
|
901
|
-
},
|
|
902
|
-
children: [
|
|
903
|
-
/* @__PURE__ */ jsxs(MetaItem, { style: { gridColumn: "1 / -1" }, children: [
|
|
904
|
-
/* @__PURE__ */ jsx(MetaKey, { children: "User ID" }),
|
|
905
|
-
/* @__PURE__ */ jsx(MonoChip, { children: user?.id })
|
|
906
|
-
] }),
|
|
907
|
-
/* @__PURE__ */ jsxs(MetaItem, { children: [
|
|
908
|
-
/* @__PURE__ */ jsx(MetaKey, { children: "Created" }),
|
|
909
|
-
/* @__PURE__ */ jsx(MetaVal, { children: user?.createdAt ? new Date(user.createdAt).toLocaleString() : "—" })
|
|
910
|
-
] }),
|
|
911
|
-
/* @__PURE__ */ jsxs(MetaItem, { children: [
|
|
912
|
-
/* @__PURE__ */ jsx(MetaKey, { children: "Last updated" }),
|
|
913
|
-
/* @__PURE__ */ jsx(MetaVal, { children: user?.updatedAt ? new Date(user.updatedAt).toLocaleString() : "—" })
|
|
914
|
-
] })
|
|
915
|
-
]
|
|
916
|
-
}
|
|
917
|
-
)
|
|
918
|
-
] }),
|
|
919
|
-
emailVerificationEnabled && /* @__PURE__ */ jsxs(Box, { children: [
|
|
920
|
-
/* @__PURE__ */ jsx(SectionLabel, { style: { marginBottom: 10 }, children: "Email actions" }),
|
|
921
|
-
/* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
|
922
|
-
/* @__PURE__ */ jsx(
|
|
923
|
-
Button,
|
|
924
|
-
{
|
|
925
|
-
variant: "secondary",
|
|
926
|
-
size: "S",
|
|
927
|
-
loading: sendVerificationMutation.isLoading,
|
|
928
|
-
disabled: !emailCallbackUrl || user?.emailVerified,
|
|
929
|
-
onClick: () => sendVerificationMutation.mutate(),
|
|
930
|
-
style: { width: "100%" },
|
|
931
|
-
children: "Send verification email"
|
|
932
|
-
}
|
|
933
|
-
),
|
|
934
|
-
/* @__PURE__ */ jsx(
|
|
935
|
-
Button,
|
|
936
|
-
{
|
|
937
|
-
variant: "secondary",
|
|
938
|
-
size: "S",
|
|
939
|
-
loading: sendResetPasswordMutation.isLoading,
|
|
940
|
-
disabled: !emailCallbackUrl,
|
|
941
|
-
onClick: () => sendResetPasswordMutation.mutate(),
|
|
942
|
-
style: { width: "100%" },
|
|
943
|
-
children: "Send password reset"
|
|
944
|
-
}
|
|
945
|
-
),
|
|
946
|
-
!settingsQuery.isLoading && !emailCallbackUrl && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: "Set `email_callback_url` in the better-auth-dashboard plugin config to enable these actions." })
|
|
947
|
-
] })
|
|
948
|
-
] }),
|
|
949
|
-
/* @__PURE__ */ jsx(
|
|
950
|
-
EditViewSidePanels,
|
|
951
|
-
{
|
|
952
|
-
model: "plugin::better-auth.user",
|
|
953
|
-
documentId: strapiUserQuery.data?.documentId,
|
|
954
|
-
document: strapiUserQuery.data ?? void 0
|
|
955
|
-
}
|
|
956
|
-
)
|
|
957
|
-
] })
|
|
958
|
-
] }) }),
|
|
959
|
-
/* @__PURE__ */ jsx(Tabs.Content, { value: "security", children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 5, paddingTop: 6, children: [
|
|
960
|
-
/* @__PURE__ */ jsxs(FormSection, { children: [
|
|
961
|
-
/* @__PURE__ */ jsx(SectionLabel, { children: "Password" }),
|
|
962
|
-
/* @__PURE__ */ jsxs(Field.Root, { hint: "The user will be able to sign in with this new password", children: [
|
|
963
|
-
/* @__PURE__ */ jsx(Field.Label, { children: "New password" }),
|
|
964
|
-
/* @__PURE__ */ jsx(
|
|
965
|
-
TextInput,
|
|
966
|
-
{
|
|
967
|
-
type: "password",
|
|
968
|
-
value: newPassword,
|
|
969
|
-
onChange: (e) => setNewPassword(e.target.value),
|
|
970
|
-
placeholder: "Enter a strong password…"
|
|
971
|
-
}
|
|
972
|
-
),
|
|
973
|
-
/* @__PURE__ */ jsx(Field.Hint, {})
|
|
974
|
-
] }),
|
|
975
|
-
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
|
|
976
|
-
Button,
|
|
977
|
-
{
|
|
978
|
-
disabled: !newPassword,
|
|
979
|
-
loading: passwordMutation.isLoading,
|
|
980
|
-
onClick: () => passwordMutation.mutate(),
|
|
981
|
-
children: "Set password"
|
|
982
|
-
}
|
|
983
|
-
) })
|
|
984
|
-
] }),
|
|
985
|
-
/* @__PURE__ */ jsxs(FormSection, { children: [
|
|
986
|
-
/* @__PURE__ */ jsx(SectionLabel, { children: "Linked accounts" }),
|
|
987
|
-
user?.account && user.account.length > 0 ? /* @__PURE__ */ jsx(Flex, { direction: "column", gap: 2, children: user.account.map((acc) => /* @__PURE__ */ jsxs(AccountRow, { children: [
|
|
988
|
-
/* @__PURE__ */ jsx(ProviderBadge, { children: acc.providerId }),
|
|
989
|
-
/* @__PURE__ */ jsx(
|
|
990
|
-
Button,
|
|
991
|
-
{
|
|
992
|
-
variant: "danger-light",
|
|
993
|
-
size: "S",
|
|
994
|
-
onClick: () => setConfirmUnlinkAccountId(acc.providerId),
|
|
995
|
-
children: "Unlink"
|
|
996
|
-
}
|
|
997
|
-
)
|
|
998
|
-
] }, acc.id)) }) : /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: "No linked OAuth accounts." })
|
|
999
|
-
] }),
|
|
1000
|
-
twoFactorEnabled && /* @__PURE__ */ jsxs(FormSection, { children: [
|
|
1001
|
-
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", children: [
|
|
1002
|
-
/* @__PURE__ */ jsx(SectionLabel, { style: { margin: 0 }, children: "Two-factor authentication" }),
|
|
1003
|
-
/* @__PURE__ */ jsx(
|
|
1004
|
-
TwoFaChip,
|
|
1005
|
-
{
|
|
1006
|
-
$enabled: !!user?.twoFactorEnabled,
|
|
1007
|
-
children: user?.twoFactorEnabled ? "Enabled" : "Not enabled"
|
|
1008
|
-
}
|
|
1009
|
-
)
|
|
1010
|
-
] }),
|
|
1011
|
-
user?.twoFactorEnabled ? /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
|
1012
|
-
/* @__PURE__ */ jsxs(AccountRow, { children: [
|
|
1013
|
-
/* @__PURE__ */ jsxs(
|
|
1014
|
-
Flex,
|
|
1015
|
-
{
|
|
1016
|
-
direction: "column",
|
|
1017
|
-
gap: 1,
|
|
1018
|
-
alignItems: "flex-start",
|
|
1019
|
-
children: [
|
|
1020
|
-
/* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: "TOTP authenticator" }),
|
|
1021
|
-
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: "View the URI and secret for this user's authenticator app." })
|
|
1022
|
-
]
|
|
1023
|
-
}
|
|
1024
|
-
),
|
|
1025
|
-
/* @__PURE__ */ jsx(
|
|
1026
|
-
Button,
|
|
1027
|
-
{
|
|
1028
|
-
variant: "secondary",
|
|
1029
|
-
size: "S",
|
|
1030
|
-
loading: viewTotpUriMutation.isLoading,
|
|
1031
|
-
onClick: () => viewTotpUriMutation.mutate(),
|
|
1032
|
-
children: totpUriData ? "Refresh" : "View"
|
|
1033
|
-
}
|
|
1034
|
-
)
|
|
1035
|
-
] }),
|
|
1036
|
-
/* @__PURE__ */ jsxs(AccountRow, { children: [
|
|
1037
|
-
/* @__PURE__ */ jsxs(
|
|
1038
|
-
Flex,
|
|
1039
|
-
{
|
|
1040
|
-
direction: "column",
|
|
1041
|
-
gap: 1,
|
|
1042
|
-
alignItems: "flex-start",
|
|
1043
|
-
children: [
|
|
1044
|
-
/* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: "Backup codes" }),
|
|
1045
|
-
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: "View or regenerate the user's recovery codes." })
|
|
1046
|
-
]
|
|
1047
|
-
}
|
|
1048
|
-
),
|
|
1049
|
-
/* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
|
1050
|
-
/* @__PURE__ */ jsx(
|
|
1051
|
-
Button,
|
|
1052
|
-
{
|
|
1053
|
-
variant: "secondary",
|
|
1054
|
-
size: "S",
|
|
1055
|
-
loading: viewBackupCodesMutation.isLoading,
|
|
1056
|
-
onClick: () => viewBackupCodesMutation.mutate(),
|
|
1057
|
-
children: backupCodesData ? "Refresh" : "View"
|
|
1058
|
-
}
|
|
1059
|
-
),
|
|
1060
|
-
/* @__PURE__ */ jsx(
|
|
1061
|
-
Button,
|
|
1062
|
-
{
|
|
1063
|
-
variant: "secondary",
|
|
1064
|
-
size: "S",
|
|
1065
|
-
onClick: () => setConfirmRegenerateBackupCodes(true),
|
|
1066
|
-
children: "Regenerate"
|
|
1067
|
-
}
|
|
1068
|
-
)
|
|
1069
|
-
] })
|
|
1070
|
-
] }),
|
|
1071
|
-
/* @__PURE__ */ jsxs(DangerRow, { children: [
|
|
1072
|
-
/* @__PURE__ */ jsxs(
|
|
1073
|
-
Flex,
|
|
1074
|
-
{
|
|
1075
|
-
direction: "column",
|
|
1076
|
-
gap: 1,
|
|
1077
|
-
alignItems: "flex-start",
|
|
1078
|
-
children: [
|
|
1079
|
-
/* @__PURE__ */ jsx(
|
|
1080
|
-
Typography,
|
|
1081
|
-
{
|
|
1082
|
-
variant: "omega",
|
|
1083
|
-
fontWeight: "semiBold",
|
|
1084
|
-
textColor: "danger600",
|
|
1085
|
-
children: "Disable two-factor authentication"
|
|
1086
|
-
}
|
|
1087
|
-
),
|
|
1088
|
-
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger500", children: "The user will no longer need a second factor to sign in." })
|
|
1089
|
-
]
|
|
1090
|
-
}
|
|
1091
|
-
),
|
|
1092
|
-
/* @__PURE__ */ jsx(
|
|
1093
|
-
Button,
|
|
1094
|
-
{
|
|
1095
|
-
variant: "danger-light",
|
|
1096
|
-
size: "S",
|
|
1097
|
-
onClick: () => setConfirmDisable2FA(true),
|
|
1098
|
-
children: "Disable 2FA"
|
|
1099
|
-
}
|
|
1100
|
-
)
|
|
1101
|
-
] })
|
|
1102
|
-
] }) : /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
|
1103
|
-
twoFactorData && /* @__PURE__ */ jsxs(
|
|
1104
|
-
Flex,
|
|
1105
|
-
{
|
|
1106
|
-
direction: "column",
|
|
1107
|
-
gap: 3,
|
|
1108
|
-
style: { padding: "2px 4px" },
|
|
1109
|
-
children: [
|
|
1110
|
-
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: "Scan the TOTP URI with an authenticator app, or enter the secret key manually." }),
|
|
1111
|
-
/* @__PURE__ */ jsxs(Field.Root, { children: [
|
|
1112
|
-
/* @__PURE__ */ jsx(Field.Label, { children: "TOTP URI" }),
|
|
1113
|
-
/* @__PURE__ */ jsx(ReadOnlyCodeInput, { children: twoFactorData.totpURI })
|
|
1114
|
-
] }),
|
|
1115
|
-
/* @__PURE__ */ jsxs(Field.Root, { children: [
|
|
1116
|
-
/* @__PURE__ */ jsx(Field.Label, { children: "Secret key" }),
|
|
1117
|
-
/* @__PURE__ */ jsx(ReadOnlyCodeInput, { children: twoFactorData.secret })
|
|
1118
|
-
] }),
|
|
1119
|
-
/* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
|
1120
|
-
/* @__PURE__ */ jsx(SectionLabel, { children: "Backup codes" }),
|
|
1121
|
-
/* @__PURE__ */ jsx(BackupCodeGrid, { children: twoFactorData.backupCodes.map((code) => /* @__PURE__ */ jsx(BackupCodeItem, { children: code }, code)) })
|
|
1122
|
-
] })
|
|
1123
|
-
]
|
|
1124
|
-
}
|
|
1125
|
-
),
|
|
1126
|
-
/* @__PURE__ */ jsxs(AccountRow, { children: [
|
|
1127
|
-
/* @__PURE__ */ jsxs(
|
|
1128
|
-
Flex,
|
|
1129
|
-
{
|
|
1130
|
-
direction: "column",
|
|
1131
|
-
gap: 1,
|
|
1132
|
-
alignItems: "flex-start",
|
|
1133
|
-
children: [
|
|
1134
|
-
/* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: "Enable two-factor authentication" }),
|
|
1135
|
-
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: "Add an extra layer of security to this account." })
|
|
1136
|
-
]
|
|
1137
|
-
}
|
|
1138
|
-
),
|
|
1139
|
-
/* @__PURE__ */ jsx(
|
|
1140
|
-
Button,
|
|
1141
|
-
{
|
|
1142
|
-
size: "S",
|
|
1143
|
-
loading: enableTwoFactorMutation.isLoading,
|
|
1144
|
-
onClick: () => enableTwoFactorMutation.mutate(),
|
|
1145
|
-
children: "Enable 2FA"
|
|
1146
|
-
}
|
|
1147
|
-
)
|
|
1148
|
-
] })
|
|
1149
|
-
] })
|
|
1150
|
-
] })
|
|
1151
|
-
] }) }),
|
|
1152
|
-
banEnabled && /* @__PURE__ */ jsx(Tabs.Content, { value: "ban", children: /* @__PURE__ */ jsx(Flex, { direction: "column", gap: 5, paddingTop: 6, children: user?.banned ? /* @__PURE__ */ jsxs(FormSection, { children: [
|
|
1153
|
-
/* @__PURE__ */ jsx(SectionLabel, { children: "Ban status" }),
|
|
1154
|
-
/* @__PURE__ */ jsxs(WarnCard, { children: [
|
|
1155
|
-
/* @__PURE__ */ jsx(
|
|
1156
|
-
Typography,
|
|
1157
|
-
{
|
|
1158
|
-
variant: "omega",
|
|
1159
|
-
fontWeight: "semiBold",
|
|
1160
|
-
textColor: "danger600",
|
|
1161
|
-
children: "This user is currently banned"
|
|
1162
|
-
}
|
|
1163
|
-
),
|
|
1164
|
-
user.banReason && /* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "danger600", children: [
|
|
1165
|
-
"Reason: ",
|
|
1166
|
-
user.banReason
|
|
1167
|
-
] }),
|
|
1168
|
-
user.banExpires ? /* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "danger600", children: [
|
|
1169
|
-
"Expires:",
|
|
1170
|
-
" ",
|
|
1171
|
-
new Date(user.banExpires).toLocaleDateString(
|
|
1172
|
-
void 0,
|
|
1173
|
-
{
|
|
1174
|
-
weekday: "long",
|
|
1175
|
-
year: "numeric",
|
|
1176
|
-
month: "long",
|
|
1177
|
-
day: "numeric"
|
|
1178
|
-
}
|
|
1179
|
-
)
|
|
1180
|
-
] }) : /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger600", children: "Duration: Permanent" })
|
|
1181
|
-
] }),
|
|
1182
|
-
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
|
|
1183
|
-
Button,
|
|
1184
|
-
{
|
|
1185
|
-
variant: "secondary",
|
|
1186
|
-
onClick: () => setConfirmUnban(true),
|
|
1187
|
-
children: "Lift ban"
|
|
1188
|
-
}
|
|
1189
|
-
) })
|
|
1190
|
-
] }) : /* @__PURE__ */ jsxs(FormSection, { children: [
|
|
1191
|
-
/* @__PURE__ */ jsx(SectionLabel, { children: "Apply ban" }),
|
|
1192
|
-
/* @__PURE__ */ jsxs(
|
|
1193
|
-
Field.Root,
|
|
1194
|
-
{
|
|
1195
|
-
hint: "Optional — will be shown to the user",
|
|
1196
|
-
style: { width: "100%" },
|
|
1197
|
-
children: [
|
|
1198
|
-
/* @__PURE__ */ jsx(Field.Label, { children: "Reason" }),
|
|
1199
|
-
/* @__PURE__ */ jsx(
|
|
1200
|
-
TextInput,
|
|
1201
|
-
{
|
|
1202
|
-
value: banReason,
|
|
1203
|
-
onChange: (e) => setBanReason(e.target.value),
|
|
1204
|
-
placeholder: "e.g. Violated terms of service"
|
|
1205
|
-
}
|
|
1206
|
-
),
|
|
1207
|
-
/* @__PURE__ */ jsx(Field.Hint, {})
|
|
1208
|
-
]
|
|
1209
|
-
}
|
|
1210
|
-
),
|
|
1211
|
-
/* @__PURE__ */ jsxs(Grid.Root, { gap: 4, children: [
|
|
1212
|
-
/* @__PURE__ */ jsx(Grid.Item, { col: 6, children: /* @__PURE__ */ jsxs(
|
|
1213
|
-
Field.Root,
|
|
1214
|
-
{
|
|
1215
|
-
hint: "Leave empty for a permanent ban",
|
|
1216
|
-
style: { width: "100%" },
|
|
1217
|
-
children: [
|
|
1218
|
-
/* @__PURE__ */ jsx(Field.Label, { children: "Duration (days)" }),
|
|
1219
|
-
/* @__PURE__ */ jsx(
|
|
1220
|
-
TextInput,
|
|
1221
|
-
{
|
|
1222
|
-
type: "number",
|
|
1223
|
-
value: banExpiresDays,
|
|
1224
|
-
onChange: (e) => setBanExpiresDays(e.target.value),
|
|
1225
|
-
placeholder: "e.g. 30"
|
|
1226
|
-
}
|
|
1227
|
-
),
|
|
1228
|
-
/* @__PURE__ */ jsx(Field.Hint, {})
|
|
1229
|
-
]
|
|
1230
|
-
}
|
|
1231
|
-
) }),
|
|
1232
|
-
/* @__PURE__ */ jsx(Grid.Item, { col: 6, children: /* @__PURE__ */ jsx(
|
|
1233
|
-
Flex,
|
|
1234
|
-
{
|
|
1235
|
-
direction: "column",
|
|
1236
|
-
justifyContent: "flex-end",
|
|
1237
|
-
style: { height: "100%", paddingBottom: 4 },
|
|
1238
|
-
children: /* @__PURE__ */ jsx(PreviewPill, { children: banExpiryPreview ? `⏱ Expires ${banExpiryPreview}` : "♾ Permanent ban" })
|
|
1239
|
-
}
|
|
1240
|
-
) })
|
|
1241
|
-
] }),
|
|
1242
|
-
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
|
|
1243
|
-
Button,
|
|
1244
|
-
{
|
|
1245
|
-
variant: "danger",
|
|
1246
|
-
onClick: () => setConfirmBan(true),
|
|
1247
|
-
children: "Ban user"
|
|
1248
|
-
}
|
|
1249
|
-
) })
|
|
1250
|
-
] }) }) }),
|
|
1251
|
-
/* @__PURE__ */ jsx(Tabs.Content, { value: "sessions", children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 5, paddingTop: 6, children: [
|
|
1252
|
-
/* @__PURE__ */ jsxs(FormSection, { children: [
|
|
1253
|
-
/* @__PURE__ */ jsx(SectionLabel, { children: "Session management" }),
|
|
1254
|
-
/* @__PURE__ */ jsxs(AccountRow, { children: [
|
|
1255
|
-
/* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 1, alignItems: "flex-start", children: [
|
|
1256
|
-
/* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: "Revoke all sessions" }),
|
|
1257
|
-
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: "Signs the user out immediately on all devices." })
|
|
1258
|
-
] }),
|
|
1259
|
-
/* @__PURE__ */ jsx(
|
|
1260
|
-
Button,
|
|
1261
|
-
{
|
|
1262
|
-
variant: "danger-light",
|
|
1263
|
-
size: "S",
|
|
1264
|
-
onClick: () => setConfirmRevokeAll(true),
|
|
1265
|
-
style: { flexShrink: 0 },
|
|
1266
|
-
children: "Revoke all"
|
|
1267
|
-
}
|
|
1268
|
-
)
|
|
1269
|
-
] })
|
|
1270
|
-
] }),
|
|
1271
|
-
/* @__PURE__ */ jsxs(FormSection, { children: [
|
|
1272
|
-
/* @__PURE__ */ jsx(SectionLabel, { children: "Active sessions" }),
|
|
1273
|
-
sessionsQuery.isLoading ? /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsx(Loader, { children: "Loading sessions…" }) }) : (sessionsQuery.data ?? []).length === 0 ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: "No active sessions." }) : /* @__PURE__ */ jsx(Flex, { direction: "column", gap: 2, alignItems: "stretch", children: (sessionsQuery.data ?? []).map((session) => /* @__PURE__ */ jsxs(SessionCard, { children: [
|
|
1274
|
-
/* @__PURE__ */ jsxs(SessionMeta, { children: [
|
|
1275
|
-
/* @__PURE__ */ jsxs(
|
|
1276
|
-
Flex,
|
|
1277
|
-
{
|
|
1278
|
-
gap: 2,
|
|
1279
|
-
alignItems: "center",
|
|
1280
|
-
style: { flexWrap: "wrap" },
|
|
1281
|
-
children: [
|
|
1282
|
-
session.ipAddress && /* @__PURE__ */ jsx(IpChip, { children: session.ipAddress }),
|
|
1283
|
-
/* @__PURE__ */ jsxs(TimestampText, { children: [
|
|
1284
|
-
"Created",
|
|
1285
|
-
" ",
|
|
1286
|
-
new Date(session.createdAt).toLocaleString(),
|
|
1287
|
-
" · Expires",
|
|
1288
|
-
" ",
|
|
1289
|
-
new Date(session.expiresAt).toLocaleString()
|
|
1290
|
-
] })
|
|
1291
|
-
]
|
|
1292
|
-
}
|
|
1293
|
-
),
|
|
1294
|
-
session.userAgent && /* @__PURE__ */ jsx(AgentText, { children: session.userAgent })
|
|
1295
|
-
] }),
|
|
1296
|
-
/* @__PURE__ */ jsx(
|
|
1297
|
-
IconButton,
|
|
1298
|
-
{
|
|
1299
|
-
label: "Revoke session",
|
|
1300
|
-
onClick: () => setConfirmRevokeSessionId(String(session.id)),
|
|
1301
|
-
style: { flexShrink: 0 },
|
|
1302
|
-
children: /* @__PURE__ */ jsx(Trash, {})
|
|
1303
|
-
}
|
|
1304
|
-
)
|
|
1305
|
-
] }, session.documentId)) })
|
|
1306
|
-
] })
|
|
1307
|
-
] }) }),
|
|
1308
|
-
/* @__PURE__ */ jsx(Tabs.Content, { value: "organizations", children: /* @__PURE__ */ jsx(Flex, { direction: "column", gap: 5, paddingTop: 6, children: /* @__PURE__ */ jsxs(FormSection, { children: [
|
|
1309
|
-
/* @__PURE__ */ jsx(SectionLabel, { children: "Memberships" }),
|
|
1310
|
-
orgsQuery.isLoading ? /* @__PURE__ */ jsx(Typography, { textColor: "neutral500", children: "Loading…" }) : (orgsQuery.data ?? []).length === 0 ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: "Not a member of any organizations." }) : /* @__PURE__ */ jsx(Flex, { direction: "column", gap: 2, children: (orgsQuery.data ?? []).map(
|
|
1311
|
-
(org) => org ? /* @__PURE__ */ jsx(AccountRow, { children: /* @__PURE__ */ jsxs(
|
|
1312
|
-
Flex,
|
|
1313
|
-
{
|
|
1314
|
-
direction: "column",
|
|
1315
|
-
gap: 1,
|
|
1316
|
-
alignItems: "flex-start",
|
|
1317
|
-
children: [
|
|
1318
|
-
/* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: org.name }),
|
|
1319
|
-
/* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
|
|
1320
|
-
/* @__PURE__ */ jsx(RoleBadge, { $role: org.role, children: org.role }),
|
|
1321
|
-
org.teams.length > 0 && /* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "neutral500", children: [
|
|
1322
|
-
org.teams.length,
|
|
1323
|
-
" team",
|
|
1324
|
-
org.teams.length !== 1 ? "s" : ""
|
|
1325
|
-
] })
|
|
1326
|
-
] })
|
|
1327
|
-
]
|
|
1328
|
-
}
|
|
1329
|
-
) }, org.id) : null
|
|
1330
|
-
) })
|
|
1331
|
-
] }) }) })
|
|
1332
|
-
] }),
|
|
1333
|
-
confirmRevokeAll && /* @__PURE__ */ jsx(
|
|
1334
|
-
ConfirmDialog,
|
|
1335
|
-
{
|
|
1336
|
-
title: "Revoke all sessions",
|
|
1337
|
-
message: "Are you sure you want to revoke all sessions for this user? They will be signed out on all devices.",
|
|
1338
|
-
confirmLabel: "Revoke all",
|
|
1339
|
-
loading: revokeAllMutation.isLoading,
|
|
1340
|
-
onConfirm: () => revokeAllMutation.mutate(),
|
|
1341
|
-
onCancel: () => setConfirmRevokeAll(false)
|
|
1342
|
-
}
|
|
1343
|
-
),
|
|
1344
|
-
confirmRevokeSessionId && /* @__PURE__ */ jsx(
|
|
1345
|
-
ConfirmDialog,
|
|
1346
|
-
{
|
|
1347
|
-
title: "Revoke session",
|
|
1348
|
-
message: "Are you sure you want to revoke this session? The user will be signed out on this device.",
|
|
1349
|
-
confirmLabel: "Revoke",
|
|
1350
|
-
loading: revokeSessionMutation.isLoading,
|
|
1351
|
-
onConfirm: () => revokeSessionMutation.mutate(confirmRevokeSessionId),
|
|
1352
|
-
onCancel: () => setConfirmRevokeSessionId(null)
|
|
1353
|
-
}
|
|
1354
|
-
),
|
|
1355
|
-
confirmBan && /* @__PURE__ */ jsx(
|
|
1356
|
-
ConfirmDialog,
|
|
1357
|
-
{
|
|
1358
|
-
title: "Ban user",
|
|
1359
|
-
message: banReason ? `Ban this user for the following reason: "${banReason}"? They will be prevented from signing in.` : "Are you sure you want to ban this user? They will be prevented from signing in.",
|
|
1360
|
-
confirmLabel: "Ban user",
|
|
1361
|
-
variant: "danger",
|
|
1362
|
-
loading: banMutation.isLoading,
|
|
1363
|
-
onConfirm: () => banMutation.mutate(),
|
|
1364
|
-
onCancel: () => setConfirmBan(false)
|
|
1365
|
-
}
|
|
1366
|
-
),
|
|
1367
|
-
confirmUnban && /* @__PURE__ */ jsx(
|
|
1368
|
-
ConfirmDialog,
|
|
1369
|
-
{
|
|
1370
|
-
title: "Lift ban",
|
|
1371
|
-
message: "Are you sure you want to lift the ban on this user? They will be able to sign in again.",
|
|
1372
|
-
confirmLabel: "Lift ban",
|
|
1373
|
-
variant: "default",
|
|
1374
|
-
loading: unbanMutation.isLoading,
|
|
1375
|
-
onConfirm: () => unbanMutation.mutate(),
|
|
1376
|
-
onCancel: () => setConfirmUnban(false)
|
|
1377
|
-
}
|
|
1378
|
-
),
|
|
1379
|
-
confirmUnlinkAccountId && /* @__PURE__ */ jsx(
|
|
1380
|
-
ConfirmDialog,
|
|
1381
|
-
{
|
|
1382
|
-
title: "Unlink account",
|
|
1383
|
-
message: `Are you sure you want to unlink the "${confirmUnlinkAccountId}" provider from this user?`,
|
|
1384
|
-
confirmLabel: "Unlink",
|
|
1385
|
-
loading: unlinkAccountMutation.isLoading,
|
|
1386
|
-
onConfirm: () => unlinkAccountMutation.mutate(confirmUnlinkAccountId),
|
|
1387
|
-
onCancel: () => setConfirmUnlinkAccountId(null)
|
|
1388
|
-
}
|
|
1389
|
-
),
|
|
1390
|
-
confirmDisable2FA && /* @__PURE__ */ jsx(
|
|
1391
|
-
ConfirmDialog,
|
|
1392
|
-
{
|
|
1393
|
-
title: "Disable two-factor authentication",
|
|
1394
|
-
message: "Are you sure you want to disable 2FA for this user? They will no longer need a second factor to sign in.",
|
|
1395
|
-
confirmLabel: "Disable 2FA",
|
|
1396
|
-
loading: disableTwoFactorMutation.isLoading,
|
|
1397
|
-
onConfirm: () => disableTwoFactorMutation.mutate(),
|
|
1398
|
-
onCancel: () => setConfirmDisable2FA(false)
|
|
1399
|
-
}
|
|
1400
|
-
),
|
|
1401
|
-
confirmRegenerateBackupCodes && /* @__PURE__ */ jsx(
|
|
1402
|
-
ConfirmDialog,
|
|
1403
|
-
{
|
|
1404
|
-
title: "Regenerate backup codes",
|
|
1405
|
-
message: "This will invalidate all existing backup codes. New codes will be shown once after generation. Are you sure?",
|
|
1406
|
-
confirmLabel: "Regenerate",
|
|
1407
|
-
loading: generateBackupCodesMutation.isLoading,
|
|
1408
|
-
onConfirm: () => generateBackupCodesMutation.mutate(),
|
|
1409
|
-
onCancel: () => setConfirmRegenerateBackupCodes(false)
|
|
1410
|
-
}
|
|
1411
|
-
),
|
|
1412
|
-
showTotpModal && totpUriData && /* @__PURE__ */ jsx(
|
|
1413
|
-
Modal.Root,
|
|
1414
|
-
{
|
|
1415
|
-
defaultOpen: true,
|
|
1416
|
-
onOpenChange: (open) => !open && setShowTotpModal(false),
|
|
1417
|
-
children: /* @__PURE__ */ jsxs(Modal.Content, { children: [
|
|
1418
|
-
/* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Typography, { variant: "beta", tag: "h2", children: "TOTP authenticator" }) }),
|
|
1419
|
-
/* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 4, children: [
|
|
1420
|
-
/* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", children: "Share these details with the user to set up their authenticator app." }),
|
|
1421
|
-
/* @__PURE__ */ jsxs(Field.Root, { children: [
|
|
1422
|
-
/* @__PURE__ */ jsx(Field.Label, { children: "TOTP URI" }),
|
|
1423
|
-
/* @__PURE__ */ jsx(ReadOnlyCodeInput, { children: totpUriData.totpURI })
|
|
1424
|
-
] }),
|
|
1425
|
-
/* @__PURE__ */ jsxs(Field.Root, { children: [
|
|
1426
|
-
/* @__PURE__ */ jsx(Field.Label, { children: "Secret key" }),
|
|
1427
|
-
/* @__PURE__ */ jsx(ReadOnlyCodeInput, { children: totpUriData.secret })
|
|
1428
|
-
] })
|
|
1429
|
-
] }) }),
|
|
1430
|
-
/* @__PURE__ */ jsx(Modal.Footer, { children: /* @__PURE__ */ jsx(
|
|
1431
|
-
Button,
|
|
1432
|
-
{
|
|
1433
|
-
variant: "tertiary",
|
|
1434
|
-
onClick: () => setShowTotpModal(false),
|
|
1435
|
-
children: "Close"
|
|
1436
|
-
}
|
|
1437
|
-
) })
|
|
1438
|
-
] })
|
|
1439
|
-
}
|
|
1440
|
-
),
|
|
1441
|
-
showBackupCodesModal && backupCodesData && /* @__PURE__ */ jsx(
|
|
1442
|
-
Modal.Root,
|
|
1443
|
-
{
|
|
1444
|
-
defaultOpen: true,
|
|
1445
|
-
onOpenChange: (open) => !open && setShowBackupCodesModal(false),
|
|
1446
|
-
children: /* @__PURE__ */ jsxs(Modal.Content, { children: [
|
|
1447
|
-
/* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Typography, { variant: "beta", tag: "h2", children: "Backup codes" }) }),
|
|
1448
|
-
/* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 4, children: [
|
|
1449
|
-
/* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", children: "Each code can only be used once. Store them somewhere safe." }),
|
|
1450
|
-
/* @__PURE__ */ jsx(BackupCodeGrid, { children: backupCodesData.map((code) => /* @__PURE__ */ jsx(BackupCodeItem, { children: code }, code)) })
|
|
1451
|
-
] }) }),
|
|
1452
|
-
/* @__PURE__ */ jsx(Modal.Footer, { children: /* @__PURE__ */ jsx(
|
|
1453
|
-
Button,
|
|
1454
|
-
{
|
|
1455
|
-
variant: "tertiary",
|
|
1456
|
-
onClick: () => setShowBackupCodesModal(false),
|
|
1457
|
-
children: "Close"
|
|
1458
|
-
}
|
|
1459
|
-
) })
|
|
1460
|
-
] })
|
|
1461
|
-
}
|
|
1462
|
-
)
|
|
1463
|
-
]
|
|
1464
|
-
}
|
|
1465
|
-
);
|
|
1466
|
-
}
|
|
1467
|
-
const PAGE_SIZE = 25;
|
|
1468
|
-
const fadeUp = keyframes`
|
|
1469
|
-
from { opacity: 0; transform: translateY(6px); }
|
|
1470
|
-
to { opacity: 1; transform: translateY(0); }
|
|
1471
|
-
`;
|
|
1472
|
-
const Wrap = styled.div`
|
|
1473
|
-
padding: 28px 32px;
|
|
1474
|
-
background: #f6f6f9;
|
|
1475
|
-
min-height: 100%;
|
|
1476
|
-
display: flex;
|
|
1477
|
-
flex-direction: column;
|
|
1478
|
-
gap: 20px;
|
|
1479
|
-
`;
|
|
1480
|
-
const PageHeader = styled.div`
|
|
1481
|
-
display: flex;
|
|
1482
|
-
justify-content: space-between;
|
|
1483
|
-
align-items: flex-start;
|
|
1484
|
-
`;
|
|
1485
|
-
const TitleBlock = styled.div`
|
|
1486
|
-
display: flex;
|
|
1487
|
-
flex-direction: column;
|
|
1488
|
-
gap: 4px;
|
|
1489
|
-
`;
|
|
1490
|
-
const PageTitle = styled.h1`
|
|
1491
|
-
margin: 0;
|
|
1492
|
-
font-size: 22px;
|
|
1493
|
-
font-weight: 800;
|
|
1494
|
-
color: #32324d;
|
|
1495
|
-
letter-spacing: -0.03em;
|
|
1496
|
-
`;
|
|
1497
|
-
const PageSubtitle = styled.p`
|
|
1498
|
-
margin: 0;
|
|
1499
|
-
font-size: 12px;
|
|
1500
|
-
color: #8e8ea9;
|
|
1501
|
-
`;
|
|
1502
|
-
const TableCard = styled.div`
|
|
1503
|
-
background: #ffffff;
|
|
1504
|
-
border: 1px solid #eaeaef;
|
|
1505
|
-
border-radius: 10px;
|
|
1506
|
-
overflow: hidden;
|
|
1507
|
-
`;
|
|
1508
|
-
const Table = styled.table`
|
|
1509
|
-
width: 100%;
|
|
1510
|
-
border-collapse: collapse;
|
|
1511
|
-
`;
|
|
1512
|
-
const TH = styled.th`
|
|
1513
|
-
text-align: left;
|
|
1514
|
-
padding: 10px 14px;
|
|
1515
|
-
font-size: 10px;
|
|
1516
|
-
font-weight: 700;
|
|
1517
|
-
color: #8e8ea9;
|
|
1518
|
-
text-transform: uppercase;
|
|
1519
|
-
letter-spacing: 0.08em;
|
|
1520
|
-
border-bottom: 1px solid #eaeaef;
|
|
1521
|
-
background: #fafafa;
|
|
1522
|
-
white-space: nowrap;
|
|
1523
|
-
&:first-child { padding-left: 20px; }
|
|
1524
|
-
&:last-child { padding-right: 20px; }
|
|
1525
|
-
`;
|
|
1526
|
-
const THCheck = styled(TH)`
|
|
1527
|
-
width: 44px;
|
|
1528
|
-
`;
|
|
1529
|
-
const THActions = styled(TH)`
|
|
1530
|
-
width: 80px;
|
|
1531
|
-
`;
|
|
1532
|
-
const TD = styled.td`
|
|
1533
|
-
padding: 11px 14px;
|
|
1534
|
-
font-size: 12px;
|
|
1535
|
-
color: #32324d;
|
|
1536
|
-
border-bottom: 1px solid #f5f5f9;
|
|
1537
|
-
vertical-align: middle;
|
|
1538
|
-
&:first-child { padding-left: 20px; }
|
|
1539
|
-
&:last-child { padding-right: 20px; }
|
|
1540
|
-
`;
|
|
1541
|
-
const TDCheck = styled(TD)`
|
|
1542
|
-
width: 44px;
|
|
1543
|
-
`;
|
|
1544
|
-
const TDActions = styled(TD)`
|
|
1545
|
-
width: 80px;
|
|
1546
|
-
`;
|
|
1547
|
-
const TR = styled.tr`
|
|
1548
|
-
animation: ${fadeUp} 280ms ease both;
|
|
1549
|
-
animation-delay: ${(p) => (p.$i ?? 0) * 25}ms;
|
|
1550
|
-
background: ${(p) => p.$selected ? "#f0f0ff" : "transparent"};
|
|
1551
|
-
transition: background 120ms ease;
|
|
1552
|
-
&:hover td { background: ${(p) => p.$selected ? "#e8e8ff" : "#fafafe"}; }
|
|
1553
|
-
&:last-child td { border-bottom: none; }
|
|
1554
|
-
`;
|
|
1555
|
-
const StatusChip = styled.span`
|
|
1556
|
-
display: inline-flex;
|
|
1557
|
-
align-items: center;
|
|
1558
|
-
gap: 4px;
|
|
1559
|
-
padding: 2px 8px;
|
|
1560
|
-
border-radius: 20px;
|
|
1561
|
-
font-size: 10px;
|
|
1562
|
-
font-weight: 700;
|
|
1563
|
-
background: ${(p) => p.$variant === "verified" ? "#eafbe7" : p.$variant === "banned" ? "#fcecea" : "#f0f0ff"};
|
|
1564
|
-
color: ${(p) => p.$variant === "verified" ? "#5cb176" : p.$variant === "banned" ? "#d02b20" : "#8e8ea9"};
|
|
1565
|
-
|
|
1566
|
-
&::before {
|
|
1567
|
-
content: '';
|
|
1568
|
-
display: inline-block;
|
|
1569
|
-
width: 5px;
|
|
1570
|
-
height: 5px;
|
|
1571
|
-
border-radius: 50%;
|
|
1572
|
-
background: ${(p) => p.$variant === "verified" ? "#5cb176" : p.$variant === "banned" ? "#d02b20" : "#b8b8c7"};
|
|
1573
|
-
}
|
|
1574
|
-
`;
|
|
1575
|
-
const MonoText = styled.span`
|
|
1576
|
-
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
|
|
1577
|
-
font-size: 11px;
|
|
1578
|
-
color: #8e8ea9;
|
|
1579
|
-
`;
|
|
1580
|
-
const DateText = styled.span`
|
|
1581
|
-
font-size: 11px;
|
|
1582
|
-
color: #b8b8c7;
|
|
1583
|
-
font-variant-numeric: tabular-nums;
|
|
1584
|
-
`;
|
|
1585
|
-
const UserName = styled.span`
|
|
1586
|
-
font-size: 12px;
|
|
1587
|
-
font-weight: 600;
|
|
1588
|
-
color: #32324d;
|
|
1589
|
-
`;
|
|
1590
|
-
const Toolbar = styled.div`
|
|
1591
|
-
display: flex;
|
|
1592
|
-
align-items: flex-end;
|
|
1593
|
-
gap: 12px;
|
|
1594
|
-
`;
|
|
1595
|
-
function UsersPage({ config }) {
|
|
1596
|
-
const rbac = useRBAC(PERMISSIONS.user);
|
|
1597
|
-
const qc = useQueryClient();
|
|
1598
|
-
const { toggleNotification } = useNotification();
|
|
1599
|
-
const banEnabled = hasPlugin(config, "admin");
|
|
1600
|
-
const emailVerificationEnabled = config.emailVerification.sendVerificationEmailEnabled;
|
|
1601
|
-
const twoFactorEnabled = hasPlugin(config, "two-factor");
|
|
1602
|
-
const [page, setPage] = useState(1);
|
|
1603
|
-
const [search, setSearch] = useState("");
|
|
1604
|
-
const [searchInput, setSearchInput] = useState("");
|
|
1605
|
-
const [selected, setSelected] = useState(/* @__PURE__ */ new Set());
|
|
1606
|
-
const [showCreate, setShowCreate] = useState(false);
|
|
1607
|
-
const [detailUserId, setDetailUserId] = useState(null);
|
|
1608
|
-
const [confirmDelete, setConfirmDelete] = useState(null);
|
|
1609
|
-
const [confirmDeleteMany, setConfirmDeleteMany] = useState(false);
|
|
1610
|
-
const [confirmBanMany, setConfirmBanMany] = useState(false);
|
|
1611
|
-
const offset = (page - 1) * PAGE_SIZE;
|
|
1612
|
-
const { data, isLoading, isError, error } = useUsers({
|
|
1613
|
-
limit: PAGE_SIZE,
|
|
1614
|
-
offset,
|
|
1615
|
-
search: search || void 0
|
|
1616
|
-
});
|
|
1617
|
-
const users = data?.users ?? [];
|
|
1618
|
-
const total = data?.total ?? 0;
|
|
1619
|
-
const pageCount = Math.ceil(total / PAGE_SIZE);
|
|
1620
|
-
const deleteMutation = useMutation({
|
|
1621
|
-
mutationFn: async (userId) => {
|
|
1622
|
-
const result = await client.dash.deleteUser(
|
|
1623
|
-
{},
|
|
1624
|
-
withContext({ userId }, getAuthHeaders())
|
|
1625
|
-
);
|
|
1626
|
-
if (result.error)
|
|
1627
|
-
throw new Error(result.error.message ?? "Delete failed");
|
|
1628
|
-
},
|
|
1629
|
-
onSuccess: () => {
|
|
1630
|
-
setConfirmDelete(null);
|
|
1631
|
-
qc.invalidateQueries({ queryKey: ["dash-users"] });
|
|
1632
|
-
qc.invalidateQueries({ queryKey: ["dash-user-stats"] });
|
|
1633
|
-
toggleNotification({ type: "success", message: "User deleted" });
|
|
1634
|
-
},
|
|
1635
|
-
onError: (err) => {
|
|
1636
|
-
toggleNotification({
|
|
1637
|
-
type: "danger",
|
|
1638
|
-
message: err.message ?? "Failed to delete user"
|
|
1639
|
-
});
|
|
1640
|
-
}
|
|
1641
|
-
});
|
|
1642
|
-
const deleteManyMutation = useMutation({
|
|
1643
|
-
mutationFn: async (userIds) => {
|
|
1644
|
-
const result = await client.dash.deleteManyUsers(
|
|
1645
|
-
{},
|
|
1646
|
-
withContext({ userIds }, getAuthHeaders())
|
|
1647
|
-
);
|
|
1648
|
-
if (result.error)
|
|
1649
|
-
throw new Error(result.error.message ?? "Delete failed");
|
|
1650
|
-
return result.data;
|
|
1651
|
-
},
|
|
1652
|
-
onSuccess: (_data, userIds) => {
|
|
1653
|
-
setConfirmDeleteMany(false);
|
|
1654
|
-
setSelected(/* @__PURE__ */ new Set());
|
|
1655
|
-
qc.invalidateQueries({ queryKey: ["dash-users"] });
|
|
1656
|
-
qc.invalidateQueries({ queryKey: ["dash-user-stats"] });
|
|
1657
|
-
toggleNotification({
|
|
1658
|
-
type: "success",
|
|
1659
|
-
message: `${userIds.length} user${userIds.length !== 1 ? "s" : ""} deleted`
|
|
1660
|
-
});
|
|
1661
|
-
},
|
|
1662
|
-
onError: (err) => {
|
|
1663
|
-
toggleNotification({
|
|
1664
|
-
type: "danger",
|
|
1665
|
-
message: err.message ?? "Failed to delete users"
|
|
1666
|
-
});
|
|
1667
|
-
}
|
|
1668
|
-
});
|
|
1669
|
-
const banManyMutation = useMutation({
|
|
1670
|
-
mutationFn: async (userIds) => {
|
|
1671
|
-
const result = await client.dash.banManyUsers(
|
|
1672
|
-
{},
|
|
1673
|
-
withContext({ userIds }, getAuthHeaders())
|
|
1674
|
-
);
|
|
1675
|
-
if (result.error) throw new Error(result.error.message ?? "Ban failed");
|
|
1676
|
-
return result.data;
|
|
1677
|
-
},
|
|
1678
|
-
onSuccess: (_data, userIds) => {
|
|
1679
|
-
setConfirmBanMany(false);
|
|
1680
|
-
setSelected(/* @__PURE__ */ new Set());
|
|
1681
|
-
qc.invalidateQueries({ queryKey: ["dash-users"] });
|
|
1682
|
-
toggleNotification({
|
|
1683
|
-
type: "success",
|
|
1684
|
-
message: `${userIds.length} user${userIds.length !== 1 ? "s" : ""} banned`
|
|
1685
|
-
});
|
|
1686
|
-
},
|
|
1687
|
-
onError: (err) => {
|
|
1688
|
-
toggleNotification({
|
|
1689
|
-
type: "danger",
|
|
1690
|
-
message: err.message ?? "Failed to ban users"
|
|
1691
|
-
});
|
|
1692
|
-
}
|
|
1693
|
-
});
|
|
1694
|
-
const toggleSelect = (id) => {
|
|
1695
|
-
setSelected((prev) => {
|
|
1696
|
-
const next = new Set(prev);
|
|
1697
|
-
if (next.has(id)) next.delete(id);
|
|
1698
|
-
else next.add(id);
|
|
1699
|
-
return next;
|
|
1700
|
-
});
|
|
1701
|
-
};
|
|
1702
|
-
const allSelected = users.length > 0 && users.every((u) => selected.has(u.id));
|
|
1703
|
-
const someSelected = selected.size > 0;
|
|
1704
|
-
const handleSelectAll = () => {
|
|
1705
|
-
if (allSelected) {
|
|
1706
|
-
setSelected(/* @__PURE__ */ new Set());
|
|
1707
|
-
} else {
|
|
1708
|
-
setSelected(new Set(users.map((u) => u.id)));
|
|
1709
|
-
}
|
|
1710
|
-
};
|
|
1711
|
-
const handleSearch = (e) => {
|
|
1712
|
-
e.preventDefault();
|
|
1713
|
-
setSearch(searchInput);
|
|
1714
|
-
setPage(1);
|
|
1715
|
-
};
|
|
1716
|
-
return /* @__PURE__ */ jsxs(Wrap, { "data-testid": "users-page", children: [
|
|
1717
|
-
/* @__PURE__ */ jsxs(PageHeader, { children: [
|
|
1718
|
-
/* @__PURE__ */ jsxs(TitleBlock, { children: [
|
|
1719
|
-
/* @__PURE__ */ jsx(PageTitle, { children: "Users" }),
|
|
1720
|
-
/* @__PURE__ */ jsxs(PageSubtitle, { children: [
|
|
1721
|
-
total.toLocaleString(),
|
|
1722
|
-
" total",
|
|
1723
|
-
data?.onlineUsers ? ` · ${data.onlineUsers} online` : ""
|
|
1724
|
-
] })
|
|
1725
|
-
] }),
|
|
1726
|
-
rbac.allowedActions.canCreate && /* @__PURE__ */ jsx(
|
|
1727
|
-
Button,
|
|
1728
|
-
{
|
|
1729
|
-
startIcon: /* @__PURE__ */ jsx(Plus, {}),
|
|
1730
|
-
onClick: () => setShowCreate(true),
|
|
1731
|
-
"data-testid": "create-user-btn",
|
|
1732
|
-
children: "Create user"
|
|
1733
|
-
}
|
|
1734
|
-
)
|
|
1735
|
-
] }),
|
|
1736
|
-
/* @__PURE__ */ jsxs(Toolbar, { children: [
|
|
1737
|
-
/* @__PURE__ */ jsx(SearchForm, { onSubmit: handleSearch, children: /* @__PURE__ */ jsx(
|
|
1738
|
-
Searchbar,
|
|
1739
|
-
{
|
|
1740
|
-
clearLabel: "Clear",
|
|
1741
|
-
name: "search",
|
|
1742
|
-
placeholder: "Search by email…",
|
|
1743
|
-
value: searchInput,
|
|
1744
|
-
onChange: (e) => setSearchInput(e.target.value),
|
|
1745
|
-
onClear: () => {
|
|
1746
|
-
setSearchInput("");
|
|
1747
|
-
setSearch("");
|
|
1748
|
-
setPage(1);
|
|
1749
|
-
},
|
|
1750
|
-
"data-testid": "user-search",
|
|
1751
|
-
children: "Search users"
|
|
1752
|
-
}
|
|
1753
|
-
) }),
|
|
1754
|
-
someSelected && /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
|
1755
|
-
rbac.allowedActions.canDelete && /* @__PURE__ */ jsxs(
|
|
1756
|
-
Button,
|
|
1757
|
-
{
|
|
1758
|
-
variant: "danger-light",
|
|
1759
|
-
size: "S",
|
|
1760
|
-
onClick: () => setConfirmDeleteMany(true),
|
|
1761
|
-
"data-testid": "delete-selected-btn",
|
|
1762
|
-
children: [
|
|
1763
|
-
"Delete ",
|
|
1764
|
-
selected.size,
|
|
1765
|
-
" selected"
|
|
1766
|
-
]
|
|
1767
|
-
}
|
|
1768
|
-
),
|
|
1769
|
-
banEnabled && rbac.allowedActions.canUpdate && /* @__PURE__ */ jsxs(
|
|
1770
|
-
Button,
|
|
1771
|
-
{
|
|
1772
|
-
variant: "secondary",
|
|
1773
|
-
size: "S",
|
|
1774
|
-
onClick: () => setConfirmBanMany(true),
|
|
1775
|
-
children: [
|
|
1776
|
-
"Ban ",
|
|
1777
|
-
selected.size,
|
|
1778
|
-
" selected"
|
|
1779
|
-
]
|
|
1780
|
-
}
|
|
1781
|
-
)
|
|
1782
|
-
] })
|
|
1783
|
-
] }),
|
|
1784
|
-
isError && /* @__PURE__ */ jsx("div", { style: { color: "#d02b20", fontSize: 12, padding: "8px 0" }, children: error?.message }),
|
|
1785
|
-
/* @__PURE__ */ jsx(TableCard, { children: isLoading ? /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsx(Loader, { children: "Loading users…" }) }) : /* @__PURE__ */ jsxs(Table, { children: [
|
|
1786
|
-
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
1787
|
-
(rbac.allowedActions.canDelete || rbac.allowedActions.canUpdate) && /* @__PURE__ */ jsx(THCheck, { children: /* @__PURE__ */ jsx(
|
|
1788
|
-
Checkbox,
|
|
1789
|
-
{
|
|
1790
|
-
checked: allSelected,
|
|
1791
|
-
onCheckedChange: handleSelectAll,
|
|
1792
|
-
"aria-label": "Select all"
|
|
1793
|
-
}
|
|
1794
|
-
) }),
|
|
1795
|
-
/* @__PURE__ */ jsx(TH, { children: "Name" }),
|
|
1796
|
-
/* @__PURE__ */ jsx(TH, { children: "Email" }),
|
|
1797
|
-
/* @__PURE__ */ jsx(TH, { children: "Status" }),
|
|
1798
|
-
/* @__PURE__ */ jsx(TH, { children: "Created" }),
|
|
1799
|
-
/* @__PURE__ */ jsx(THActions, {})
|
|
1800
|
-
] }) }),
|
|
1801
|
-
/* @__PURE__ */ jsx("tbody", { children: users.length === 0 ? /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx(
|
|
1802
|
-
TD,
|
|
1803
|
-
{
|
|
1804
|
-
colSpan: 6,
|
|
1805
|
-
style: {
|
|
1806
|
-
textAlign: "center",
|
|
1807
|
-
padding: "40px",
|
|
1808
|
-
color: "#8e8ea9"
|
|
1809
|
-
},
|
|
1810
|
-
"data-testid": "users-empty",
|
|
1811
|
-
children: search ? `No users matching "${search}"` : "No users found"
|
|
1812
|
-
}
|
|
1813
|
-
) }) : users.map((user, i) => /* @__PURE__ */ jsxs(
|
|
1814
|
-
TR,
|
|
1815
|
-
{
|
|
1816
|
-
$selected: selected.has(user.id),
|
|
1817
|
-
$i: i,
|
|
1818
|
-
"data-testid": "user-row",
|
|
1819
|
-
children: [
|
|
1820
|
-
(rbac.allowedActions.canDelete || rbac.allowedActions.canUpdate) && /* @__PURE__ */ jsx(TDCheck, { children: /* @__PURE__ */ jsx(
|
|
1821
|
-
Checkbox,
|
|
1822
|
-
{
|
|
1823
|
-
checked: selected.has(user.id),
|
|
1824
|
-
onCheckedChange: () => toggleSelect(user.id),
|
|
1825
|
-
"aria-label": `Select ${user.name}`
|
|
1826
|
-
}
|
|
1827
|
-
) }),
|
|
1828
|
-
/* @__PURE__ */ jsx(TD, { children: /* @__PURE__ */ jsxs(Flex, { alignItems: "center", gap: 2, children: [
|
|
1829
|
-
/* @__PURE__ */ jsx(
|
|
1830
|
-
Avatar,
|
|
1831
|
-
{
|
|
1832
|
-
name: user.name ?? "",
|
|
1833
|
-
src: user.image,
|
|
1834
|
-
size: 28
|
|
1835
|
-
}
|
|
1836
|
-
),
|
|
1837
|
-
/* @__PURE__ */ jsx(UserName, { children: user.name })
|
|
1838
|
-
] }) }),
|
|
1839
|
-
/* @__PURE__ */ jsx(TD, { children: /* @__PURE__ */ jsx(MonoText, { children: user.email }) }),
|
|
1840
|
-
/* @__PURE__ */ jsx(TD, { children: /* @__PURE__ */ jsxs(Flex, { gap: 1, children: [
|
|
1841
|
-
user.emailVerified ? /* @__PURE__ */ jsx(StatusChip, { $variant: "verified", children: "Verified" }) : /* @__PURE__ */ jsx(StatusChip, { $variant: "unverified", children: "Unverified" }),
|
|
1842
|
-
user.banned && /* @__PURE__ */ jsx(StatusChip, { $variant: "banned", children: "Banned" })
|
|
1843
|
-
] }) }),
|
|
1844
|
-
/* @__PURE__ */ jsx(TD, { children: /* @__PURE__ */ jsx(DateText, { children: new Date(user.createdAt).toLocaleDateString() }) }),
|
|
1845
|
-
/* @__PURE__ */ jsx(TDActions, { children: /* @__PURE__ */ jsxs(Flex, { gap: 1, justifyContent: "flex-end", children: [
|
|
1846
|
-
rbac.allowedActions.canUpdate && /* @__PURE__ */ jsx(
|
|
1847
|
-
IconButton,
|
|
1848
|
-
{
|
|
1849
|
-
label: "Edit user",
|
|
1850
|
-
onClick: () => setDetailUserId(user.id),
|
|
1851
|
-
"data-testid": "edit-user-btn",
|
|
1852
|
-
children: /* @__PURE__ */ jsx(Pencil, {})
|
|
1853
|
-
}
|
|
1854
|
-
),
|
|
1855
|
-
rbac.allowedActions.canDelete && /* @__PURE__ */ jsx(
|
|
1856
|
-
IconButton,
|
|
1857
|
-
{
|
|
1858
|
-
label: "Delete user",
|
|
1859
|
-
onClick: () => setConfirmDelete(user.id),
|
|
1860
|
-
"data-testid": "delete-user-btn",
|
|
1861
|
-
children: /* @__PURE__ */ jsx(Trash, {})
|
|
1862
|
-
}
|
|
1863
|
-
)
|
|
1864
|
-
] }) })
|
|
1865
|
-
]
|
|
1866
|
-
},
|
|
1867
|
-
user.id
|
|
1868
|
-
)) })
|
|
1869
|
-
] }) }),
|
|
1870
|
-
pageCount > 1 && /* @__PURE__ */ jsx(Flex, { justifyContent: "flex-end", children: /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
|
1871
|
-
/* @__PURE__ */ jsx(
|
|
1872
|
-
Button,
|
|
1873
|
-
{
|
|
1874
|
-
variant: "tertiary",
|
|
1875
|
-
size: "S",
|
|
1876
|
-
disabled: page === 1,
|
|
1877
|
-
onClick: () => setPage((p) => p - 1),
|
|
1878
|
-
children: "Previous"
|
|
1879
|
-
}
|
|
1880
|
-
),
|
|
1881
|
-
/* @__PURE__ */ jsx(
|
|
1882
|
-
Button,
|
|
1883
|
-
{
|
|
1884
|
-
variant: "tertiary",
|
|
1885
|
-
size: "S",
|
|
1886
|
-
disabled: page >= pageCount,
|
|
1887
|
-
onClick: () => setPage((p) => p + 1),
|
|
1888
|
-
children: "Next"
|
|
1889
|
-
}
|
|
1890
|
-
)
|
|
1891
|
-
] }) }),
|
|
1892
|
-
rbac.allowedActions.canCreate && showCreate && /* @__PURE__ */ jsx(CreateUserDialog, { onClose: () => setShowCreate(false) }),
|
|
1893
|
-
rbac.allowedActions.canUpdate && detailUserId && /* @__PURE__ */ jsx(
|
|
1894
|
-
UserDetailDrawer,
|
|
1895
|
-
{
|
|
1896
|
-
userId: detailUserId,
|
|
1897
|
-
banEnabled,
|
|
1898
|
-
emailVerificationEnabled,
|
|
1899
|
-
twoFactorEnabled,
|
|
1900
|
-
onClose: () => setDetailUserId(null)
|
|
1901
|
-
}
|
|
1902
|
-
),
|
|
1903
|
-
rbac.allowedActions.canDelete && confirmDelete && /* @__PURE__ */ jsx(
|
|
1904
|
-
ConfirmDialog,
|
|
1905
|
-
{
|
|
1906
|
-
title: "Delete user",
|
|
1907
|
-
message: "Are you sure you want to delete this user? This action cannot be undone.",
|
|
1908
|
-
confirmLabel: "Delete",
|
|
1909
|
-
loading: deleteMutation.isLoading,
|
|
1910
|
-
onConfirm: () => deleteMutation.mutate(confirmDelete),
|
|
1911
|
-
onCancel: () => setConfirmDelete(null)
|
|
1912
|
-
}
|
|
1913
|
-
),
|
|
1914
|
-
rbac.allowedActions.canDelete && confirmDeleteMany && /* @__PURE__ */ jsx(
|
|
1915
|
-
ConfirmDialog,
|
|
1916
|
-
{
|
|
1917
|
-
title: `Delete ${selected.size} user${selected.size !== 1 ? "s" : ""}`,
|
|
1918
|
-
message: `Are you sure you want to delete ${selected.size} user${selected.size !== 1 ? "s" : ""}? This action cannot be undone.`,
|
|
1919
|
-
confirmLabel: "Delete all",
|
|
1920
|
-
loading: deleteManyMutation.isLoading,
|
|
1921
|
-
onConfirm: () => deleteManyMutation.mutate([...selected]),
|
|
1922
|
-
onCancel: () => setConfirmDeleteMany(false)
|
|
1923
|
-
}
|
|
1924
|
-
),
|
|
1925
|
-
rbac.allowedActions.canUpdate && confirmBanMany && /* @__PURE__ */ jsx(
|
|
1926
|
-
ConfirmDialog,
|
|
1927
|
-
{
|
|
1928
|
-
title: `Ban ${selected.size} user${selected.size !== 1 ? "s" : ""}`,
|
|
1929
|
-
message: `Are you sure you want to ban ${selected.size} user${selected.size !== 1 ? "s" : ""}? They will be prevented from signing in.`,
|
|
1930
|
-
confirmLabel: "Ban all",
|
|
1931
|
-
variant: "danger",
|
|
1932
|
-
loading: banManyMutation.isLoading,
|
|
1933
|
-
onConfirm: () => banManyMutation.mutate([...selected]),
|
|
1934
|
-
onCancel: () => setConfirmBanMany(false)
|
|
1935
|
-
}
|
|
1936
|
-
)
|
|
1937
|
-
] });
|
|
1938
|
-
}
|
|
1939
|
-
function ProtectedUsersPage() {
|
|
1940
|
-
const { data: config, isError, error } = useDashConfig();
|
|
1941
|
-
if (isError) {
|
|
1942
|
-
return /* @__PURE__ */ jsx(Flex, { padding: 6, children: /* @__PURE__ */ jsx(
|
|
1943
|
-
Alert,
|
|
1944
|
-
{
|
|
1945
|
-
closeLabel: "Close",
|
|
1946
|
-
title: "Error loading configuration",
|
|
1947
|
-
variant: "danger",
|
|
1948
|
-
children: error.message
|
|
1949
|
-
}
|
|
1950
|
-
) });
|
|
1951
|
-
}
|
|
1952
|
-
if (!config) {
|
|
1953
|
-
return /* @__PURE__ */ jsx(Flex, { justifyContent: "center", alignItems: "center", padding: 12, children: /* @__PURE__ */ jsx(Loader, { children: "Loading user configuration…" }) });
|
|
1954
|
-
}
|
|
1955
|
-
return /* @__PURE__ */ jsx(
|
|
1956
|
-
Page.Protect,
|
|
1957
|
-
{
|
|
1958
|
-
permissions: PERMISSIONS.user.filter(
|
|
1959
|
-
(p) => p.action === `plugin::${PLUGIN_ID}.user.read`
|
|
1960
|
-
),
|
|
1961
|
-
children: /* @__PURE__ */ jsx(UsersPage, { config })
|
|
1962
|
-
}
|
|
1963
|
-
);
|
|
1964
|
-
}
|
|
1965
|
-
export {
|
|
1966
|
-
UsersPage,
|
|
1967
|
-
ProtectedUsersPage as default
|
|
1968
|
-
};
|