@strapi-community/plugin-better-auth-dashboard 1.0.0-alpha.9 → 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/README.md +65 -0
- package/dist/admin/Avatar-CdT7eBCh.js +39 -0
- package/dist/admin/Avatar-zlMTAZh3.mjs +40 -0
- package/dist/admin/Root-CgVBJuoM.mjs +365 -0
- package/dist/admin/Root-CsiOnzlB.js +367 -0
- 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-BCBu-0nr.js +457 -0
- package/dist/admin/index-BI2WIsds.mjs +458 -0
- 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 +2 -2
- package/dist/admin/index.mjs +2 -2
- 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-BogQah8f.js +756 -0
- package/dist/admin/useModelSchema-C6bxNjW4.mjs +755 -0
- package/dist/server/index.js +220 -10
- package/dist/server/index.mjs +220 -10
- package/package.json +5 -4
- package/dist/admin/Root-BYdYQBE5.mjs +0 -5742
- package/dist/admin/Root-D_vCtQoC.js +0 -5744
- package/dist/admin/index-BMTIuxZI.mjs +0 -96
- package/dist/admin/index-CkSsWnBx.js +0 -95
package/dist/server/index.js
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
3
|
const utils = require("@strapi/utils");
|
|
4
|
+
const strapi$1 = { "name": "better-auth-dashboard" };
|
|
5
|
+
const packageJson = {
|
|
6
|
+
strapi: strapi$1
|
|
7
|
+
};
|
|
8
|
+
const PLUGIN_ID = packageJson.strapi.name;
|
|
9
|
+
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
10
|
+
const provider = strapi2.admin.services.permission.actionProvider;
|
|
11
|
+
const candidates = [
|
|
12
|
+
{ resource: "user", uid: "plugin::better-auth.user" },
|
|
13
|
+
{ resource: "organization", uid: "plugin::better-auth.organization" }
|
|
14
|
+
];
|
|
15
|
+
const subjects = candidates.filter(({ uid }) => uid in strapi2.contentTypes);
|
|
16
|
+
for (const { resource, uid } of subjects) {
|
|
17
|
+
for (const action of ["create", "read", "update", "delete"]) {
|
|
18
|
+
const explorerActionId = `plugin::content-manager.explorer.${action}`;
|
|
19
|
+
const dashboardAction = provider.get(
|
|
20
|
+
`plugin::${PLUGIN_ID}.${resource}.${action}`
|
|
21
|
+
);
|
|
22
|
+
if (!dashboardAction) continue;
|
|
23
|
+
if (!dashboardAction.aliases) dashboardAction.aliases = [];
|
|
24
|
+
const alreadyAliased = dashboardAction.aliases.some(
|
|
25
|
+
({
|
|
26
|
+
actionId,
|
|
27
|
+
subjects: aliasSubjects
|
|
28
|
+
}) => actionId === explorerActionId && aliasSubjects?.includes(uid)
|
|
29
|
+
);
|
|
30
|
+
if (!alreadyAliased) {
|
|
31
|
+
dashboardAction.aliases.push({
|
|
32
|
+
actionId: explorerActionId,
|
|
33
|
+
subjects: [uid]
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const config = {
|
|
40
|
+
default: {},
|
|
41
|
+
validator(config2) {
|
|
42
|
+
if (config2.email_callback_url === void 0) return;
|
|
43
|
+
if (typeof config2.email_callback_url !== "string" || config2.email_callback_url.length === 0) {
|
|
44
|
+
throw new Error("email_callback_url must be a non-empty string");
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
new URL(config2.email_callback_url);
|
|
48
|
+
} catch {
|
|
49
|
+
throw new Error("email_callback_url must be a valid absolute URL");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
4
53
|
const DASHBOARD_API_KEY = process.env.BETTER_AUTH_DASHBOARD_SECRET || "strapi-internal-dashboard-key";
|
|
5
54
|
const DASH_CONTEXT_HEADER = "x-dash-context";
|
|
6
55
|
async function hashApiKey(value) {
|
|
@@ -113,7 +162,7 @@ const dbController = () => ({
|
|
|
113
162
|
start: (page - 1) * pageSize,
|
|
114
163
|
...populateArg ? { populate: populateArg } : {}
|
|
115
164
|
}),
|
|
116
|
-
|
|
165
|
+
service.count({ filters: filters ?? {} })
|
|
117
166
|
]);
|
|
118
167
|
ctx.body = {
|
|
119
168
|
results,
|
|
@@ -151,9 +200,157 @@ const dbController = () => ({
|
|
|
151
200
|
ctx.body = result;
|
|
152
201
|
}
|
|
153
202
|
});
|
|
203
|
+
const settingsController = () => ({
|
|
204
|
+
async get(ctx) {
|
|
205
|
+
ctx.body = strapi.config.get(`plugin::${PLUGIN_ID}`, {});
|
|
206
|
+
}
|
|
207
|
+
});
|
|
154
208
|
const controllers = {
|
|
155
209
|
"auth-controller": proxyController,
|
|
156
|
-
"db-controller": dbController
|
|
210
|
+
"db-controller": dbController,
|
|
211
|
+
"settings-controller": settingsController
|
|
212
|
+
};
|
|
213
|
+
const { PolicyError } = utils.errors;
|
|
214
|
+
const endpointsCategories = Object.freeze({
|
|
215
|
+
"/auth/dash/config": ["overview", "user", "organization"],
|
|
216
|
+
"/auth/dash/user-stats": ["overview"],
|
|
217
|
+
"/auth/dash/user-graph-data": ["overview"],
|
|
218
|
+
"/auth/dash/user-retention-data": ["overview"],
|
|
219
|
+
"/auth/dash/list-users": ["overview", "user"],
|
|
220
|
+
"/auth/dash/list-organization": ["overview", "organization"],
|
|
221
|
+
"/auth/dash/user": ["user"],
|
|
222
|
+
"/auth/dash/organization": ["organization"]
|
|
223
|
+
});
|
|
224
|
+
const types = Object.freeze({
|
|
225
|
+
POST: "read",
|
|
226
|
+
PUT: "update",
|
|
227
|
+
GET: "read",
|
|
228
|
+
DELETE: "delete"
|
|
229
|
+
});
|
|
230
|
+
const endpointsTypes = Object.freeze({
|
|
231
|
+
"/auth/dash/user-stats": "read",
|
|
232
|
+
"/auth/dash/user-graph-data": "read",
|
|
233
|
+
"/auth/dash/user-retention-data": "read",
|
|
234
|
+
"/auth/dash/list-users": "read",
|
|
235
|
+
"/auth/dash/list-organizations": "read",
|
|
236
|
+
"/auth/dash/organization/options": "read",
|
|
237
|
+
"/auth/dash/create-user": "create",
|
|
238
|
+
"/auth/dash/update-user": "update",
|
|
239
|
+
"/auth/dash/user": "read",
|
|
240
|
+
"/auth/dash/delete-user": "delete",
|
|
241
|
+
"/auth/dash/organization/create": "create",
|
|
242
|
+
"/auth/dash/organization/delete": "delete"
|
|
243
|
+
});
|
|
244
|
+
const hasPermission = async (ctx, _, { strapi: strapi2 }) => {
|
|
245
|
+
const { user, route } = ctx.state;
|
|
246
|
+
if (!user) return false;
|
|
247
|
+
const inherentType = types[route.method];
|
|
248
|
+
const determinedType = endpointsTypes?.[Object.keys(endpointsTypes)?.find(
|
|
249
|
+
(k) => ctx.originalUrl?.includes(k)
|
|
250
|
+
)];
|
|
251
|
+
const found = [];
|
|
252
|
+
for await (const role of user.roles) {
|
|
253
|
+
const categories = endpointsCategories[Object.keys(endpointsCategories).find(
|
|
254
|
+
(key) => ctx.originalUrl.startsWith(key)
|
|
255
|
+
)];
|
|
256
|
+
const permissions = await strapi2.documents("admin::permission").findMany({
|
|
257
|
+
filters: {
|
|
258
|
+
$or: (categories || []).map((cat) => ({
|
|
259
|
+
role: { id: role.id },
|
|
260
|
+
action: {
|
|
261
|
+
$startsWith: "plugin::better-auth-dashboard",
|
|
262
|
+
$containsi: cat,
|
|
263
|
+
$endsWith: determinedType || inherentType
|
|
264
|
+
}
|
|
265
|
+
}))
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
if (permissions?.length > 0) found.push(...permissions);
|
|
269
|
+
}
|
|
270
|
+
if (found.length <= 0) {
|
|
271
|
+
throw new PolicyError("You do not have permission to see this content.");
|
|
272
|
+
}
|
|
273
|
+
return true;
|
|
274
|
+
};
|
|
275
|
+
const policies = { "has-permission": hasPermission };
|
|
276
|
+
const ACTIONS = {
|
|
277
|
+
overview: [
|
|
278
|
+
{
|
|
279
|
+
section: "plugins",
|
|
280
|
+
subCategory: "overview",
|
|
281
|
+
displayName: "Read",
|
|
282
|
+
pluginName: PLUGIN_ID,
|
|
283
|
+
uid: "overview.read"
|
|
284
|
+
}
|
|
285
|
+
],
|
|
286
|
+
user: [
|
|
287
|
+
{
|
|
288
|
+
section: "plugins",
|
|
289
|
+
subCategory: "user",
|
|
290
|
+
displayName: "Create",
|
|
291
|
+
pluginName: PLUGIN_ID,
|
|
292
|
+
uid: "user.create"
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
section: "plugins",
|
|
296
|
+
subCategory: "user",
|
|
297
|
+
displayName: "Read",
|
|
298
|
+
pluginName: PLUGIN_ID,
|
|
299
|
+
uid: "user.read"
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
section: "plugins",
|
|
303
|
+
subCategory: "user",
|
|
304
|
+
displayName: "Update",
|
|
305
|
+
pluginName: PLUGIN_ID,
|
|
306
|
+
uid: "user.update"
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
section: "plugins",
|
|
310
|
+
subCategory: "user",
|
|
311
|
+
displayName: "Delete",
|
|
312
|
+
pluginName: PLUGIN_ID,
|
|
313
|
+
uid: "user.delete"
|
|
314
|
+
}
|
|
315
|
+
],
|
|
316
|
+
organization: [
|
|
317
|
+
{
|
|
318
|
+
section: "plugins",
|
|
319
|
+
subCategory: "organization",
|
|
320
|
+
displayName: "Create",
|
|
321
|
+
pluginName: PLUGIN_ID,
|
|
322
|
+
uid: "organization.create"
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
section: "plugins",
|
|
326
|
+
subCategory: "organization",
|
|
327
|
+
displayName: "Read",
|
|
328
|
+
pluginName: PLUGIN_ID,
|
|
329
|
+
uid: "organization.read"
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
section: "plugins",
|
|
333
|
+
subCategory: "organization",
|
|
334
|
+
displayName: "Update",
|
|
335
|
+
pluginName: PLUGIN_ID,
|
|
336
|
+
uid: "organization.update"
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
section: "plugins",
|
|
340
|
+
subCategory: "organization",
|
|
341
|
+
displayName: "Delete",
|
|
342
|
+
pluginName: PLUGIN_ID,
|
|
343
|
+
uid: "organization.delete"
|
|
344
|
+
}
|
|
345
|
+
]
|
|
346
|
+
};
|
|
347
|
+
const register = ({ strapi: strapi2 }) => {
|
|
348
|
+
const actionsToRegister = [...ACTIONS.overview, ...ACTIONS.user];
|
|
349
|
+
if (strapi2.plugin("better-auth").contentTypes?.organization)
|
|
350
|
+
actionsToRegister.push(...ACTIONS.organization);
|
|
351
|
+
strapi2.admin.services.permission.actionProvider.registerMany(
|
|
352
|
+
actionsToRegister
|
|
353
|
+
);
|
|
157
354
|
};
|
|
158
355
|
const adminRoutes = () => ({
|
|
159
356
|
type: "admin",
|
|
@@ -163,7 +360,7 @@ const adminRoutes = () => ({
|
|
|
163
360
|
path: "/auth/:path*",
|
|
164
361
|
handler: "auth-controller.handleAuthRequest",
|
|
165
362
|
config: {
|
|
166
|
-
policies: [],
|
|
363
|
+
policies: ["has-permission"],
|
|
167
364
|
prefix: ""
|
|
168
365
|
}
|
|
169
366
|
},
|
|
@@ -172,7 +369,7 @@ const adminRoutes = () => ({
|
|
|
172
369
|
path: "/auth/:path*",
|
|
173
370
|
handler: "auth-controller.handleAuthRequest",
|
|
174
371
|
config: {
|
|
175
|
-
policies: [],
|
|
372
|
+
policies: ["has-permission"],
|
|
176
373
|
prefix: ""
|
|
177
374
|
}
|
|
178
375
|
},
|
|
@@ -181,7 +378,7 @@ const adminRoutes = () => ({
|
|
|
181
378
|
path: "/auth/:path*",
|
|
182
379
|
handler: "auth-controller.handleAuthRequest",
|
|
183
380
|
config: {
|
|
184
|
-
policies: [],
|
|
381
|
+
policies: ["has-permission"],
|
|
185
382
|
prefix: ""
|
|
186
383
|
}
|
|
187
384
|
},
|
|
@@ -190,7 +387,7 @@ const adminRoutes = () => ({
|
|
|
190
387
|
path: "/auth/:path*",
|
|
191
388
|
handler: "auth-controller.handleAuthRequest",
|
|
192
389
|
config: {
|
|
193
|
-
policies: [],
|
|
390
|
+
policies: ["has-permission"],
|
|
194
391
|
prefix: ""
|
|
195
392
|
}
|
|
196
393
|
},
|
|
@@ -199,7 +396,7 @@ const adminRoutes = () => ({
|
|
|
199
396
|
path: "/auth/:path*",
|
|
200
397
|
handler: "auth-controller.handleAuthRequest",
|
|
201
398
|
config: {
|
|
202
|
-
policies: [],
|
|
399
|
+
policies: ["has-permission"],
|
|
203
400
|
prefix: ""
|
|
204
401
|
}
|
|
205
402
|
},
|
|
@@ -208,7 +405,7 @@ const adminRoutes = () => ({
|
|
|
208
405
|
path: "/better-auth-dashboard/db",
|
|
209
406
|
handler: "db-controller.list",
|
|
210
407
|
config: {
|
|
211
|
-
policies: [],
|
|
408
|
+
policies: ["has-permission"],
|
|
212
409
|
prefix: ""
|
|
213
410
|
}
|
|
214
411
|
},
|
|
@@ -217,7 +414,16 @@ const adminRoutes = () => ({
|
|
|
217
414
|
path: "/better-auth-dashboard/db/:documentId",
|
|
218
415
|
handler: "db-controller.update",
|
|
219
416
|
config: {
|
|
220
|
-
policies: [],
|
|
417
|
+
policies: ["has-permission"],
|
|
418
|
+
prefix: ""
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
method: "GET",
|
|
423
|
+
path: "/better-auth-dashboard/settings",
|
|
424
|
+
handler: "settings-controller.get",
|
|
425
|
+
config: {
|
|
426
|
+
policies: ["has-permission"],
|
|
221
427
|
prefix: ""
|
|
222
428
|
}
|
|
223
429
|
}
|
|
@@ -225,7 +431,11 @@ const adminRoutes = () => ({
|
|
|
225
431
|
});
|
|
226
432
|
const routes = { admin: adminRoutes };
|
|
227
433
|
const index = {
|
|
434
|
+
config,
|
|
228
435
|
controllers,
|
|
229
|
-
routes
|
|
436
|
+
routes,
|
|
437
|
+
policies,
|
|
438
|
+
register,
|
|
439
|
+
bootstrap
|
|
230
440
|
};
|
|
231
441
|
exports.default = index;
|
package/dist/server/index.mjs
CHANGED
|
@@ -1,4 +1,53 @@
|
|
|
1
1
|
import { errors } from "@strapi/utils";
|
|
2
|
+
const strapi$1 = { "name": "better-auth-dashboard" };
|
|
3
|
+
const packageJson = {
|
|
4
|
+
strapi: strapi$1
|
|
5
|
+
};
|
|
6
|
+
const PLUGIN_ID = packageJson.strapi.name;
|
|
7
|
+
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
8
|
+
const provider = strapi2.admin.services.permission.actionProvider;
|
|
9
|
+
const candidates = [
|
|
10
|
+
{ resource: "user", uid: "plugin::better-auth.user" },
|
|
11
|
+
{ resource: "organization", uid: "plugin::better-auth.organization" }
|
|
12
|
+
];
|
|
13
|
+
const subjects = candidates.filter(({ uid }) => uid in strapi2.contentTypes);
|
|
14
|
+
for (const { resource, uid } of subjects) {
|
|
15
|
+
for (const action of ["create", "read", "update", "delete"]) {
|
|
16
|
+
const explorerActionId = `plugin::content-manager.explorer.${action}`;
|
|
17
|
+
const dashboardAction = provider.get(
|
|
18
|
+
`plugin::${PLUGIN_ID}.${resource}.${action}`
|
|
19
|
+
);
|
|
20
|
+
if (!dashboardAction) continue;
|
|
21
|
+
if (!dashboardAction.aliases) dashboardAction.aliases = [];
|
|
22
|
+
const alreadyAliased = dashboardAction.aliases.some(
|
|
23
|
+
({
|
|
24
|
+
actionId,
|
|
25
|
+
subjects: aliasSubjects
|
|
26
|
+
}) => actionId === explorerActionId && aliasSubjects?.includes(uid)
|
|
27
|
+
);
|
|
28
|
+
if (!alreadyAliased) {
|
|
29
|
+
dashboardAction.aliases.push({
|
|
30
|
+
actionId: explorerActionId,
|
|
31
|
+
subjects: [uid]
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const config = {
|
|
38
|
+
default: {},
|
|
39
|
+
validator(config2) {
|
|
40
|
+
if (config2.email_callback_url === void 0) return;
|
|
41
|
+
if (typeof config2.email_callback_url !== "string" || config2.email_callback_url.length === 0) {
|
|
42
|
+
throw new Error("email_callback_url must be a non-empty string");
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
new URL(config2.email_callback_url);
|
|
46
|
+
} catch {
|
|
47
|
+
throw new Error("email_callback_url must be a valid absolute URL");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
2
51
|
const DASHBOARD_API_KEY = process.env.BETTER_AUTH_DASHBOARD_SECRET || "strapi-internal-dashboard-key";
|
|
3
52
|
const DASH_CONTEXT_HEADER = "x-dash-context";
|
|
4
53
|
async function hashApiKey(value) {
|
|
@@ -111,7 +160,7 @@ const dbController = () => ({
|
|
|
111
160
|
start: (page - 1) * pageSize,
|
|
112
161
|
...populateArg ? { populate: populateArg } : {}
|
|
113
162
|
}),
|
|
114
|
-
|
|
163
|
+
service.count({ filters: filters ?? {} })
|
|
115
164
|
]);
|
|
116
165
|
ctx.body = {
|
|
117
166
|
results,
|
|
@@ -149,9 +198,157 @@ const dbController = () => ({
|
|
|
149
198
|
ctx.body = result;
|
|
150
199
|
}
|
|
151
200
|
});
|
|
201
|
+
const settingsController = () => ({
|
|
202
|
+
async get(ctx) {
|
|
203
|
+
ctx.body = strapi.config.get(`plugin::${PLUGIN_ID}`, {});
|
|
204
|
+
}
|
|
205
|
+
});
|
|
152
206
|
const controllers = {
|
|
153
207
|
"auth-controller": proxyController,
|
|
154
|
-
"db-controller": dbController
|
|
208
|
+
"db-controller": dbController,
|
|
209
|
+
"settings-controller": settingsController
|
|
210
|
+
};
|
|
211
|
+
const { PolicyError } = errors;
|
|
212
|
+
const endpointsCategories = Object.freeze({
|
|
213
|
+
"/auth/dash/config": ["overview", "user", "organization"],
|
|
214
|
+
"/auth/dash/user-stats": ["overview"],
|
|
215
|
+
"/auth/dash/user-graph-data": ["overview"],
|
|
216
|
+
"/auth/dash/user-retention-data": ["overview"],
|
|
217
|
+
"/auth/dash/list-users": ["overview", "user"],
|
|
218
|
+
"/auth/dash/list-organization": ["overview", "organization"],
|
|
219
|
+
"/auth/dash/user": ["user"],
|
|
220
|
+
"/auth/dash/organization": ["organization"]
|
|
221
|
+
});
|
|
222
|
+
const types = Object.freeze({
|
|
223
|
+
POST: "read",
|
|
224
|
+
PUT: "update",
|
|
225
|
+
GET: "read",
|
|
226
|
+
DELETE: "delete"
|
|
227
|
+
});
|
|
228
|
+
const endpointsTypes = Object.freeze({
|
|
229
|
+
"/auth/dash/user-stats": "read",
|
|
230
|
+
"/auth/dash/user-graph-data": "read",
|
|
231
|
+
"/auth/dash/user-retention-data": "read",
|
|
232
|
+
"/auth/dash/list-users": "read",
|
|
233
|
+
"/auth/dash/list-organizations": "read",
|
|
234
|
+
"/auth/dash/organization/options": "read",
|
|
235
|
+
"/auth/dash/create-user": "create",
|
|
236
|
+
"/auth/dash/update-user": "update",
|
|
237
|
+
"/auth/dash/user": "read",
|
|
238
|
+
"/auth/dash/delete-user": "delete",
|
|
239
|
+
"/auth/dash/organization/create": "create",
|
|
240
|
+
"/auth/dash/organization/delete": "delete"
|
|
241
|
+
});
|
|
242
|
+
const hasPermission = async (ctx, _, { strapi: strapi2 }) => {
|
|
243
|
+
const { user, route } = ctx.state;
|
|
244
|
+
if (!user) return false;
|
|
245
|
+
const inherentType = types[route.method];
|
|
246
|
+
const determinedType = endpointsTypes?.[Object.keys(endpointsTypes)?.find(
|
|
247
|
+
(k) => ctx.originalUrl?.includes(k)
|
|
248
|
+
)];
|
|
249
|
+
const found = [];
|
|
250
|
+
for await (const role of user.roles) {
|
|
251
|
+
const categories = endpointsCategories[Object.keys(endpointsCategories).find(
|
|
252
|
+
(key) => ctx.originalUrl.startsWith(key)
|
|
253
|
+
)];
|
|
254
|
+
const permissions = await strapi2.documents("admin::permission").findMany({
|
|
255
|
+
filters: {
|
|
256
|
+
$or: (categories || []).map((cat) => ({
|
|
257
|
+
role: { id: role.id },
|
|
258
|
+
action: {
|
|
259
|
+
$startsWith: "plugin::better-auth-dashboard",
|
|
260
|
+
$containsi: cat,
|
|
261
|
+
$endsWith: determinedType || inherentType
|
|
262
|
+
}
|
|
263
|
+
}))
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
if (permissions?.length > 0) found.push(...permissions);
|
|
267
|
+
}
|
|
268
|
+
if (found.length <= 0) {
|
|
269
|
+
throw new PolicyError("You do not have permission to see this content.");
|
|
270
|
+
}
|
|
271
|
+
return true;
|
|
272
|
+
};
|
|
273
|
+
const policies = { "has-permission": hasPermission };
|
|
274
|
+
const ACTIONS = {
|
|
275
|
+
overview: [
|
|
276
|
+
{
|
|
277
|
+
section: "plugins",
|
|
278
|
+
subCategory: "overview",
|
|
279
|
+
displayName: "Read",
|
|
280
|
+
pluginName: PLUGIN_ID,
|
|
281
|
+
uid: "overview.read"
|
|
282
|
+
}
|
|
283
|
+
],
|
|
284
|
+
user: [
|
|
285
|
+
{
|
|
286
|
+
section: "plugins",
|
|
287
|
+
subCategory: "user",
|
|
288
|
+
displayName: "Create",
|
|
289
|
+
pluginName: PLUGIN_ID,
|
|
290
|
+
uid: "user.create"
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
section: "plugins",
|
|
294
|
+
subCategory: "user",
|
|
295
|
+
displayName: "Read",
|
|
296
|
+
pluginName: PLUGIN_ID,
|
|
297
|
+
uid: "user.read"
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
section: "plugins",
|
|
301
|
+
subCategory: "user",
|
|
302
|
+
displayName: "Update",
|
|
303
|
+
pluginName: PLUGIN_ID,
|
|
304
|
+
uid: "user.update"
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
section: "plugins",
|
|
308
|
+
subCategory: "user",
|
|
309
|
+
displayName: "Delete",
|
|
310
|
+
pluginName: PLUGIN_ID,
|
|
311
|
+
uid: "user.delete"
|
|
312
|
+
}
|
|
313
|
+
],
|
|
314
|
+
organization: [
|
|
315
|
+
{
|
|
316
|
+
section: "plugins",
|
|
317
|
+
subCategory: "organization",
|
|
318
|
+
displayName: "Create",
|
|
319
|
+
pluginName: PLUGIN_ID,
|
|
320
|
+
uid: "organization.create"
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
section: "plugins",
|
|
324
|
+
subCategory: "organization",
|
|
325
|
+
displayName: "Read",
|
|
326
|
+
pluginName: PLUGIN_ID,
|
|
327
|
+
uid: "organization.read"
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
section: "plugins",
|
|
331
|
+
subCategory: "organization",
|
|
332
|
+
displayName: "Update",
|
|
333
|
+
pluginName: PLUGIN_ID,
|
|
334
|
+
uid: "organization.update"
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
section: "plugins",
|
|
338
|
+
subCategory: "organization",
|
|
339
|
+
displayName: "Delete",
|
|
340
|
+
pluginName: PLUGIN_ID,
|
|
341
|
+
uid: "organization.delete"
|
|
342
|
+
}
|
|
343
|
+
]
|
|
344
|
+
};
|
|
345
|
+
const register = ({ strapi: strapi2 }) => {
|
|
346
|
+
const actionsToRegister = [...ACTIONS.overview, ...ACTIONS.user];
|
|
347
|
+
if (strapi2.plugin("better-auth").contentTypes?.organization)
|
|
348
|
+
actionsToRegister.push(...ACTIONS.organization);
|
|
349
|
+
strapi2.admin.services.permission.actionProvider.registerMany(
|
|
350
|
+
actionsToRegister
|
|
351
|
+
);
|
|
155
352
|
};
|
|
156
353
|
const adminRoutes = () => ({
|
|
157
354
|
type: "admin",
|
|
@@ -161,7 +358,7 @@ const adminRoutes = () => ({
|
|
|
161
358
|
path: "/auth/:path*",
|
|
162
359
|
handler: "auth-controller.handleAuthRequest",
|
|
163
360
|
config: {
|
|
164
|
-
policies: [],
|
|
361
|
+
policies: ["has-permission"],
|
|
165
362
|
prefix: ""
|
|
166
363
|
}
|
|
167
364
|
},
|
|
@@ -170,7 +367,7 @@ const adminRoutes = () => ({
|
|
|
170
367
|
path: "/auth/:path*",
|
|
171
368
|
handler: "auth-controller.handleAuthRequest",
|
|
172
369
|
config: {
|
|
173
|
-
policies: [],
|
|
370
|
+
policies: ["has-permission"],
|
|
174
371
|
prefix: ""
|
|
175
372
|
}
|
|
176
373
|
},
|
|
@@ -179,7 +376,7 @@ const adminRoutes = () => ({
|
|
|
179
376
|
path: "/auth/:path*",
|
|
180
377
|
handler: "auth-controller.handleAuthRequest",
|
|
181
378
|
config: {
|
|
182
|
-
policies: [],
|
|
379
|
+
policies: ["has-permission"],
|
|
183
380
|
prefix: ""
|
|
184
381
|
}
|
|
185
382
|
},
|
|
@@ -188,7 +385,7 @@ const adminRoutes = () => ({
|
|
|
188
385
|
path: "/auth/:path*",
|
|
189
386
|
handler: "auth-controller.handleAuthRequest",
|
|
190
387
|
config: {
|
|
191
|
-
policies: [],
|
|
388
|
+
policies: ["has-permission"],
|
|
192
389
|
prefix: ""
|
|
193
390
|
}
|
|
194
391
|
},
|
|
@@ -197,7 +394,7 @@ const adminRoutes = () => ({
|
|
|
197
394
|
path: "/auth/:path*",
|
|
198
395
|
handler: "auth-controller.handleAuthRequest",
|
|
199
396
|
config: {
|
|
200
|
-
policies: [],
|
|
397
|
+
policies: ["has-permission"],
|
|
201
398
|
prefix: ""
|
|
202
399
|
}
|
|
203
400
|
},
|
|
@@ -206,7 +403,7 @@ const adminRoutes = () => ({
|
|
|
206
403
|
path: "/better-auth-dashboard/db",
|
|
207
404
|
handler: "db-controller.list",
|
|
208
405
|
config: {
|
|
209
|
-
policies: [],
|
|
406
|
+
policies: ["has-permission"],
|
|
210
407
|
prefix: ""
|
|
211
408
|
}
|
|
212
409
|
},
|
|
@@ -215,7 +412,16 @@ const adminRoutes = () => ({
|
|
|
215
412
|
path: "/better-auth-dashboard/db/:documentId",
|
|
216
413
|
handler: "db-controller.update",
|
|
217
414
|
config: {
|
|
218
|
-
policies: [],
|
|
415
|
+
policies: ["has-permission"],
|
|
416
|
+
prefix: ""
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
method: "GET",
|
|
421
|
+
path: "/better-auth-dashboard/settings",
|
|
422
|
+
handler: "settings-controller.get",
|
|
423
|
+
config: {
|
|
424
|
+
policies: ["has-permission"],
|
|
219
425
|
prefix: ""
|
|
220
426
|
}
|
|
221
427
|
}
|
|
@@ -223,8 +429,12 @@ const adminRoutes = () => ({
|
|
|
223
429
|
});
|
|
224
430
|
const routes = { admin: adminRoutes };
|
|
225
431
|
const index = {
|
|
432
|
+
config,
|
|
226
433
|
controllers,
|
|
227
|
-
routes
|
|
434
|
+
routes,
|
|
435
|
+
policies,
|
|
436
|
+
register,
|
|
437
|
+
bootstrap
|
|
228
438
|
};
|
|
229
439
|
export {
|
|
230
440
|
index as default
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi-community/plugin-better-auth-dashboard",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
4
|
"description": "Better Auth dashboard for the Strapi admin panel",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"@biomejs/biome": "^2.3.11",
|
|
43
43
|
"@playwright/test": "^1.49.0",
|
|
44
44
|
"@strapi/sdk-plugin": "^6.0.0",
|
|
45
|
-
"@strapi/strapi": "5.
|
|
46
|
-
"@strapi/typescript-utils": "5.
|
|
45
|
+
"@strapi/strapi": "5.60.0",
|
|
46
|
+
"@strapi/typescript-utils": "5.60.0",
|
|
47
47
|
"@types/koa": "^3.0.1",
|
|
48
48
|
"@types/node": "^22",
|
|
49
49
|
"@types/react": "^18.0.0",
|
|
@@ -64,7 +64,8 @@
|
|
|
64
64
|
"react-intl": "^6.0.0 || ^7.0.0",
|
|
65
65
|
"react-query": "^3.0.0",
|
|
66
66
|
"styled-components": "^6.0.0",
|
|
67
|
-
"
|
|
67
|
+
"react-router-dom": "^6.0.0",
|
|
68
|
+
"@strapi-community/plugin-better-auth": "^1.0.0-beta.8"
|
|
68
69
|
},
|
|
69
70
|
"strapi": {
|
|
70
71
|
"kind": "plugin",
|