@protobase/server 0.3.5 → 0.4.1
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/better-auth/admin-only.js +13 -0
- package/dist/better-auth/create-auth.d.ts +2357 -30
- package/dist/better-auth/create-auth.js +70 -24
- package/dist/better-auth/operator-provider.d.ts +29 -0
- package/dist/better-auth/operator-provider.js +130 -0
- package/dist/better-auth/parse-roles.d.ts +7 -0
- package/dist/better-auth/parse-roles.js +12 -0
- package/dist/better-auth/policy-plugin.js +142 -0
- package/dist/better-auth/policy-store.js +65 -0
- package/dist/better-auth/sign-in-enforcement.js +65 -0
- package/dist/better-auth/sign-in-mail.js +78 -0
- package/dist/better-auth/sign-in-policy.d.ts +49 -0
- package/dist/better-auth/sign-in-policy.js +83 -0
- package/dist/better-auth/staff-checks.js +65 -0
- package/dist/better-auth/staff-log.d.ts +14 -0
- package/dist/better-auth/staff-log.js +96 -0
- package/dist/better-auth/staff-plugin.js +61 -0
- package/dist/better-auth/staff-sign-in-endpoints.js +162 -0
- package/dist/better-auth/status-route.js +23 -8
- package/dist/better-auth/tokens.js +1 -1
- package/dist/better-auth/two-factor-challenge.js +23 -0
- package/dist/better-auth/users.d.ts +5 -7
- package/dist/better-auth/users.js +3 -10
- package/dist/index.d.ts +6 -2
- package/dist/index.js +5 -2
- package/package.json +6 -4
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { parseRoles } from "./parse-roles.js";
|
|
2
|
+
import { APIError, createAuthMiddleware, sessionMiddleware } from "better-auth/api";
|
|
3
|
+
//#region src/better-auth/admin-only.ts
|
|
4
|
+
/** Lets a request through only with the session of an admin; others get `403 ADMIN_ONLY` with `message`. */
|
|
5
|
+
const adminOnly = (message) => createAuthMiddleware({ use: [sessionMiddleware] }, async (ctx) => {
|
|
6
|
+
if (!parseRoles(ctx.context.session.user.role).includes("admin")) throw new APIError("FORBIDDEN", {
|
|
7
|
+
code: "ADMIN_ONLY",
|
|
8
|
+
message
|
|
9
|
+
});
|
|
10
|
+
return { session: ctx.context.session };
|
|
11
|
+
});
|
|
12
|
+
//#endregion
|
|
13
|
+
export { adminOnly };
|