@protobase/server 0.1.3 → 0.1.5
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.
|
@@ -31,7 +31,14 @@ export type CreateAuthOptions = {
|
|
|
31
31
|
* Default none.
|
|
32
32
|
*/
|
|
33
33
|
socialProviders?: BetterAuthOptions['socialProviders'];
|
|
34
|
+
/** Encrypt the OAuth access, refresh and ID tokens Better Auth stores for social sign-ins, with `secret`. Default off. */
|
|
35
|
+
encryptOAuthTokens?: boolean;
|
|
36
|
+
/** Runs after a user is created, by any route: `createUser`, an admin, or a social sign-up. Default none. */
|
|
37
|
+
onUserCreated?: UserCreatedHook;
|
|
34
38
|
};
|
|
39
|
+
type UserCreateHooks = NonNullable<NonNullable<NonNullable<BetterAuthOptions['databaseHooks']>['user']>['create']>;
|
|
40
|
+
/** Better Auth's `databaseHooks.user.create.after`: the created user (with its `role`) and the request context, `null` outside a request. */
|
|
41
|
+
export type UserCreatedHook = NonNullable<UserCreateHooks['after']>;
|
|
35
42
|
/** The configured roles with `admin` first; `admin` is added when missing. */
|
|
36
43
|
export declare const normalizeRoles: (roles?: string[]) => string[];
|
|
37
44
|
export declare const createAuth: (options: CreateAuthOptions) => import("better-auth").Auth<{
|
|
@@ -1181,6 +1188,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
|
|
|
1181
1188
|
databaseHooks: {
|
|
1182
1189
|
user: {
|
|
1183
1190
|
create: {
|
|
1191
|
+
after?: ((user: import("better-auth").User & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<void>) | undefined;
|
|
1184
1192
|
before: (user: {
|
|
1185
1193
|
id: string;
|
|
1186
1194
|
createdAt: Date;
|
|
@@ -1224,6 +1232,9 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
|
|
|
1224
1232
|
handler: () => void;
|
|
1225
1233
|
};
|
|
1226
1234
|
};
|
|
1235
|
+
account?: {
|
|
1236
|
+
encryptOAuthTokens: true;
|
|
1237
|
+
} | undefined;
|
|
1227
1238
|
socialProviders?: import("better-auth").SocialProviders | undefined;
|
|
1228
1239
|
database: any;
|
|
1229
1240
|
baseURL: string;
|
|
@@ -44,6 +44,7 @@ const betterAuthOptions = (options, { roles, defaultRole, mailer }) => {
|
|
|
44
44
|
...mailer && passwordResetOptions(mailer)
|
|
45
45
|
},
|
|
46
46
|
...options.socialProviders && { socialProviders: options.socialProviders },
|
|
47
|
+
...options.encryptOAuthTokens && { account: { encryptOAuthTokens: true } },
|
|
47
48
|
plugins: [admin({
|
|
48
49
|
defaultRole: defaultRole ?? "unassigned",
|
|
49
50
|
roles: Object.fromEntries(roles.map((role) => [role, role === "admin" ? adminAc : userAc]))
|
|
@@ -56,12 +57,15 @@ const betterAuthOptions = (options, { roles, defaultRole, mailer }) => {
|
|
|
56
57
|
role: user.role
|
|
57
58
|
})
|
|
58
59
|
} })],
|
|
59
|
-
databaseHooks: { user: { create: {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
databaseHooks: { user: { create: {
|
|
61
|
+
before: async (user) => {
|
|
62
|
+
const given = String(user.role ?? "").split(",").map((name) => name.trim()).filter(Boolean);
|
|
63
|
+
const unknown = given.find((name) => !roles.includes(name));
|
|
64
|
+
if (given.length === 0 || unknown !== void 0) throw new APIError("BAD_REQUEST", { message: `Choose a role for the new user: ${roles.join(", ")}` });
|
|
65
|
+
return { data: user };
|
|
66
|
+
},
|
|
67
|
+
...options.onUserCreated && { after: options.onUserCreated }
|
|
68
|
+
} } },
|
|
65
69
|
rateLimit: {
|
|
66
70
|
enabled: true,
|
|
67
71
|
window: 60,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AdminAuth, CreateAuthOptions, createAuth, normalizeRoles } from "./better-auth/create-auth.js";
|
|
1
|
+
import { AdminAuth, CreateAuthOptions, UserCreatedHook, createAuth, normalizeRoles } from "./better-auth/create-auth.js";
|
|
2
2
|
import { ResourceSource, configExports } from "./resource-source.js";
|
|
3
3
|
import { Admin, AdminOptions, AuditEvent, AuditQueue, Authenticator, PipelineHook, ScanGuardMode, Session, TenantValue, User, ViewSource, WriteEvent, WriteOperation } from "./types.js";
|
|
4
4
|
import { CreateAdminInput, createAdmin } from "./create-admin.js";
|
|
@@ -8,4 +8,4 @@ import { HttpProblem, badRequest, forbidden, notFound, unauthorized } from "./pr
|
|
|
8
8
|
import { BetterAuthAuthenticatorOptions, betterAuthAuthenticator } from "./better-auth/authenticator.js";
|
|
9
9
|
import { NewUser, StoredUser, createUser, deleteUser, hasUsers, listUsers, parseRoles, roleChoices, setUserBanned, setUserRole } from "./better-auth/users.js";
|
|
10
10
|
import { IssueTokenOptions, issueToken, maxTokenTtlSeconds } from "./better-auth/tokens.js";
|
|
11
|
-
export { type Admin, type AdminAuth, type AdminOptions, type AuditEvent, type AuditQueue, type Authenticator, type BetterAuthAuthenticatorOptions, type CreateAdminInput, type CreateAuthOptions, HttpProblem, type IssueTokenOptions, type JwtOptions, type NewUser, type PipelineHook, type ResourceSource, type ScanGuardMode, type Session, type StoredUser, type TenantValue, type User, type ViewSource, type WriteEvent, type WriteOperation, badRequest, betterAuthAuthenticator, configExports, consoleAuditQueue, createAdmin, createAuth, createUser, deleteUser, forbidden, hasUsers, issueToken, jwtAuthenticator, listUsers, maxTokenTtlSeconds, normalizeRoles, notFound, parseRoles, roleChoices, setUserBanned, setUserRole, unauthorized };
|
|
11
|
+
export { type Admin, type AdminAuth, type AdminOptions, type AuditEvent, type AuditQueue, type Authenticator, type BetterAuthAuthenticatorOptions, type CreateAdminInput, type CreateAuthOptions, HttpProblem, type IssueTokenOptions, type JwtOptions, type NewUser, type PipelineHook, type ResourceSource, type ScanGuardMode, type Session, type StoredUser, type TenantValue, type User, type UserCreatedHook, type ViewSource, type WriteEvent, type WriteOperation, badRequest, betterAuthAuthenticator, configExports, consoleAuditQueue, createAdmin, createAuth, createUser, deleteUser, forbidden, hasUsers, issueToken, jwtAuthenticator, listUsers, maxTokenTtlSeconds, normalizeRoles, notFound, parseRoles, roleChoices, setUserBanned, setUserRole, unauthorized };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "The Protobase REST API as a Hono app, with Better Auth sign-in.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"kysely": "^0.29.6",
|
|
33
33
|
"nodemailer": "^10.0.16",
|
|
34
34
|
"zod": "^4.6.5",
|
|
35
|
-
"@protobase/
|
|
36
|
-
"@protobase/
|
|
37
|
-
"@protobase/schema": "0.1.
|
|
35
|
+
"@protobase/query": "0.1.5",
|
|
36
|
+
"@protobase/layout": "0.1.5",
|
|
37
|
+
"@protobase/schema": "0.1.5"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsdown"
|