@vite-hub/auth 0.6.1 → 0.8.0
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 +86 -12
- package/dist/{abilities-BYOcyQ9B.d.ts → abilities-IOwpkcz4.d.ts} +1 -1
- package/dist/abilities.d.ts +1 -1
- package/dist/{ability-error-D3-u8k1A.js → ability-error-DgR91Jwc.js} +1 -1
- package/dist/{access-pages-9aKr6z-k.js → access-pages-C69nwa99.js} +10 -3
- package/dist/agent.d.ts +2 -3
- package/dist/agent.js +31 -12
- package/dist/{auth-instance-BWiRS9QZ.js → auth-instance-WeEK1zDd.js} +174 -64
- package/dist/{cli-C5pAfY4x.d.ts → cli-DL7uCAvz.d.ts} +15 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/client-extension-BgUlm6hy.d.ts +33 -0
- package/dist/client-request-B1DCz3a9.js +29 -0
- package/dist/{console-runtime-DMH1I2fl.d.ts → console-runtime-C71weVrt.d.ts} +1 -1
- package/dist/{console-runtime-CaIXVtB_.js → console-runtime-Dk3j4Jmz.js} +5 -3
- package/dist/console-runtime.d.ts +2 -2
- package/dist/console-runtime.js +1 -1
- package/dist/console.d.ts +1 -1
- package/dist/database-options-Cms7BI3c.js +36 -0
- package/dist/{database-schema-options-peXHNLkJ.js → database-schema-options-IlHEeUBK.js} +1 -1
- package/dist/database.d.ts +1 -1
- package/dist/database.js +13 -8
- package/dist/{definition-BypPLIbI.js → definition-EpeI5LUG.js} +18 -4
- package/dist/{error-diagnostics-CUPwukgE.js → error-diagnostics-DZHuHXPP.js} +46 -5
- package/dist/{events-BXU1_9mc.js → events-Cm7Iwq47.js} +1 -1
- package/dist/extension-BWmjJhoN.d.ts +59 -0
- package/dist/extension-mCx4TrsO.js +133 -0
- package/dist/forward.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +5 -3
- package/dist/internal/server.d.ts +3 -3
- package/dist/internal/server.js +5 -4
- package/dist/{mcp-config-C7srUMIZ.js → mcp-config-Bbr8kQxm.js} +9 -1
- package/dist/{mcp-token-CuqdbBy8.js → mcp-token-BleQZK6H.js} +52 -11
- package/dist/{mcp-token-CmQbXbTu.d.ts → mcp-token-CxpopXmK.d.ts} +5 -2
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +27 -6
- package/dist/{members-CwPIx10t.js → members-7OMdqha_.js} +188 -152
- package/dist/nuxt.d.ts +4 -14
- package/dist/nuxt.js +53 -20
- package/dist/{own-access-BNcxKrDl.d.ts → own-access-CGiai2L3.d.ts} +1 -1
- package/dist/{page-tools-shared-CtoKaNQZ.js → page-tools-shared-dVJBPPTk.js} +8 -0
- package/dist/presets.js +1 -1
- package/dist/roles-BGi8CyBG.js +17 -0
- package/dist/runtime/client-request-plugin.d.ts +2 -1
- package/dist/runtime/client-request-plugin.js +8 -5
- package/dist/runtime/console.d.ts +1 -1
- package/dist/runtime/console.js +2 -2
- package/dist/runtime/empty-abilities.d.ts +1 -1
- package/dist/runtime/empty-client.d.ts +3 -0
- package/dist/runtime/empty-client.js +3 -1
- package/dist/runtime/empty-definition.d.ts +1 -1
- package/dist/runtime/server.d.ts +4 -3
- package/dist/runtime/server.js +7 -4
- package/dist/runtime/vue-nuxt.js +27 -11
- package/dist/schema.d.ts +32 -14
- package/dist/schema.js +21 -14
- package/dist/{server-Iru6jcnW.js → server-5t-HA7I1.js} +80 -328
- package/dist/{server-C4Kni3Vj.d.ts → server-DyP1v-sZ.d.ts} +39 -7
- package/dist/{server-BHniJi2m.d.ts → server-mmp8EfcE.d.ts} +4 -2
- package/dist/server.d.ts +6 -3
- package/dist/server.js +9 -3
- package/dist/{session-cookies-fR6Pv4kD.js → session-cookies-BNtY3hMp.js} +4 -16
- package/dist/{set-cookie-DVfi-nJX.js → set-cookie-Bva-P-_C.js} +1 -1
- package/dist/{table-specs-CCSY4tiS.js → table-specs-Bm7QJCbu.js} +1 -1
- package/dist/{table-specs-P4LvbOlX.d.ts → table-specs-BxKeFD_y.d.ts} +5 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +2 -2
- package/dist/{types-DmH31d2t.d.ts → types-CnO5bHEF.d.ts} +40 -6
- package/dist/{vite-CpWhT1Wi.js → vite-7I1bJvqA.js} +686 -244
- package/dist/vite-CZ_Z6IR3.d.ts +28 -0
- package/dist/vite.d.ts +41 -6
- package/dist/vite.js +1 -1
- package/dist/vue.d.ts +4 -3
- package/dist/vue.js +39 -4
- package/package.json +9 -8
- package/dist/client-request-BzMKtfCY.js +0 -52
- package/dist/database-options-B87hDU4j.js +0 -28
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as authDatabaseSchemaError } from "./database-options-Cms7BI3c.js";
|
|
2
2
|
import { getAuthTables } from "better-auth/db";
|
|
3
3
|
// src/database-schema-options.ts
|
|
4
4
|
/** Better Auth reads each table by its key and each column by its field key, so the options must not rename them. */
|
package/dist/database.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as AuthAppDatabase } from "./types-
|
|
1
|
+
import { f as AuthAppDatabase } from "./types-CnO5bHEF.js";
|
|
2
2
|
/**
|
|
3
3
|
* The Better Auth `database` adapter for the app Database `name` (default `"default"`). Pass it inline as the
|
|
4
4
|
* `database` of `defineAuth()`. Auth then adds the Better Auth tables, the fields of `admin()` when the Definition calls it, the
|
package/dist/database.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as authErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import {
|
|
3
|
-
import { t as assertAuthDatabaseNames } from "./database-schema-options-
|
|
1
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-DZHuHXPP.js";
|
|
2
|
+
import { o as authDatabaseSchemaError, r as authDatabaseIdColumnError, t as assertAuthDatabaseIdStrategy } from "./database-options-Cms7BI3c.js";
|
|
3
|
+
import { t as assertAuthDatabaseNames } from "./database-schema-options-IlHEeUBK.js";
|
|
4
4
|
import { getAuthTables } from "better-auth/db";
|
|
5
5
|
import { getTableColumns, is, isTable } from "drizzle-orm";
|
|
6
6
|
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
@@ -9,14 +9,18 @@ import { PgAsyncDatabase } from "drizzle-orm/pg-core";
|
|
|
9
9
|
// src/database.ts
|
|
10
10
|
/**
|
|
11
11
|
* Compares the tables and fields that the options need, with the plugins and additional fields, against the Drizzle
|
|
12
|
-
* tables of the Database,
|
|
12
|
+
* tables of the Database. On Postgres, it compares the declared ID column type against the ID strategy. It does not
|
|
13
|
+
* query the live database.
|
|
13
14
|
*/
|
|
14
|
-
function assertAuthDatabaseSchema(options, schema, database) {
|
|
15
|
+
function assertAuthDatabaseSchema(options, schema, database, postgres) {
|
|
16
|
+
const uuidIds = options.advanced?.database?.generateId === "uuid";
|
|
15
17
|
const fix = "Import the plugin by name from its package, such as `import { admin } from \"better-auth/plugins\"`, and call it in `server/auth.ts` or in a file that it imports with a relative path. Auth does not read a default import of the plugin, or a namespace that a local file re-exports. Write `additionalFields` inline in `server/auth.ts`, so that the Auth Vite plugin adds the columns. Then run `vitehub database generate` and apply the migration";
|
|
16
18
|
for (const [model, table] of Object.entries(getAuthTables(options))) {
|
|
17
19
|
const drizzleTable = Object.hasOwn(schema, model) ? schema[model] : void 0;
|
|
18
20
|
if (!isTable(drizzleTable)) throw authDatabaseSchemaError(`the ${JSON.stringify(database)} Database has no \`${model}\` table. ${fix}`);
|
|
19
21
|
const columns = getTableColumns(drizzleTable);
|
|
22
|
+
const uuidColumn = columns.id?.getSQLType() === "uuid";
|
|
23
|
+
if (postgres && uuidColumn !== uuidIds) throw authDatabaseIdColumnError(database, model, uuidColumn);
|
|
20
24
|
for (const key of Object.keys(table.fields)) if (!Object.hasOwn(columns, key)) throw authDatabaseSchemaError(`the \`${model}\` table of the ${JSON.stringify(database)} Database has no \`${key}\` column. ${fix}`);
|
|
21
25
|
}
|
|
22
26
|
}
|
|
@@ -32,10 +36,11 @@ function authDatabase(name = "default") {
|
|
|
32
36
|
assertAuthDatabaseIdStrategy(options.advanced?.database?.generateId);
|
|
33
37
|
assertAuthDatabaseNames(options);
|
|
34
38
|
const entry = Object.hasOwn(databases, name) ? databases[name] : void 0;
|
|
35
|
-
if (!entry || !Object.hasOwn(entry.schema, "user")) throw authErrorDiagnostics.AUTH_R0019({ message: `[vitehub] \`authDatabase(${JSON.stringify(name)})\` found no Better Auth tables in the ${JSON.stringify(name)} Database. Pass \`authDatabase()\` inline as the \`database\` of \`defineAuth()\` so that Auth adds them,
|
|
36
|
-
|
|
39
|
+
if (!entry || !Object.hasOwn(entry.schema, "user")) throw authErrorDiagnostics.AUTH_R0019({ message: `[vitehub] \`authDatabase(${JSON.stringify(name)})\` found no Better Auth tables in the ${JSON.stringify(name)} Database. Pass \`authDatabase()\` inline as the \`database\` of \`defineAuth()\` so that Auth adds them, then run \`vitehub database generate\` and \`vitehub database migrate\`. \`vitehub inspect definitions --kind database\` lists the tables of each Database.` });
|
|
40
|
+
const postgres = is(entry.db, PgAsyncDatabase);
|
|
41
|
+
assertAuthDatabaseSchema(options, entry.schema, name, postgres);
|
|
37
42
|
return drizzleAdapter(entry.db, {
|
|
38
|
-
provider:
|
|
43
|
+
provider: postgres ? "pg" : "sqlite",
|
|
39
44
|
schema: entry.schema
|
|
40
45
|
})(options);
|
|
41
46
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as assertAuthPages, o as normalizeAuthBasePath } from "./access-pages-C69nwa99.js";
|
|
2
|
+
import { n as isAuthRole } from "./roles-BGi8CyBG.js";
|
|
2
3
|
import { t as accessRouteSyntaxError } from "./application-path-zKi7NrvK.js";
|
|
3
|
-
import { t as authErrorDiagnostics } from "./error-diagnostics-
|
|
4
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-DZHuHXPP.js";
|
|
4
5
|
import { t as isRecord } from "./object-CAK6UYR5.js";
|
|
5
|
-
import {
|
|
6
|
+
import { i as authDatabaseName } from "./database-options-Cms7BI3c.js";
|
|
6
7
|
import { parseDuration } from "@vite-hub/runtime";
|
|
7
8
|
// src/stateless-user-id.ts
|
|
8
9
|
const pendingUserIds = /* @__PURE__ */ new WeakMap();
|
|
@@ -307,6 +308,7 @@ const authRuntimeOptionNames = /* @__PURE__ */ new Set([
|
|
|
307
308
|
const accessRouteKeys = /* @__PURE__ */ new Set([
|
|
308
309
|
"authorize",
|
|
309
310
|
"method",
|
|
311
|
+
"role",
|
|
310
312
|
"route"
|
|
311
313
|
]);
|
|
312
314
|
function validateAuthDatabase(value) {
|
|
@@ -356,6 +358,18 @@ function validateAuthAccessRoute(value, label) {
|
|
|
356
358
|
validateRouteValue(value.route, `${label}.route`);
|
|
357
359
|
if (typeof value.authorize !== "undefined" && typeof value.authorize !== "function") throw authErrorDiagnostics.AUTH_C0033({ message: `\`defineAuth()\` ${label}.authorize must be a function.` });
|
|
358
360
|
if (typeof value.method !== "undefined") validateStringValue(value.method, `${label}.method`);
|
|
361
|
+
validateAuthAccessRole(value.role, label);
|
|
362
|
+
}
|
|
363
|
+
function validateAuthAccessRole(value, label) {
|
|
364
|
+
if (typeof value !== "undefined" && !isAuthRole(value)) throw authErrorDiagnostics.AUTH_ACCESS_ROLE_INVALID({ message: `\`defineAuth()\` ${label}.role must be a role name or a non-empty list of role names, such as \`role: ["team", "admin"]\`.` });
|
|
365
|
+
}
|
|
366
|
+
/** Also checked when a Definition callback returns the options, so a route never runs with a role it cannot match. */
|
|
367
|
+
function validateAuthAccessRouteRoles(access) {
|
|
368
|
+
const routes = isRecord(access) ? access.routes : void 0;
|
|
369
|
+
if (!Array.isArray(routes)) return;
|
|
370
|
+
routes.forEach((route, index) => {
|
|
371
|
+
if (isRecord(route)) validateAuthAccessRole(route.role, `access.routes[${index}]`);
|
|
372
|
+
});
|
|
359
373
|
}
|
|
360
374
|
function validateAuthAccess(value) {
|
|
361
375
|
if (typeof value === "undefined") return;
|
|
@@ -417,4 +431,4 @@ function defineAuthOptions(options) {
|
|
|
417
431
|
applyAuthPreset(options);
|
|
418
432
|
return { options };
|
|
419
433
|
}
|
|
420
|
-
export {
|
|
434
|
+
export { validateAuthComponents as a, validateAuthEvents as c, validateAuthAccessRouteRoles as i, applyAuthPreset as l, defineAuth as n, createDeleteAccount as o, validateAuthAccessPolicy as r, validateDeleteAccount as s, assertNoRuntimeOption as t };
|
|
@@ -49,10 +49,15 @@ const authErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
49
49
|
why: "Invalid password hash",
|
|
50
50
|
fix: "The stored password hash is not `<salt>:<key>`. Hash new passwords with `hashPasswordWithNoble()` or the Better Auth hasher, and reset the password of the user whose hash is broken."
|
|
51
51
|
},
|
|
52
|
+
AUTH_SECRET_MISSING: {
|
|
53
|
+
why: "Auth has no secret to sign sessions, so Better Auth would use its public default secret. `VITEHUB_SECRET` is not set, and the app sets no Better Auth secret.",
|
|
54
|
+
fix: "Run `pnpm vitehub secret generate` and set the output as `VITEHUB_SECRET` in the server environment. On Cloudflare, run `pnpm exec wrangler secret put VITEHUB_SECRET`. To keep a Better Auth secret, set `BETTER_AUTH_SECRET`, or return `secret` from the Definition callback."
|
|
55
|
+
},
|
|
52
56
|
AUTH_SIGN_OUT_REDIRECT_INVALID: {
|
|
53
57
|
why: ({ redirectTo }) => `\`signOut()\` redirects only to a path of the app, not to ${JSON.stringify(redirectTo)}.`,
|
|
54
58
|
fix: "Pass a path that starts with one `/`, for example `signOut(event, { redirectTo: '/login' })`. A value from the query string can point to another site, so check it against your own pages first."
|
|
55
59
|
},
|
|
60
|
+
AUTH_ACCESS_ROLE_INVALID: withFix("Set `role` to a role name or a non-empty list of role names without commas, as Better Auth's `admin()` plugin stores them in `user.role`, for example `{ route: '/api/**', role: ['team', 'admin'] }` or `pages: { '/dashboard/**': { role: 'team' } }`."),
|
|
56
61
|
AUTH_AFTER_SIGN_IN_INVALID: {
|
|
57
62
|
why: "`defineAuth()` access.afterSignIn must be an inline path of the app that starts with one `/`.",
|
|
58
63
|
fix: "Set `access.afterSignIn` to a string literal path, for example `afterSignIn: '/dashboard'`. The Nuxt page guard reads it at build time."
|
|
@@ -61,7 +66,43 @@ const authErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
61
66
|
why: "`defineAuth()` components must be an inline object with only `prefix`, an inline non-empty string.",
|
|
62
67
|
fix: "Write `components: { prefix: 'Custom' }` in `defineAuth()` to register `<CustomAuthPermission>`, or remove `components`. The Nuxt module reads the prefix at build time, so it cannot use a variable or an expression."
|
|
63
68
|
},
|
|
64
|
-
|
|
69
|
+
AUTH_DATABASE_DISABLED: {
|
|
70
|
+
why: ({ definition }) => `${definition} keeps users in the app Database with \`authDatabase()\`, but \`vitehub()\` sets \`database: false\`.`,
|
|
71
|
+
fix: "Remove `database: false` from `vitehub()`, or from the `vitehub` key of `nuxt.config.ts`. `authDatabase()` turns the Database on. To keep the Database off, set `database: \"memory\"` or `preset: stateless()` in `defineAuth()`."
|
|
72
|
+
},
|
|
73
|
+
AUTH_DUPLICATE_PLUGIN: {
|
|
74
|
+
why: ({ plugin, files }) => files[0] === files[1] ? `${files[0]} adds the Better Auth plugin "${plugin}" twice.` : `Two Auth sources add the Better Auth plugin "${plugin}": ${files.join(" and ")}. Auth does not pick one.`,
|
|
75
|
+
fix: "Keep the plugin in one of the files that the message names and remove it from the other. To change the options of a plugin that a Nuxt layer adds, change them in the file of the layer."
|
|
76
|
+
},
|
|
77
|
+
AUTH_EXTENSION_OPTION_INVALID: {
|
|
78
|
+
why: ({ file, option }) => option ? `${file ?? "`extendAuth()`"} sets \`${option}\`. A part of the Auth Definition takes only \`plugins\` and \`user.additionalFields\`.` : `${file} must have \`export default extendAuth({ ... })\` with an inline object literal, so that the build can read its plugins and fields.`,
|
|
79
|
+
fix: "Move the option that the message names to `defineAuth()` in `server/auth.ts`, which holds every other Auth option. Keep `export default extendAuth({ plugins, user: { additionalFields } })` from `vite-hub/auth` in `server/auth.extend.ts`, with static keys and without a spread. In `app/auth.client.extend.ts`, keep `export default extendAuthClient({ plugins })` from `vite-hub/auth/vue`, and move other client options to `app/auth.client.ts`."
|
|
80
|
+
},
|
|
81
|
+
AUTH_EXTENSION_WITHOUT_DEFINITION: {
|
|
82
|
+
why: ({ file }) => `${file} adds to the Auth Definition, but the app and its Nuxt layers have no Auth Definition.`,
|
|
83
|
+
fix: "Add `server/auth.ts` with `export default defineAuth({ ... })` from `vite-hub/auth` to the app, or to the Nuxt layer that owns Auth. Or delete the file that the message names."
|
|
84
|
+
},
|
|
85
|
+
AUTH_FIELD_CONFLICT: {
|
|
86
|
+
why: ({ model, field, files, attributes }) => `${files.join(" and ")} declare ${model}.${field} with a different ${attributes.map((attribute) => `\`${attribute}\``).join(", ")}. Auth does not pick one.`,
|
|
87
|
+
fix: "Give the field the same attributes in each file that the message names, or keep it in one file. A field that two files declare with the same attributes is one column."
|
|
88
|
+
},
|
|
89
|
+
AUTH_LAYER_CLIENT_IGNORED: {
|
|
90
|
+
why: ({ files, app }) => app ? `Auth uses the client options of ${app} and would ignore the \`auth.client.ts\` of a Nuxt layer: ${files.join(", ")}.` : `More than one Nuxt layer has an \`auth.client.ts\`, and Auth loads one file: ${files.join(", ")}.`,
|
|
91
|
+
fix: "Keep one `auth.client.ts`. In each layer that the message lists, rename `app/auth.client.ts` to `app/auth.client.extend.ts`, and change `defineAuthClient({ plugins })` to `extendAuthClient({ plugins })` from `vite-hub/auth/vue`. Auth adds the client plugins of each layer to the client options of the app. Options other than `plugins` stay in the one `auth.client.ts`."
|
|
92
|
+
},
|
|
93
|
+
AUTH_LAYER_DEFINITION_REPLACED: {
|
|
94
|
+
why: ({ app, layer, dropped }) => `${app} replaces the Auth Definition of a Nuxt layer, ${layer}, and has no plugin or additional field for these tables and columns of the layer: ${dropped.join(", ")}. The next migration would drop them.`,
|
|
95
|
+
fix: "Move the plugins and the `user.additionalFields` of the layer Definition to `server/auth.extend.ts` of the layer, as `export default extendAuth({ plugins, user: { additionalFields } })` from `vite-hub/auth`, and delete `server/auth.ts` of the layer. Auth adds them to the Definition of the app. For fields of other tables, add the `additionalFields` to the Definition of the app. To drop the tables and columns, delete `server/auth.ts` of the layer."
|
|
96
|
+
},
|
|
97
|
+
AUTH_PAGE_ROUTES_INVALID: withFix("Write `access.pages` inline in `defineAuth()`, and do not use a spread or a computed key in `access`. Start each key with `/` and use only static segments, `:name`, and a last `**`. Keep one key for the same pages, and set each value to `'user'`, `'guest'`, `false`, or `{ role }`, for example `pages: { '/dashboard/**': 'user', '/login': 'guest' }`. For an optional segment, add one key with the segment and one key without it."),
|
|
98
|
+
AUTH_PLUGIN_FIELD_NOT_IN_SCHEMA: {
|
|
99
|
+
why: ({ plugin, file, fields }) => `The Better Auth plugin "${plugin}" in ${file} adds ${fields.join(", ")} to a table of another plugin that \`authDatabase()\` owns. Auth reads the \`schema\` of a plugin in the project only for the \`user\`, \`session\`, \`account\`, and \`verification\` tables, so the Database would not have ${fields.length > 1 ? "these columns" : "this column"}.`,
|
|
100
|
+
fix: "Move each field that the message lists to a table of the plugin itself, or to `user`, `session`, `account`, or `verification`. Then run `vitehub database generate`."
|
|
101
|
+
},
|
|
102
|
+
AUTH_PLUGIN_SCHEMA_UNREADABLE: {
|
|
103
|
+
why: ({ plugin, file, detail }) => `The build cannot read the \`schema\` of the Better Auth plugin "${plugin}" in ${file}: ${detail}. Auth does not run plugin code at build time, so the Database would not have the columns of the plugin.`,
|
|
104
|
+
fix: "Write `schema` as an inline object literal in the plugin, with each field as an inline object, for example `schema: { user: { fields: { customerId: { type: 'string', required: false } } } }`. Then run `vitehub database generate`."
|
|
105
|
+
},
|
|
65
106
|
AUTH_REDIRECTS_MOVED: {
|
|
66
107
|
why: "`vitehub({ auth })` takes only `true` or `false`. The `redirects` option moved to the Auth Definition.",
|
|
67
108
|
fix: "Remove the object from `auth` in `vitehub()`. In `server/auth.ts`, set `access: { signIn: '/login', afterSignIn: '/' }`: `redirects.login` is now `signIn`, and `redirects.guest` is now `afterSignIn`. `vitehub migrate` moves them."
|
|
@@ -119,12 +160,12 @@ const authErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
119
160
|
AUTH_C0050: withFix("Set `events: { store: createDatabaseAuthEventStore({ db }) }`, or `events: false` to disable the log. `events.authorize` and `events.onEvent` must be functions."),
|
|
120
161
|
AUTH_C0051: withFix("Add `admin()` from `better-auth/plugins` to the `plugins` of `defineAuth()`, or unset the variable that the message names."),
|
|
121
162
|
AUTH_C0052: withFix("Pass the Database name as one string literal, for example `authDatabase('content')`, or no argument for the `default` Database."),
|
|
122
|
-
AUTH_C0053: withFix("Remove `advanced.database.generateId`, or set it to a function that returns strings. Use another Better Auth adapter for numeric or
|
|
163
|
+
AUTH_C0053: withFix("Remove `advanced.database.generateId`, set it to `'uuid'` inline in the Auth Definition, or set it to a function that returns strings. Use another Better Auth adapter for numeric IDs or IDs that only the database makes."),
|
|
123
164
|
AUTH_C0054: withFix("Call `authDatabase()` inline as `database` in the object of `defineAuth()`, or in the one object that its callback returns. Do not select it in a branch."),
|
|
124
165
|
AUTH_C0055: withFix("Write `additionalFields` inline in `server/auth.ts`, with a literal `type` for each field, for example `user: { additionalFields: { login: { type: 'string', required: false } } }`."),
|
|
125
166
|
AUTH_C0056: withFix("Remove the `modelName` or `fieldName` change. For a plugin that adds a table or a column, import it by name from its package, such as `import { admin } from 'better-auth/plugins'`, and call it in `server/auth.ts` or in a file that `server/auth.ts` imports with a relative path, so that the Auth Vite plugin adds its tables, or add its tables to the Database Definition. Then run `vitehub database generate`."),
|
|
126
|
-
AUTH_C0057: withFix("Unset `VITEHUB_ADMIN_EMAILS`. List each admin's social account in `VITEHUB_ADMINS`, for example `VITEHUB_ADMINS=github:22072217`."),
|
|
127
|
-
AUTH_C0058: withFix("Write each `VITEHUB_ADMINS` entry as `<provider>:<account id>`, for example `github:22072217`. Run `gh api users/<login> --jq .id` to get a GitHub account id.
|
|
167
|
+
AUTH_C0057: withFix("Unset `VITEHUB_ADMIN_EMAILS`. List each admin's social account or email in `VITEHUB_ADMINS`, for example `VITEHUB_ADMINS=github:22072217,ada@example.com`."),
|
|
168
|
+
AUTH_C0058: withFix("Write each `VITEHUB_ADMINS` entry as `<provider>:<account id>`, for example `github:22072217`, or as an email, for example `ada@example.com`. Run `gh api users/<login> --jq .id` to get a GitHub account id."),
|
|
128
169
|
AUTH_C0059: withFix("Run `vitehub auth claim` and set `VITEHUB_ADMIN_CLAIM` to the `sha256:` value that it prints. Do not set the code itself."),
|
|
129
170
|
AUTH_R0018: withFix("Set `events: { store: createDatabaseAuthEventStore({ db }) }` in `defineAuth()`."),
|
|
130
171
|
AUTH_R0003: withFix("Keep one of `server/auth.ts` and `server.auth.ts` and delete the others that the message lists. For Nuxt layers, add `server/auth.ts` to the app to select the Definition."),
|
|
@@ -153,7 +194,7 @@ const authErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
153
194
|
AUTH_R0014: withFix("Pass a function that returns `true`, `false`, or a `Response`, for example `withAuthorization(({ user }) => user.role === 'admin', handler)`. `withAuthorization()` and `requireAuthorization()` also take `true` for any signed-in user. `withAnonymousAuthorization()` takes only a function."),
|
|
154
195
|
AUTH_R0015: withFix("Pass your handler function, for example `withAuth((event, { user }) => ({ id: user.id }))`."),
|
|
155
196
|
AUTH_R0016: withFix("Set `VITEHUB_SECRET` to at least 32 random characters. Run `openssl rand -base64 32` to make one."),
|
|
156
|
-
AUTH_R0019: withFix("Pass `authDatabase()` inline as `database` of `defineAuth()`,
|
|
197
|
+
AUTH_R0019: withFix("Pass `authDatabase()` inline as `database` of `defineAuth()`, then run `vitehub database generate` and `vitehub database migrate`. Run `vitehub inspect definitions --kind database` to list the tables."),
|
|
157
198
|
AUTH_R0020: withFix("Add the named rule to `shared/abilities.ts` with `defineAbilities()`, or use an existing ability name."),
|
|
158
199
|
AUTH_R0021: withFix("Return the result at once. Load data before the ability check and pass it as a rule argument; remove `async` from the rule."),
|
|
159
200
|
AUTH_R0022: withFix("Send the request to an origin that `vitehub({ publicUrl })` returns for one of your Agents, or set `baseURL` in the Auth Definition. The request Host cannot choose the Auth origin."),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as authErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-DZHuHXPP.js";
|
|
2
2
|
import { t as isRecord } from "./object-CAK6UYR5.js";
|
|
3
3
|
import { defineErrors } from "@vite-hub/runtime";
|
|
4
4
|
import { sql } from "drizzle-orm";
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { _ as AuthDefinition } from "./types-CnO5bHEF.js";
|
|
2
|
+
import { BetterAuthOptions } from "better-auth";
|
|
3
|
+
type UserAdditionalFields = NonNullable<NonNullable<BetterAuthOptions["user"]>["additionalFields"]>;
|
|
4
|
+
/** What a part of the Auth Definition can add. Every other option stays in `defineAuth()`. */
|
|
5
|
+
interface AuthExtensionOptions {
|
|
6
|
+
/** Better Auth server plugins, added after the plugins of the Definition. */
|
|
7
|
+
plugins?: NonNullable<BetterAuthOptions["plugins"]>;
|
|
8
|
+
user?: {
|
|
9
|
+
/** Fields of the `user` table. A field that another source declares must have the same attributes. */
|
|
10
|
+
additionalFields?: UserAdditionalFields;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** A part of the Auth Definition, from `extendAuth()` in `server/auth.extend.ts`. */
|
|
14
|
+
interface AuthExtension<TOptions extends AuthExtensionOptions = AuthExtensionOptions> {
|
|
15
|
+
extension: TOptions;
|
|
16
|
+
}
|
|
17
|
+
/** `TOptions` with each key outside `TKeys` as `never`, so the editor reports an option that a part cannot set. */
|
|
18
|
+
type OnlyKeys<TOptions, TKeys extends PropertyKey> = TOptions & { [Key in Exclude<keyof TOptions, TKeys>]: never; };
|
|
19
|
+
type OnlyExtensionOptions<TOptions extends AuthExtensionOptions> = OnlyKeys<TOptions, keyof AuthExtensionOptions> & {
|
|
20
|
+
user?: OnlyKeys<NonNullable<TOptions["user"]>, "additionalFields">;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* A part of the Auth Definition: Better Auth server plugins and `user` fields that a Nuxt layer, or the app, adds to
|
|
24
|
+
* the Definition of `server/auth.ts`. Export it as the default export of `server/auth.extend.ts`.
|
|
25
|
+
*/
|
|
26
|
+
declare function extendAuth<const TOptions extends AuthExtensionOptions>(options: OnlyExtensionOptions<TOptions>): AuthExtension<TOptions>;
|
|
27
|
+
/**
|
|
28
|
+
* The Auth Definition with the plugins and `user` fields of its parts: the Definition first, then each part in the
|
|
29
|
+
* order of `extensions`. A Definition callback gets them on each resolution.
|
|
30
|
+
*/
|
|
31
|
+
declare function applyAuthExtensions(definition: AuthDefinition, file: string, extensions: ReadonlyArray<{
|
|
32
|
+
file: string;
|
|
33
|
+
extension: AuthExtension;
|
|
34
|
+
}>): AuthDefinition;
|
|
35
|
+
type PluginsOf<TOptions> = TOptions extends {
|
|
36
|
+
plugins: infer TPlugins extends readonly unknown[];
|
|
37
|
+
} ? TPlugins : [];
|
|
38
|
+
type UserOf<TOptions> = TOptions extends {
|
|
39
|
+
user: infer TUser;
|
|
40
|
+
} ? TUser : {};
|
|
41
|
+
type UserFieldsOf<TOptions> = UserOf<TOptions> extends {
|
|
42
|
+
additionalFields: infer TFields;
|
|
43
|
+
} ? TFields : {};
|
|
44
|
+
type ExtensionPlugins<TExtensions extends readonly unknown[]> = TExtensions extends readonly [AuthExtension<infer TOptions>, ...infer TRest] ? [...PluginsOf<TOptions>, ...ExtensionPlugins<TRest>] : [];
|
|
45
|
+
type ExtensionUserFields<TExtensions extends readonly unknown[]> = TExtensions extends readonly [AuthExtension<infer TOptions>, ...infer TRest] ? UserFieldsOf<TOptions> & ExtensionUserFields<TRest> : {};
|
|
46
|
+
type ExtendedOptions<TOptions, TExtensions extends readonly unknown[]> = Omit<TOptions, "plugins" | "user"> & {
|
|
47
|
+
plugins: [...PluginsOf<TOptions>, ...ExtensionPlugins<TExtensions>];
|
|
48
|
+
user: Omit<UserOf<TOptions>, "additionalFields"> & {
|
|
49
|
+
additionalFields: UserFieldsOf<TOptions> & ExtensionUserFields<TExtensions>;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The type of an Auth Definition with its parts, which generated declarations register. `TExtensions` is the tuple of
|
|
54
|
+
* the default exports of the `server/auth.extend.ts` files, in merge order.
|
|
55
|
+
*/
|
|
56
|
+
type ExtendedAuthDefinition<TDefinition extends AuthDefinition, TExtensions extends readonly unknown[]> = {
|
|
57
|
+
options: TDefinition["options"] extends ((context: infer TContext) => infer TResolved) ? (context: TContext) => ExtendedOptions<TResolved, TExtensions> : ExtendedOptions<TDefinition["options"], TExtensions>;
|
|
58
|
+
};
|
|
59
|
+
export { applyAuthExtensions as a, OnlyKeys as i, AuthExtensionOptions as n, extendAuth as o, ExtendedAuthDefinition as r, AuthExtension as t };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { t as isRecord } from "./object-CAK6UYR5.js";
|
|
2
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-DZHuHXPP.js";
|
|
3
|
+
// src/extension.ts
|
|
4
|
+
/** The options of a part. The build scanner checks the same keys in the source. */
|
|
5
|
+
const authExtensionKeys = /* @__PURE__ */ new Set(["plugins", "user"]);
|
|
6
|
+
/**
|
|
7
|
+
* A part of the Auth Definition: Better Auth server plugins and `user` fields that a Nuxt layer, or the app, adds to
|
|
8
|
+
* the Definition of `server/auth.ts`. Export it as the default export of `server/auth.extend.ts`.
|
|
9
|
+
*/
|
|
10
|
+
function extendAuth(options) {
|
|
11
|
+
const option = Object.keys(options).find((key) => !authExtensionKeys.has(key)) ?? Object.keys(options.user ?? {}).filter((key) => key !== "additionalFields").map((key) => `user.${key}`)[0];
|
|
12
|
+
if (option) throw authErrorDiagnostics.AUTH_EXTENSION_OPTION_INVALID({ option });
|
|
13
|
+
return { extension: options };
|
|
14
|
+
}
|
|
15
|
+
/** Fails when two sources add a plugin with the same id, or one source adds it twice. */
|
|
16
|
+
function assertUniquePluginIds(sources) {
|
|
17
|
+
const owners = /* @__PURE__ */ new Map();
|
|
18
|
+
for (const { file, ids } of sources) for (const id of ids) {
|
|
19
|
+
const first = owners.get(id);
|
|
20
|
+
if (first !== void 0) throw authErrorDiagnostics.AUTH_DUPLICATE_PLUGIN({
|
|
21
|
+
plugin: id,
|
|
22
|
+
files: [first, file]
|
|
23
|
+
});
|
|
24
|
+
owners.set(id, file);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** The attributes that two declarations of one field do not share. */
|
|
28
|
+
function differentFieldAttributes(left, right) {
|
|
29
|
+
return [.../* @__PURE__ */ new Set([...Object.keys(left), ...Object.keys(right)])].filter((key) => !sameAttribute(Reflect.get(left, key), Reflect.get(right, key)));
|
|
30
|
+
}
|
|
31
|
+
function sameAttribute(left, right) {
|
|
32
|
+
if (Object.is(left, right)) return true;
|
|
33
|
+
if (Array.isArray(left) && Array.isArray(right)) return left.length === right.length && left.every((value, index) => sameAttribute(value, right[index]));
|
|
34
|
+
return isRecord(left) && isRecord(right) && Object.getPrototypeOf(left) === Object.prototype && Object.getPrototypeOf(right) === Object.prototype && differentFieldAttributes(left, right).length === 0;
|
|
35
|
+
}
|
|
36
|
+
const authCoreModels = [
|
|
37
|
+
"user",
|
|
38
|
+
"session",
|
|
39
|
+
"account",
|
|
40
|
+
"verification"
|
|
41
|
+
];
|
|
42
|
+
function effectiveFieldAttributes(attributes) {
|
|
43
|
+
const resolved = { ...attributes };
|
|
44
|
+
for (const [key, fallback] of Object.entries({
|
|
45
|
+
required: false,
|
|
46
|
+
unique: false,
|
|
47
|
+
index: false,
|
|
48
|
+
bigint: false,
|
|
49
|
+
returned: true,
|
|
50
|
+
input: true
|
|
51
|
+
})) resolved[key] ??= fallback;
|
|
52
|
+
return resolved;
|
|
53
|
+
}
|
|
54
|
+
/** The fields of each model, with the first declaration of each. A later declaration must have the same attributes. */
|
|
55
|
+
function mergeFieldDeclarations(declarations, compare = differentFieldAttributes) {
|
|
56
|
+
const first = /* @__PURE__ */ new Map();
|
|
57
|
+
const merged = {};
|
|
58
|
+
for (const declaration of declarations) {
|
|
59
|
+
const key = `${declaration.model}.${declaration.field}`;
|
|
60
|
+
const existing = first.get(key);
|
|
61
|
+
if (!existing) {
|
|
62
|
+
first.set(key, declaration);
|
|
63
|
+
(merged[declaration.model] ??= {})[declaration.field] = declaration.attributes;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const attributes = compare(existing.attributes, declaration.attributes);
|
|
67
|
+
if (attributes.length) throw authErrorDiagnostics.AUTH_FIELD_CONFLICT({
|
|
68
|
+
model: declaration.model,
|
|
69
|
+
field: declaration.field,
|
|
70
|
+
files: [existing.file, declaration.file],
|
|
71
|
+
attributes
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return merged;
|
|
75
|
+
}
|
|
76
|
+
const pluginIds = (options) => (options.plugins ?? []).flatMap((plugin) => isRecord(plugin) && typeof plugin.id === "string" ? [plugin.id] : []);
|
|
77
|
+
const optionFields = (file, options) => authCoreModels.flatMap((model) => Object.entries(options[model]?.additionalFields ?? {}).map(([field, attributes]) => ({
|
|
78
|
+
model,
|
|
79
|
+
field,
|
|
80
|
+
file,
|
|
81
|
+
attributes: Object(attributes)
|
|
82
|
+
})));
|
|
83
|
+
function pluginFields(file, options) {
|
|
84
|
+
return (options.plugins ?? []).flatMap((plugin) => {
|
|
85
|
+
if (!isRecord(plugin) || !isRecord(plugin.schema)) return [];
|
|
86
|
+
const schema = plugin.schema;
|
|
87
|
+
return authCoreModels.flatMap((model) => {
|
|
88
|
+
const table = schema[model];
|
|
89
|
+
if (!isRecord(table) || !isRecord(table.fields)) return [];
|
|
90
|
+
return Object.entries(table.fields).flatMap(([field, attributes]) => isRecord(attributes) ? [{
|
|
91
|
+
model,
|
|
92
|
+
field,
|
|
93
|
+
file,
|
|
94
|
+
attributes
|
|
95
|
+
}] : []);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const compareEffectiveFields = (left, right) => differentFieldAttributes(effectiveFieldAttributes(left), effectiveFieldAttributes(right));
|
|
100
|
+
/**
|
|
101
|
+
* The Auth Definition with the plugins and `user` fields of its parts: the Definition first, then each part in the
|
|
102
|
+
* order of `extensions`. A Definition callback gets them on each resolution.
|
|
103
|
+
*/
|
|
104
|
+
function applyAuthExtensions(definition, file, extensions) {
|
|
105
|
+
const parts = extensions.map(({ file, extension }) => ({
|
|
106
|
+
file,
|
|
107
|
+
options: extension.extension
|
|
108
|
+
}));
|
|
109
|
+
const merge = (options) => {
|
|
110
|
+
const sources = [{
|
|
111
|
+
file,
|
|
112
|
+
options
|
|
113
|
+
}, ...parts];
|
|
114
|
+
assertUniquePluginIds(sources.map((source) => ({
|
|
115
|
+
file: source.file,
|
|
116
|
+
ids: pluginIds(source.options)
|
|
117
|
+
})));
|
|
118
|
+
const additional = sources.flatMap((source) => optionFields(source.file, source.options));
|
|
119
|
+
mergeFieldDeclarations([...additional, ...sources.flatMap((source) => pluginFields(source.file, source.options))], compareEffectiveFields);
|
|
120
|
+
const fields = mergeFieldDeclarations(additional.filter((field) => field.model === "user"), compareEffectiveFields).user;
|
|
121
|
+
return {
|
|
122
|
+
...options,
|
|
123
|
+
plugins: sources.flatMap((source) => source.options.plugins ?? []),
|
|
124
|
+
...fields ? { user: {
|
|
125
|
+
...options.user,
|
|
126
|
+
additionalFields: fields
|
|
127
|
+
} } : {}
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
const { options } = definition;
|
|
131
|
+
return { options: typeof options === "function" ? (context) => merge(options(context)) : merge(options) };
|
|
132
|
+
}
|
|
133
|
+
export { differentFieldAttributes as a, mergeFieldDeclarations as c, authExtensionKeys as i, assertUniquePluginIds as n, effectiveFieldAttributes as o, authCoreModels as r, extendAuth as s, applyAuthExtensions as t };
|
package/dist/forward.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as authErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-DZHuHXPP.js";
|
|
2
2
|
import { t as forwardSignIns } from "./forward-sign-ins-BWXPPTRz.js";
|
|
3
3
|
import { createAuthMiddleware } from "better-auth/api";
|
|
4
4
|
import { applySetCookies, deleteSessionCookie, setSessionCookie } from "better-auth/cookies";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference path="./host-declarations.d.ts" />
|
|
2
|
-
import { A as AuthRuntimeEnv, At as
|
|
3
|
-
import { n as
|
|
2
|
+
import { A as AuthRuntimeEnv, At as AuthEvent, B as AuthViteHubOptions, Bt as AuthEventWindow, C as AuthGuardedHandler, D as AuthReservedOption, Dt as AuthRole, F as AuthSessionRefresh, Ft as AuthEventMetadata, G as ViteHubAuth, H as RegisteredAuth, Ht as createDatabaseAuthEventStore, I as AuthSessionRefreshContext, It as AuthEventPage, L as AuthSessionRefreshFields, Lt as AuthEventRetention, M as AuthRuntimeOption, Mt as AuthEventAggregates, N as AuthRuntimeOptions, Nt as AuthEventCounts, O as AuthResolvedDefinitionOptions, Ot as hasRole, P as AuthSessionOptions, Pt as AuthEventListInput, R as AuthSignInConfiguration, Rt as AuthEventStore, S as AuthFor, T as AuthRequest, Ut as defaultAuthEventRetention, V as DiscoveredAuthDefinition, Vt as AuthEventsConfiguration, W as ResolvedAuthViteConfig, Z as AuthConsoleColumn, _ as AuthDefinition, a as AuthAccessPolicy, b as AuthDefinitionResolver, c as AuthAccessRouteConfiguration, d as AuthAnonymousGuardedHandler, g as AuthComponentsOptions, gt as AuthConsoleRoles, h as AuthBetterAuthRuntimeOptions, i as AuthAccessConfiguration, j as AuthRuntimeOnlyOptions, jt as AuthEventActor, k as AuthRuntimeContext, kt as AuthDevice, l as AuthAnonymousAuthorization, lt as AuthConsoleOptions, m as AuthBetterAuthOptions, mt as AuthConsolePolicy, n as AuthAccessAuthorize, o as AuthAccessPolicyContext, p as AuthAuthorization, r as AuthAccessAuthorizeResult, rt as AuthConsoleFieldPolicy, s as AuthAccessRoute, t as AuthAccessAuthorizationContext, u as AuthAnonymousAuthorize, v as AuthDefinitionInput, w as AuthOptions, x as AuthDeleteAccountOptions, y as AuthDefinitionOptions, z as AuthSourceSummary, zt as AuthEventType } from "./types-CnO5bHEF.js";
|
|
3
|
+
import { n as AuthExtensionOptions, o as extendAuth, r as ExtendedAuthDefinition, t as AuthExtension } from "./extension-BWmjJhoN.js";
|
|
4
|
+
import { n as checksOwnAccess } from "./own-access-CGiai2L3.js";
|
|
4
5
|
import { n as AuthStatelessPreset, r as AuthStatelessPresetOptions, t as AuthPreset } from "./presets-C6AtiRdI.js";
|
|
5
6
|
import { Result } from "@vite-hub/runtime";
|
|
6
7
|
export declare function defineAuth<const TOptions extends AuthResolvedDefinitionOptions>(options: AuthDefinitionResolver<TOptions>): AuthDefinition<AuthDefinitionResolver<TOptions>>;
|
|
@@ -18,4 +19,4 @@ type GitHubOrgMemberErrorCode = "AUTH_GITHUB_NOT_ORG_MEMBER" | "AUTH_GITHUB_ORG_
|
|
|
18
19
|
* Returns `[undefined, undefined]` for an active membership, else the error that says why it could not confirm one.
|
|
19
20
|
*/
|
|
20
21
|
export declare function checkGitHubOrgMember(accessToken: string | null | undefined, org: string, options?: GitHubOrgMemberOptions): Promise<Result<void, GitHubOrgMemberErrorCode>>;
|
|
21
|
-
export { type AuthAccessAuthorizationContext, type AuthAccessAuthorize, type AuthAccessAuthorizeResult, type AuthAccessConfiguration, type AuthAccessPolicy, type AuthAccessPolicyContext, type AuthAccessRoute, type AuthAccessRouteConfiguration, type AuthAnonymousAuthorization, type AuthAnonymousAuthorize, type AuthAnonymousGuardedHandler, type AuthAuthorization, type AuthBetterAuthOptions, type AuthBetterAuthRuntimeOptions, type AuthComponentsOptions, type AuthConsoleColumn, type AuthConsoleFieldPolicy, type AuthConsoleOptions, type AuthConsolePolicy, type AuthConsoleRoles, type AuthDefinition, type AuthDefinitionInput, type AuthDefinitionOptions, type AuthDefinitionResolver, type AuthDeleteAccountOptions, type AuthDevice, type AuthEvent, type AuthEventActor, type AuthEventAggregates, type AuthEventCounts, type AuthEventListInput, type AuthEventMetadata, type AuthEventPage, type AuthEventRetention, type AuthEventStore, type AuthEventType, type AuthEventWindow, type AuthEventsConfiguration, type AuthFor, type AuthGuardedHandler, type AuthOptions, type AuthPreset, type AuthRequest, type AuthReservedOption, type AuthResolvedDefinitionOptions, type AuthRuntimeContext, type AuthRuntimeEnv, type AuthRuntimeOnlyOptions, type AuthRuntimeOption, type AuthRuntimeOptions, type AuthSessionOptions, type AuthSessionRefresh, type AuthSessionRefreshContext, type AuthSessionRefreshFields, type AuthSignInConfiguration, type AuthStatelessPreset, type AuthStatelessPresetOptions, type AuthViteHubOptions, type DiscoveredAuthDefinition, type GitHubOrgMemberErrorCode, type GitHubOrgMemberOptions, type RegisteredAuth, type ResolvedAuthViteConfig, type ViteHubAuth, checksOwnAccess, createDatabaseAuthEventStore, defaultAuthEventRetention };
|
|
22
|
+
export { type AuthAccessAuthorizationContext, type AuthAccessAuthorize, type AuthAccessAuthorizeResult, type AuthAccessConfiguration, type AuthAccessPolicy, type AuthAccessPolicyContext, type AuthAccessRoute, type AuthAccessRouteConfiguration, type AuthAnonymousAuthorization, type AuthAnonymousAuthorize, type AuthAnonymousGuardedHandler, type AuthAuthorization, type AuthBetterAuthOptions, type AuthBetterAuthRuntimeOptions, type AuthComponentsOptions, type AuthConsoleColumn, type AuthConsoleFieldPolicy, type AuthConsoleOptions, type AuthConsolePolicy, type AuthConsoleRoles, type AuthDefinition, type AuthDefinitionInput, type AuthDefinitionOptions, type AuthDefinitionResolver, type AuthDeleteAccountOptions, type AuthDevice, type AuthEvent, type AuthEventActor, type AuthEventAggregates, type AuthEventCounts, type AuthEventListInput, type AuthEventMetadata, type AuthEventPage, type AuthEventRetention, type AuthEventStore, type AuthEventType, type AuthEventWindow, type AuthEventsConfiguration, type AuthExtension, type AuthExtensionOptions, type AuthFor, type AuthGuardedHandler, type AuthOptions, type AuthPreset, type AuthRequest, type AuthReservedOption, type AuthResolvedDefinitionOptions, type AuthRole, type AuthRuntimeContext, type AuthRuntimeEnv, type AuthRuntimeOnlyOptions, type AuthRuntimeOption, type AuthRuntimeOptions, type AuthSessionOptions, type AuthSessionRefresh, type AuthSessionRefreshContext, type AuthSessionRefreshFields, type AuthSignInConfiguration, type AuthSourceSummary, type AuthStatelessPreset, type AuthStatelessPresetOptions, type AuthViteHubOptions, type DiscoveredAuthDefinition, type ExtendedAuthDefinition, type GitHubOrgMemberErrorCode, type GitHubOrgMemberOptions, type RegisteredAuth, type ResolvedAuthViteConfig, type ViteHubAuth, checksOwnAccess, createDatabaseAuthEventStore, defaultAuthEventRetention, extendAuth, hasRole };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { n as defineAuth } from "./definition-
|
|
2
|
-
import {
|
|
1
|
+
import { n as defineAuth } from "./definition-EpeI5LUG.js";
|
|
2
|
+
import { s as extendAuth } from "./extension-mCx4TrsO.js";
|
|
3
|
+
import { a as checkGitHubOrgMember, n as defaultAuthEventRetention, t as createDatabaseAuthEventStore } from "./events-Cm7Iwq47.js";
|
|
3
4
|
import { n as checksOwnAccess } from "./own-access-CYsakJiH.js";
|
|
4
|
-
|
|
5
|
+
import { t as hasRole } from "./roles-BGi8CyBG.js";
|
|
6
|
+
export { checkGitHubOrgMember, checksOwnAccess, createDatabaseAuthEventStore, defaultAuthEventRetention, defineAuth, extendAuth, hasRole };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference path="../host-declarations.d.ts" />
|
|
2
|
-
import { C as
|
|
3
|
-
import { a as setAuthAccessIdentityResolver, o as setAuthRuntimeEnvResolver, s as resetAuth } from "../server-
|
|
2
|
+
import { A as withAuthorization, C as requireAuthorization, D as useAuth, E as toAuthRequest, F as getAuthForDefinition, N as createBetterAuthOptions, O as withAnonymousAuthorization, P as findVerifiedAuthUserId, S as requireAuthAccessRoutes, T as signOut, _ as handleAuth, a as authMiddleware, b as requireAbility, c as checkAuthMember, d as createAuthForRequest, f as createAuthHandler, g as getAuthEvents, h as getAuthConsoleForRequest, i as assertAuthOrigin, j as sendSessionCookies, k as withAuth, l as createAuth, m as getAuth, n as AuthSignOutOptions, o as authRoute, p as createAuthRequestRuntimeOptions, r as aggregateAuthEvents, s as can, t as AuthEventReadErrorCode, u as createAuthAccessHandler, v as handleAuthRequest, w as requireCaller, x as requireAuth, y as listAuthEvents } from "../server-DyP1v-sZ.js";
|
|
3
|
+
import { a as setAuthAccessIdentityResolver, o as setAuthRuntimeEnvResolver, s as resetAuth } from "../server-mmp8EfcE.js";
|
|
4
4
|
import { n as AbilityErrorData, t as AbilityError } from "../ability-error-C1c30O6E.js";
|
|
5
|
-
export { AbilityError, type AbilityErrorData, AuthEventReadErrorCode, AuthSignOutOptions, aggregateAuthEvents, assertAuthOrigin, can, checkAuthMember, createAuth, createAuthAccessHandler, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, authRoute as default, findVerifiedAuthUserId, getAuth, getAuthConsoleForRequest, getAuthEvents, getAuthForDefinition, handleAuth, handleAuthRequest, listAuthEvents, requireAbility, requireAuth, requireAuthAccessRoutes, requireAuthorization, requireCaller, resetAuth, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver, signOut, toAuthRequest, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
|
|
5
|
+
export { AbilityError, type AbilityErrorData, AuthEventReadErrorCode, AuthSignOutOptions, aggregateAuthEvents, assertAuthOrigin, authMiddleware, can, checkAuthMember, createAuth, createAuthAccessHandler, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, authRoute as default, findVerifiedAuthUserId, getAuth, getAuthConsoleForRequest, getAuthEvents, getAuthForDefinition, handleAuth, handleAuthRequest, listAuthEvents, requireAbility, requireAuth, requireAuthAccessRoutes, requireAuthorization, requireCaller, resetAuth, sendSessionCookies, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver, signOut, toAuthRequest, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
|
package/dist/internal/server.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { n as sendSessionCookies } from "../session-cookies-BNtY3hMp.js";
|
|
1
2
|
import { n as resetAuth } from "../runtime-state-C0Rd1W4m.js";
|
|
2
|
-
import { a as getAuthForDefinition, i as findVerifiedAuthUserId, n as createBetterAuthOptions } from "../auth-instance-
|
|
3
|
+
import { a as getAuthForDefinition, i as findVerifiedAuthUserId, n as createBetterAuthOptions } from "../auth-instance-WeEK1zDd.js";
|
|
3
4
|
import { setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver } from "../runtime/server.js";
|
|
4
|
-
import { t as AbilityError } from "../ability-error-
|
|
5
|
-
import { C as
|
|
6
|
-
export { AbilityError, aggregateAuthEvents, assertAuthOrigin, can, checkAuthMember, createAuth, createAuthAccessHandler, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, authRoute as default, findVerifiedAuthUserId, getAuth, getAuthConsoleForRequest, getAuthEvents, getAuthForDefinition, handleAuth, handleAuthRequest, listAuthEvents, requireAbility, requireAuth, requireAuthAccessRoutes, requireAuthorization, requireCaller, resetAuth, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver, signOut, toAuthRequest, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
|
|
5
|
+
import { t as AbilityError } from "../ability-error-DgR91Jwc.js";
|
|
6
|
+
import { C as signOut, D as withAuth, E as withAnonymousAuthorization, O as withAuthorization, S as requireCaller, T as useAuth, _ as listAuthEvents, a as can, b as requireAuthAccessRoutes, c as createAuthAccessHandler, d as createAuthRequestRuntimeOptions, f as getAuth, g as handleAuthRequest, h as handleAuth, i as authRoute, l as createAuthForRequest, m as getAuthEvents, n as assertAuthOrigin, o as checkAuthMember, p as getAuthConsoleForRequest, r as authMiddleware, s as createAuth, t as aggregateAuthEvents, u as createAuthHandler, v as requireAbility, w as toAuthRequest, x as requireAuthorization, y as requireAuth } from "../server-5t-HA7I1.js";
|
|
7
|
+
export { AbilityError, aggregateAuthEvents, assertAuthOrigin, authMiddleware, can, checkAuthMember, createAuth, createAuthAccessHandler, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, authRoute as default, findVerifiedAuthUserId, getAuth, getAuthConsoleForRequest, getAuthEvents, getAuthForDefinition, handleAuth, handleAuthRequest, listAuthEvents, requireAbility, requireAuth, requireAuthAccessRoutes, requireAuthorization, requireCaller, resetAuth, sendSessionCookies, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver, signOut, toAuthRequest, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { t as isRecord } from "./object-CAK6UYR5.js";
|
|
2
|
+
import { t as clientRequest } from "./client-request-B1DCz3a9.js";
|
|
3
|
+
import { v as forwardedRequestOrigin } from "./auth-instance-WeEK1zDd.js";
|
|
4
|
+
// src/client-request.ts
|
|
5
|
+
function clientRequestOrigin(request, trustProxyHeaders = false) {
|
|
6
|
+
const client = clientRequest(request);
|
|
7
|
+
return trustProxyHeaders ? forwardedRequestOrigin(client) : new URL(client.url).origin;
|
|
8
|
+
}
|
|
2
9
|
// src/mcp-config.ts
|
|
3
10
|
const mcpRegistrationPluginId = "vitehub-mcp-registration";
|
|
11
|
+
const mcpConsentClaim = "vitehub_consent_id";
|
|
4
12
|
/**
|
|
5
13
|
* The resources of MCP OAuth: the Better Auth `oauthProvider()` with `resources` and JWT access tokens of `jwt()`, from
|
|
6
14
|
* `mcpOAuth()` or added by hand. Empty when the Auth has no MCP OAuth, also with `disableJwtPlugin`, whose access tokens
|
|
@@ -14,4 +22,4 @@ function mcpOAuthResources(plugins = []) {
|
|
|
14
22
|
}
|
|
15
23
|
/** True for a token in the JWS compact form (`header.payload.signature`), the form of an MCP OAuth access token. */
|
|
16
24
|
const isJwsToken = (token) => /^[\w-]+\.[\w-]+\.[\w-]+$/.test(token);
|
|
17
|
-
export {
|
|
25
|
+
export { clientRequestOrigin as a, mcpRegistrationPluginId as i, mcpConsentClaim as n, mcpOAuthResources as r, isJwsToken as t };
|