@vite-hub/auth 0.7.0 → 0.9.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 +59 -6
- package/dist/{abilities-CfvuGrBv.d.ts → abilities-6LE7VSdN.d.ts} +1 -1
- package/dist/abilities.d.ts +1 -1
- package/dist/{ability-error-OKoyOwPM.js → ability-error-Ccm5Iy4F.js} +1 -1
- package/dist/{access-pages-Bej95blM.js → access-pages-lQGfRvfL.js} +1 -4
- package/dist/{admin-claim-code-C3X_U43x.js → admin-claim-code-CMa0eRRm.js} +0 -1
- package/dist/agent.js +11 -11
- package/dist/{application-path-zKi7NrvK.js → application-path-LMc_ptL9.js} +0 -2
- package/dist/{auth-instance-5RSiFTDC.js → auth-instance-0PTsOttV.js} +41 -57
- package/dist/bun-sqlite.d.ts +0 -2
- package/dist/cli.js +2 -2
- package/dist/client-extension-BVBVUqa1.d.ts +33 -0
- package/dist/client-request-B1DCz3a9.js +29 -0
- package/dist/{console-runtime-Bg_PAl7e.js → console-runtime-BlOx9hWC.js} +3 -19
- package/dist/{console-runtime-XcplYv4R.d.ts → console-runtime-D2FUATXQ.d.ts} +1 -1
- 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-CPhnGap9.js +36 -0
- package/dist/{database-schema-options-CCQsNhjc.js → database-schema-options-BQyynyhw.js} +1 -1
- package/dist/database.d.ts +1 -1
- package/dist/database.js +22 -11
- package/dist/{definition-DeEeqTLC.js → definition-CvmvHaQT.js} +4 -12
- package/dist/{error-diagnostics-DkzL9ltR.js → error-diagnostics-BpQy1iIO.js} +35 -4
- package/dist/{events-BUaoHFoC.js → events-aP_Rz_gx.js} +1 -1
- package/dist/extension-B35v_o1u.js +133 -0
- package/dist/extension-C2giF7w2.d.ts +59 -0
- package/dist/forward.d.ts +0 -5
- package/dist/forward.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/internal/server.d.ts +3 -3
- package/dist/internal/server.js +5 -5
- package/dist/{mcp-config-C7srUMIZ.js → mcp-config-DYlTXmr6.js} +9 -1
- package/dist/{mcp-token-DG1jmw4o.d.ts → mcp-token-CxpopXmK.d.ts} +4 -2
- package/dist/{mcp-token-DgveSGEl.js → mcp-token-i-8NMulH.js} +28 -6
- package/dist/mcp.d.ts +2 -7
- package/dist/mcp.js +26 -7
- package/dist/{members-CRlYyxVk.js → members-USm08YwK.js} +4 -6
- package/dist/nuxt.d.ts +4 -14
- package/dist/nuxt.js +29 -61
- package/dist/{own-access-BvVUjaeL.d.ts → own-access-B7VRd92K.d.ts} +1 -1
- package/dist/presets.js +1 -1
- package/dist/{request-Dpq7GO8B.js → request-CdlcvqVc.js} +0 -1
- 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 +5 -4
- package/dist/runtime/vue-nuxt.js +2 -18
- package/dist/schema.d.ts +32 -17
- package/dist/schema.js +39 -16
- package/dist/{server-1G_BbfBD.d.ts → server-4_EXgXFn.d.ts} +25 -8
- package/dist/{server-iQNOXyfS.js → server-CZR2dVVp.js} +43 -352
- package/dist/{server-B8kTFrHP.d.ts → server-DAIBBKbR.d.ts} +3 -2
- package/dist/server.d.ts +3 -3
- package/dist/server.js +4 -4
- package/dist/{session-cookies-DN0svCKj.js → session-cookies-CfXdF1yd.js} +5 -33
- package/dist/{set-cookie-CMB3t4NF.js → set-cookie-BYZslovs.js} +1 -1
- package/dist/{table-specs-C3-bLOSF.js → table-specs-Cvjc_Ccs.js} +28 -2
- package/dist/{table-specs-P4LvbOlX.d.ts → table-specs-VYAy_jJ7.d.ts} +5 -2
- package/dist/test.d.ts +1 -1
- package/dist/test.js +2 -2
- package/dist/{types-BmRGse4l.d.ts → types-DakualFJ.d.ts} +20 -4
- package/dist/vite-CZ_Z6IR3.d.ts +28 -0
- package/dist/{vite-GRzej8Cs.js → vite-DVvWaN3D.js} +652 -301
- package/dist/vite.d.ts +35 -17
- package/dist/vite.js +1 -1
- package/dist/vue.d.ts +4 -34
- package/dist/vue.js +40 -66
- package/package.json +9 -8
- package/dist/client-request-BzMKtfCY.js +0 -52
- package/dist/database-options-DE9lMwu1.js +0 -28
package/dist/runtime/vue-nuxt.js
CHANGED
|
@@ -1,35 +1,28 @@
|
|
|
1
1
|
import { n as invariantError } from "../invariant-Dj2R1eMr.js";
|
|
2
2
|
import "../page-tools-shared-dVJBPPTk.js";
|
|
3
|
-
import { i as resolveAuthMountPath } from "../application-path-
|
|
4
|
-
import { t as authErrorDiagnostics } from "../error-diagnostics-
|
|
3
|
+
import { i as resolveAuthMountPath } from "../application-path-LMc_ptL9.js";
|
|
4
|
+
import { t as authErrorDiagnostics } from "../error-diagnostics-BpQy1iIO.js";
|
|
5
5
|
import { n as isAuthRole, t as hasRole } from "../roles-BGi8CyBG.js";
|
|
6
6
|
import { a as setRequestFetchResolver, i as setNuxtErrorFactory, n as setDefaultAuthBasePath, o as setSessionSeedResolver, r as setNuxtAppResolver, s as setSignOutHandler } from "../nuxt-bridge-pRyfYD5c.js";
|
|
7
7
|
import { addRouteMiddleware, createError, defineNuxtPlugin, navigateTo, showError, tryUseNuxtApp, useRequestEvent, useRouter, useRuntimeConfig, useState } from "#app";
|
|
8
8
|
// src/runtime/vue-nuxt.ts
|
|
9
|
-
/** Vue Router gives the same params in other forms: `"a"` or `["a"]`, `[]` or `""` or nothing for an empty one, and any key order. */
|
|
10
9
|
function sameParams(a, b) {
|
|
11
10
|
const values = (value) => JSON.stringify(value === void 0 || value === "" ? [] : [value].flat());
|
|
12
11
|
return [.../* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])].every((key) => values(a[key]) === values(b[key]));
|
|
13
12
|
}
|
|
14
13
|
const stateKey = "vitehub:auth:session";
|
|
15
14
|
const guardRouteKey = "vitehub:auth:guard-route";
|
|
16
|
-
/**
|
|
17
|
-
* True when the request may have a session: ViteHub's `vitehub_session` marker cookie, which Auth sets next to the
|
|
18
|
-
* session cookie, or Better Auth's own `<prefix>.session_token` and `<prefix>.session_data` cookies.
|
|
19
|
-
*/
|
|
20
15
|
function hasSessionCookie(cookie) {
|
|
21
16
|
if (!cookie) return false;
|
|
22
17
|
return cookie.split(";").map((part) => part.split("=")[0]?.trim() ?? "").some((name) => name === "vitehub_session" || /(?:^|\.)session_(?:token|data)$/.test(name));
|
|
23
18
|
}
|
|
24
19
|
const isoDate = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
|
|
25
|
-
/** Better Auth's client returns dates as `Date`. Revive them so the server's session has the same shape. */
|
|
26
20
|
function reviveDates(value) {
|
|
27
21
|
if (typeof value === "string" && isoDate.test(value)) return new Date(value);
|
|
28
22
|
if (Array.isArray(value)) return value.map(reviveDates);
|
|
29
23
|
if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, reviveDates(entry)]));
|
|
30
24
|
return value;
|
|
31
25
|
}
|
|
32
|
-
/** Forward Better Auth's `Set-Cookie` headers, such as a refreshed session, to the page response. */
|
|
33
26
|
function appendSetCookies(event, response) {
|
|
34
27
|
for (const cookie of response.headers.getSetCookie()) event.res.headers.append("set-cookie", cookie);
|
|
35
28
|
}
|
|
@@ -46,10 +39,6 @@ async function pageFetch(event, path, init) {
|
|
|
46
39
|
});
|
|
47
40
|
return serverFetch(request);
|
|
48
41
|
}
|
|
49
|
-
/**
|
|
50
|
-
* The path and query of a URL that Better Auth's client built. The client can build an absolute URL from a variable
|
|
51
|
-
* such as `VERCEL_URL`, and that URL would leave the process.
|
|
52
|
-
*/
|
|
53
42
|
function pathOf(input) {
|
|
54
43
|
const url = new URL(input instanceof Request ? input.url : String(input), "http://localhost");
|
|
55
44
|
return url.pathname + url.search;
|
|
@@ -69,10 +58,6 @@ function currentRequestFetch() {
|
|
|
69
58
|
fetch: requestFetch
|
|
70
59
|
};
|
|
71
60
|
}
|
|
72
|
-
/**
|
|
73
|
-
* Reads the session of the request, so server rendering and hydration start signed in or signed out. Returns `null` at
|
|
74
|
-
* once when the request has no session cookie, else a promise. Call it in a Nuxt context.
|
|
75
|
-
*/
|
|
76
61
|
function readServerSession(basePath) {
|
|
77
62
|
const event = useRequestEvent();
|
|
78
63
|
if (!event) return void 0;
|
|
@@ -101,7 +86,6 @@ async function fetchServerSession(event, basePath) {
|
|
|
101
86
|
function userOf(session) {
|
|
102
87
|
return typeof session === "object" && session !== null ? Reflect.get(session, "user") ?? null : null;
|
|
103
88
|
}
|
|
104
|
-
/** The session read of each server request, so the page guard and all components share one read. */
|
|
105
89
|
const serverReads = /* @__PURE__ */ new WeakMap();
|
|
106
90
|
const viteHubAuthPlugin = defineNuxtPlugin({
|
|
107
91
|
name: "vitehub:auth",
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as AuthSchemaPlugin, c as AuthTableSpec, d as resolveAuthTableSpecs, i as AuthSchemaOptions, l as authPluginSchemas, n as AuthCoreTableSpecs, o as AuthTableField, r as AuthPluginSchemas, s as AuthTableName, t as AuthCoreModel, u as authTableSpecs } from "./table-specs-
|
|
1
|
+
import { a as AuthSchemaPlugin, c as AuthTableSpec, d as resolveAuthTableSpecs, i as AuthSchemaOptions, l as authPluginSchemas, n as AuthCoreTableSpecs, o as AuthTableField, r as AuthPluginSchemas, s as AuthTableName, t as AuthCoreModel, u as authTableSpecs } from "./table-specs-VYAy_jJ7.js";
|
|
2
2
|
import { $Type, BuildColumns, HasDefault, IsPrimaryKey, NotNull } from "drizzle-orm";
|
|
3
|
-
import { PgBigInt53Builder, PgBooleanBuilder, PgBuildColumns, PgColumn, PgIntegerBuilder, PgJsonbBuilder, PgTableWithColumns, PgTextBuilder, PgTimestampBuilder } from "drizzle-orm/pg-core";
|
|
3
|
+
import { PgBigInt53Builder, PgBooleanBuilder, PgBuildColumns, PgColumn, PgIntegerBuilder, PgJsonbBuilder, PgTableWithColumns, PgTextBuilder, PgTimestampBuilder, PgUUIDBuilder } from "drizzle-orm/pg-core";
|
|
4
4
|
import { SQLiteBooleanBuilder, SQLiteColumn, SQLiteIntegerBuilder, SQLiteTableWithColumns, SQLiteTextBuilder, SQLiteTextJsonBuilder, SQLiteTimestampBuilder } from "drizzle-orm/sqlite-core";
|
|
5
5
|
interface AuthExistingColumn {
|
|
6
6
|
notNull: boolean;
|
|
@@ -86,7 +86,7 @@ type SqliteBuilder<F> = F extends {
|
|
|
86
86
|
} ? SQLiteIntegerBuilder : F extends {
|
|
87
87
|
type: "string";
|
|
88
88
|
} ? SQLiteTextBuilder<[string, ...string[]]> : $Type<SQLiteTextJsonBuilder, FieldData<F>>;
|
|
89
|
-
type PostgresBuilder<F> = F extends {
|
|
89
|
+
type PostgresBuilder<F, TUuidIds extends boolean> = F extends {
|
|
90
90
|
type: "boolean";
|
|
91
91
|
} ? PgBooleanBuilder : F extends {
|
|
92
92
|
type: "date";
|
|
@@ -96,7 +96,11 @@ type PostgresBuilder<F> = F extends {
|
|
|
96
96
|
bigint: true;
|
|
97
97
|
} ? PgBigInt53Builder : PgIntegerBuilder : F extends {
|
|
98
98
|
type: "string";
|
|
99
|
-
} ?
|
|
99
|
+
} ? [TUuidIds, F] extends [true, {
|
|
100
|
+
references: {
|
|
101
|
+
field: "id";
|
|
102
|
+
};
|
|
103
|
+
}] ? PgUUIDBuilder : PgTextBuilder : F extends {
|
|
100
104
|
type: "json";
|
|
101
105
|
} ? PgJsonbBuilder : $Type<PgTextBuilder, FieldData<F>>;
|
|
102
106
|
type WithSqliteConstraints<TBuilder, TField, TColumns, TName extends string> = [TColumns] extends [never] ? WithConstraints<TBuilder, TField> : [TColumns] extends [Record<TName, infer TColumn extends AuthExistingColumn>] ? WithColumnConstraints<TBuilder, [TColumn] extends [{
|
|
@@ -107,9 +111,9 @@ type WithSqliteConstraints<TBuilder, TField, TColumns, TName extends string> = [
|
|
|
107
111
|
type SqliteColumns<TFields, TExistingColumns> = {
|
|
108
112
|
id: IsPrimaryKey<SQLiteTextBuilder<[string, ...string[]]>>;
|
|
109
113
|
} & { -readonly [K in keyof TFields]: WithSqliteConstraints<SqliteBuilder<TFields[K]>, TFields[K], TExistingColumns, SqlName<K & string>>; };
|
|
110
|
-
type PostgresColumns<TFields> = {
|
|
111
|
-
id: IsPrimaryKey<PgTextBuilder>;
|
|
112
|
-
} & { -readonly [K in keyof TFields]: WithConstraints<PostgresBuilder<TFields[K]>, TFields[K]>; };
|
|
114
|
+
type PostgresColumns<TFields, TUuidIds extends boolean> = {
|
|
115
|
+
id: TUuidIds extends true ? HasDefault<IsPrimaryKey<PgUUIDBuilder>> : IsPrimaryKey<PgTextBuilder>;
|
|
116
|
+
} & { -readonly [K in keyof TFields]: WithConstraints<PostgresBuilder<TFields[K], TUuidIds>, TFields[K]>; };
|
|
113
117
|
/** A SQLite table with a typed column for each field of `TFields`. */
|
|
114
118
|
export type AuthSqliteTableOf<TFields, TExistingColumns = never> = SQLiteTableWithColumns<{
|
|
115
119
|
name: string;
|
|
@@ -118,11 +122,11 @@ export type AuthSqliteTableOf<TFields, TExistingColumns = never> = SQLiteTableWi
|
|
|
118
122
|
dialect: "sqlite";
|
|
119
123
|
isAlias: false;
|
|
120
124
|
}>;
|
|
121
|
-
/** A Postgres table with a typed column for each field of `TFields`. */
|
|
122
|
-
export type AuthPostgresTableOf<TFields> = PgTableWithColumns<{
|
|
125
|
+
/** A Postgres table with a typed column for each field of `TFields`. `TUuidIds` types the `uuid` IDs and references. */
|
|
126
|
+
export type AuthPostgresTableOf<TFields, TUuidIds extends boolean = false> = PgTableWithColumns<{
|
|
123
127
|
name: string;
|
|
124
128
|
schema: undefined;
|
|
125
|
-
columns: PgBuildColumns<string, PostgresColumns<TFields>>;
|
|
129
|
+
columns: PgBuildColumns<string, PostgresColumns<TFields, TUuidIds>>;
|
|
126
130
|
dialect: "pg";
|
|
127
131
|
isAlias: false;
|
|
128
132
|
}>;
|
|
@@ -134,9 +138,7 @@ export type AuthPostgresCoreTable<TModel extends AuthTableName> = AuthPostgresTa
|
|
|
134
138
|
export type AuthSqliteSchema = { readonly [TModel in AuthTableName]: AuthSqliteCoreTable<TModel>; };
|
|
135
139
|
/** The Better Auth tables for Postgres. Auth adds them to the app Database. */
|
|
136
140
|
export type AuthPostgresSchema = { readonly [TModel in AuthTableName]: AuthPostgresCoreTable<TModel>; };
|
|
137
|
-
/** The fields of a union of field records, keyed by every key of the union. */
|
|
138
141
|
type MergeFields<TUnion> = { [K in TUnion extends unknown ? keyof TUnion : never]: TUnion extends { readonly [P in K]: infer TField; } ? TField : never; };
|
|
139
|
-
/** `TFirst` wins a key that both have, as `resolveAuthTableSpecs()` keeps the column that a table has already. */
|
|
140
142
|
type Prefer<TFirst, TSecond> = TFirst & Omit<TSecond, keyof TFirst>;
|
|
141
143
|
type HasPlugin<TPlugins, TPlugin> = TPlugins extends readonly [infer TFirst, ...infer TRest] ? [TFirst] extends [TPlugin] ? true : HasPlugin<TRest, TPlugin> : TPlugins extends readonly [...infer TRest, infer TLast] ? [TLast] extends [TPlugin] ? true : HasPlugin<TRest, TPlugin> : false;
|
|
142
144
|
type SchemaPlugins<TOptions> = [TOptions] extends [{
|
|
@@ -156,10 +158,12 @@ type TableFields<TOptions, TModel extends AuthTableName> = Prefer<Prefer<AuthCor
|
|
|
156
158
|
type PluginTableFields<TOptions, TTable extends keyof PluginTables<SchemaPlugins<TOptions>>> = PluginTables<SchemaPlugins<TOptions>>[TTable] extends {
|
|
157
159
|
fields: infer TFields;
|
|
158
160
|
} ? TFields : never;
|
|
161
|
+
type UuidIds<TOptions> = [TOptions] extends [{
|
|
162
|
+
generateId: "uuid";
|
|
163
|
+
}] ? true : false;
|
|
159
164
|
type Lower = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
|
|
160
165
|
type Upper = Uppercase<Lower>;
|
|
161
166
|
type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
162
|
-
/** The same word boundaries as `authSqlName()`, for lookup in a migration snapshot. */
|
|
163
167
|
type SqlName<TName extends string, TPrevious extends string = "", TResult extends string = ""> = TName extends `${infer TChar}${infer TRest}` ? SqlName<TRest, TChar, `${TResult}${TChar extends Upper ? TPrevious extends Lower | Digit ? "_" : TPrevious extends Upper ? TRest extends `${Lower}${string}` ? "_" : "" : "" : ""}${Lowercase<TChar>}`> : TResult;
|
|
164
168
|
type ExistingColumns<TExisting, TModel extends string> = [TExisting] extends [Record<SqlName<TModel>, {
|
|
165
169
|
columns: infer TColumns;
|
|
@@ -167,9 +171,17 @@ type ExistingColumns<TExisting, TModel extends string> = [TExisting] extends [Re
|
|
|
167
171
|
/** The Better Auth tables for SQLite, with fields from `TOptions` and constraints from a literal migration snapshot. */
|
|
168
172
|
export type AuthSqliteSchemaFor<TOptions extends AuthSchemaOptions, TExisting extends AuthExistingTables | undefined = undefined> = { readonly [TModel in AuthTableName]: AuthSqliteTableOf<TableFields<TOptions, TModel>, ExistingColumns<TExisting, TModel>>; } & { readonly [TTable in keyof PluginTables<SchemaPlugins<TOptions>>]: AuthSqliteTableOf<PluginTableFields<TOptions, TTable>, ExistingColumns<TExisting, TTable & string>>; };
|
|
169
173
|
/** The Better Auth tables for Postgres, with the plugin tables and the plugin and additional columns of `TOptions`. */
|
|
170
|
-
export type AuthPostgresSchemaFor<TOptions extends AuthSchemaOptions> = { readonly [TModel in AuthTableName]: AuthPostgresTableOf<TableFields<TOptions, TModel>>; } & { readonly [TTable in keyof PluginTables<SchemaPlugins<TOptions>>]: AuthPostgresTableOf<PluginTableFields<TOptions, TTable>>; };
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
export type AuthPostgresSchemaFor<TOptions extends AuthSchemaOptions> = { readonly [TModel in AuthTableName]: AuthPostgresTableOf<TableFields<TOptions, TModel>, UuidIds<TOptions>>; } & { readonly [TTable in keyof PluginTables<SchemaPlugins<TOptions>>]: AuthPostgresTableOf<PluginTableFields<TOptions, TTable>, UuidIds<TOptions>>; };
|
|
175
|
+
declare global {
|
|
176
|
+
namespace ViteHub {
|
|
177
|
+
interface AuthRegistry {}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
type RegisteredAuthSchema<TExport extends string, TCore> = ViteHub.AuthRegistry extends {
|
|
181
|
+
schema: { readonly [K in TExport]: infer TSchema; };
|
|
182
|
+
} ? TSchema : TCore;
|
|
183
|
+
export declare const authSqliteSchema: RegisteredAuthSchema<"authSqliteSchema", AuthSqliteSchema>;
|
|
184
|
+
export declare const authPostgresSchema: RegisteredAuthSchema<"authPostgresSchema", AuthPostgresSchema>;
|
|
173
185
|
/**
|
|
174
186
|
* The Better Auth tables for SQLite, libSQL, and Cloudflare D1, with the plugins and additional fields of `options`. The
|
|
175
187
|
* Auth Vite plugin writes a module that calls it when the Auth Definition adds fields or imports a plugin of
|
|
@@ -180,6 +192,9 @@ export declare const authPostgresSchema: AuthPostgresSchema;
|
|
|
180
192
|
* snapshot literal when present.
|
|
181
193
|
*/
|
|
182
194
|
export declare function createAuthSqliteSchema<const TOptions extends AuthSchemaOptions, const TExisting extends AuthExistingTables | undefined = AuthExistingTables | undefined>(options: TOptions, existing?: TExisting): AuthSqliteSchemaFor<TOptions, TExisting>;
|
|
183
|
-
/**
|
|
195
|
+
/**
|
|
196
|
+
* The Better Auth tables for Postgres, with the plugins and additional fields of `options`, typed from its literal. With
|
|
197
|
+
* `generateId: "uuid"`, each `id` is `uuid` with a `gen_random_uuid()` default, and each column that references one is `uuid`.
|
|
198
|
+
*/
|
|
184
199
|
export declare function createAuthPostgresSchema<const TOptions extends AuthSchemaOptions>(options: TOptions): AuthPostgresSchemaFor<TOptions>;
|
|
185
200
|
export { type AuthCoreModel, type AuthCoreTableSpecs, type AuthPluginSchemas, type AuthSchemaOptions, type AuthSchemaPlugin, type AuthTableField, type AuthTableName, type AuthTableSpec, authPluginSchemas, authTableSpecs, resolveAuthTableSpecs };
|
package/dist/schema.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as resolveAuthTableSpecs, i as authTableSpecs, n as authPluginSchemas, r as authSqlName } from "./table-specs-Cvjc_Ccs.js";
|
|
2
2
|
import { sql } from "drizzle-orm";
|
|
3
|
-
import { bigint, boolean, foreignKey, index, integer, jsonb, pgTable, text, timestamp, uniqueIndex } from "drizzle-orm/pg-core";
|
|
4
|
-
import { foreignKey as foreignKey$1, index as index$1, integer as integer$1, sqliteTable, text as text$1, uniqueIndex as uniqueIndex$1 } from "drizzle-orm/sqlite-core";
|
|
3
|
+
import { bigint, boolean, foreignKey, index, integer, jsonb, pgTable, text, timestamp, uniqueIndex, uuid } from "drizzle-orm/pg-core";
|
|
4
|
+
import { customType, foreignKey as foreignKey$1, index as index$1, integer as integer$1, sqliteTable, text as text$1, uniqueIndex as uniqueIndex$1 } from "drizzle-orm/sqlite-core";
|
|
5
5
|
// src/schema.ts
|
|
6
6
|
const sameColumns = (left, right) => left.length === right.length && left.every((column, index) => column === right[index]);
|
|
7
7
|
const foreignKeyAction = (action) => action.toLowerCase();
|
|
@@ -13,7 +13,7 @@ function buildTables(dialect, specs, existing) {
|
|
|
13
13
|
const modelBySqlName = new Map(Object.keys(specs).map((model) => [authSqlName(model), model]));
|
|
14
14
|
for (const [model, spec] of Object.entries(specs)) {
|
|
15
15
|
const current = existing && Object.hasOwn(existing, authSqlName(model)) ? existing[authSqlName(model)] : void 0;
|
|
16
|
-
const columns = {
|
|
16
|
+
const columns = {};
|
|
17
17
|
const indexed = [];
|
|
18
18
|
const foreignKeys = [];
|
|
19
19
|
const indexName = (fields, unique, name) => current?.indexes.find((entry) => entry.unique === unique && sameColumns(entry.columns, fields.map(authSqlName)))?.name ?? name;
|
|
@@ -23,7 +23,7 @@ function buildTables(dialect, specs, existing) {
|
|
|
23
23
|
let builder = dialect.column(name, field);
|
|
24
24
|
if (column) {
|
|
25
25
|
if (column.default !== void 0) builder = builder.default(dialect.raw(column.default));
|
|
26
|
-
} else if (field.defaultValue !== void 0) builder = builder.default(field.defaultValue === "now" && field.type !== "string" ? field.type === "number" ? dialect.nowMs : dialect.now : field.defaultValue);
|
|
26
|
+
} else if (field.defaultValue !== void 0 && !(current && field.unique && !field.required)) builder = builder.default(field.defaultValue === "now" && field.type !== "string" ? field.type === "number" ? dialect.nowMs : dialect.now : field.defaultValue);
|
|
27
27
|
if (field.onUpdate) builder = builder.$onUpdate(() => /* @__PURE__ */ new Date());
|
|
28
28
|
if (column ? column.notNull : field.required && (!current || field.defaultValue !== void 0)) builder = builder.notNull();
|
|
29
29
|
if (field.unique) {
|
|
@@ -95,11 +95,26 @@ function buildTables(dialect, specs, existing) {
|
|
|
95
95
|
}
|
|
96
96
|
return tables;
|
|
97
97
|
}
|
|
98
|
+
function readSqliteJsonFromEitherAdapter(value) {
|
|
99
|
+
const parsed = typeof value === "string" ? JSON.parse(value) : value;
|
|
100
|
+
if (typeof parsed !== "string") return parsed;
|
|
101
|
+
try {
|
|
102
|
+
const legacy = JSON.parse(parsed);
|
|
103
|
+
return typeof legacy === "object" && legacy !== null ? legacy : parsed;
|
|
104
|
+
} catch {
|
|
105
|
+
return parsed;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const sqliteJson = customType({
|
|
109
|
+
dataType: () => "text",
|
|
110
|
+
toDriver: (value) => JSON.stringify(value),
|
|
111
|
+
fromDriver: readSqliteJsonFromEitherAdapter,
|
|
112
|
+
fromJson: readSqliteJsonFromEitherAdapter
|
|
113
|
+
});
|
|
98
114
|
const sqliteDialect = {
|
|
99
115
|
column(name, field) {
|
|
100
|
-
return field.type === "boolean" ? integer$1(name, { mode: "boolean" }) : field.type === "date" ? integer$1(name, { mode: "timestamp_ms" }) : field.type === "number" ? integer$1(name) : field.type === "string" ? text$1(name) :
|
|
116
|
+
return field.type === "boolean" ? integer$1(name, { mode: "boolean" }) : field.type === "date" ? integer$1(name, { mode: "timestamp_ms" }) : field.type === "number" ? integer$1(name) : field.type === "string" ? text$1(name) : sqliteJson(name);
|
|
101
117
|
},
|
|
102
|
-
id: () => text$1("id").primaryKey(),
|
|
103
118
|
index: (name, unique, columns) => (unique ? uniqueIndex$1(name) : index$1(name)).on(...columns),
|
|
104
119
|
foreignKey: (name, columns, foreignColumns, actions) => foreignKey$1({
|
|
105
120
|
name,
|
|
@@ -109,13 +124,15 @@ const sqliteDialect = {
|
|
|
109
124
|
now: sql`(cast(unixepoch('subsecond') * 1000 as integer))`,
|
|
110
125
|
nowMs: sql`(cast(unixepoch('subsecond') * 1000 as integer))`,
|
|
111
126
|
raw: (sqlText) => sql.raw(sqlText),
|
|
112
|
-
table: (name, columns, extras) => sqliteTable(name,
|
|
127
|
+
table: (name, columns, extras) => sqliteTable(name, {
|
|
128
|
+
id: text$1("id").primaryKey(),
|
|
129
|
+
...columns
|
|
130
|
+
}, (table) => extras(table))
|
|
113
131
|
};
|
|
114
|
-
const postgresDialect = {
|
|
132
|
+
const postgresDialect = (uuidIds) => ({
|
|
115
133
|
column(name, field) {
|
|
116
|
-
return field.type === "boolean" ? boolean(name) : field.type === "date" ? timestamp(name) : field.type === "number" ? field.bigint ? bigint(name, { mode: "number" }) : integer(name) : field.type === "string" ? text(name) : field.type === "string[]" ? text(name).array() : field.type === "number[]" ? integer(name).array() : jsonb(name);
|
|
134
|
+
return field.type === "boolean" ? boolean(name) : field.type === "date" ? timestamp(name) : field.type === "number" ? field.bigint ? bigint(name, { mode: "number" }) : integer(name) : field.type === "string" ? uuidIds && field.references?.field === "id" ? uuid(name) : text(name) : field.type === "string[]" ? text(name).array() : field.type === "number[]" ? (field.bigint ? bigint(name, { mode: "number" }) : integer(name)).array() : jsonb(name);
|
|
117
135
|
},
|
|
118
|
-
id: () => text("id").primaryKey(),
|
|
119
136
|
index: (name, unique, columns) => (unique ? uniqueIndex(name) : index(name)).on(...columns),
|
|
120
137
|
foreignKey: (name, columns, foreignColumns, actions) => foreignKey({
|
|
121
138
|
name,
|
|
@@ -125,10 +142,13 @@ const postgresDialect = {
|
|
|
125
142
|
now: sql`now()`,
|
|
126
143
|
nowMs: sql`(extract(epoch from now()) * 1000)::bigint`,
|
|
127
144
|
raw: (sqlText) => sql.raw(sqlText),
|
|
128
|
-
table: (name, columns, extras) => pgTable(name,
|
|
129
|
-
|
|
145
|
+
table: (name, columns, extras) => pgTable(name, {
|
|
146
|
+
id: uuidIds ? uuid("id").defaultRandom().primaryKey() : text("id").primaryKey(),
|
|
147
|
+
...columns
|
|
148
|
+
}, (table) => extras(table))
|
|
149
|
+
});
|
|
130
150
|
const authSqliteSchema = buildTables(sqliteDialect, authTableSpecs);
|
|
131
|
-
const authPostgresSchema = buildTables(postgresDialect, authTableSpecs);
|
|
151
|
+
const authPostgresSchema = buildTables(postgresDialect(false), authTableSpecs);
|
|
132
152
|
/**
|
|
133
153
|
* The Better Auth tables for SQLite, libSQL, and Cloudflare D1, with the plugins and additional fields of `options`. The
|
|
134
154
|
* Auth Vite plugin writes a module that calls it when the Auth Definition adds fields or imports a plugin of
|
|
@@ -141,8 +161,11 @@ const authPostgresSchema = buildTables(postgresDialect, authTableSpecs);
|
|
|
141
161
|
function createAuthSqliteSchema(options, existing) {
|
|
142
162
|
return buildTables(sqliteDialect, resolveAuthTableSpecs(options), existing);
|
|
143
163
|
}
|
|
144
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* The Better Auth tables for Postgres, with the plugins and additional fields of `options`, typed from its literal. With
|
|
166
|
+
* `generateId: "uuid"`, each `id` is `uuid` with a `gen_random_uuid()` default, and each column that references one is `uuid`.
|
|
167
|
+
*/
|
|
145
168
|
function createAuthPostgresSchema(options) {
|
|
146
|
-
return buildTables(postgresDialect, resolveAuthTableSpecs(options));
|
|
169
|
+
return buildTables(postgresDialect(options.generateId === "uuid"), resolveAuthTableSpecs(options));
|
|
147
170
|
}
|
|
148
171
|
export { authPluginSchemas, authPostgresSchema, authSqliteSchema, authTableSpecs, createAuthPostgresSchema, createAuthSqliteSchema, resolveAuthTableSpecs };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as AuthConsole } from "./console-runtime-
|
|
2
|
-
import { C as AuthGuardedHandler, E as AuthRequestInput,
|
|
3
|
-
import { i as AbilityName, n as AbilityAuthorization, t as AbilityArgs } from "./abilities-
|
|
4
|
-
import { o as McpTokenInvalidError } from "./mcp-token-
|
|
5
|
-
import "./server-
|
|
1
|
+
import { t as AuthConsole } from "./console-runtime-D2FUATXQ.js";
|
|
2
|
+
import { Bt as AuthEventWindow, C as AuthGuardedHandler, E as AuthRequestInput, G as ViteHubAuth, H as RegisteredAuth, It as AuthEventPage, Mt as AuthEventAggregates, N as AuthRuntimeOptions, Pt as AuthEventListInput, R as AuthSignInConfiguration, Rt as AuthEventStore, S as AuthFor, T as AuthRequest, U as ResolvedAuthAccessRoute, _ as AuthDefinition, at as AuthConsoleHostOptions, d as AuthAnonymousGuardedHandler, h as AuthBetterAuthRuntimeOptions, p as AuthAuthorization, u as AuthAnonymousAuthorize } from "./types-DakualFJ.js";
|
|
3
|
+
import { i as AbilityName, n as AbilityAuthorization, t as AbilityArgs } from "./abilities-6LE7VSdN.js";
|
|
4
|
+
import { o as McpTokenInvalidError } from "./mcp-token-CxpopXmK.js";
|
|
5
|
+
import "./server-DAIBBKbR.js";
|
|
6
6
|
import "./ability-error-C1c30O6E.js";
|
|
7
7
|
import { AccessAuthorizeOption, Result, ResultError, ViteHubContext } from "@vite-hub/runtime";
|
|
8
8
|
import { APIError } from "better-auth/api";
|
|
@@ -53,9 +53,7 @@ declare function authForRequest(request: Pick<Request, "headers" | "url">, event
|
|
|
53
53
|
* and the Cache-Control of the route becomes `private`, unless it already has `private` or `no-store`.
|
|
54
54
|
*/
|
|
55
55
|
declare function sendSessionCookies<T>(input: AuthRequestInput, outcome: T): T | Response;
|
|
56
|
-
/** Where Better Auth returns after one sign-in that a guard starts. */
|
|
57
56
|
type AuthSignInURLs = Pick<AuthProviderSignIn, "callbackURL" | "errorCallbackURL">;
|
|
58
|
-
/** A provider sign-in with the page that Better Auth returns to. */
|
|
59
57
|
type AuthProviderSignIn = AuthSignInConfiguration & {
|
|
60
58
|
callbackURL?: string;
|
|
61
59
|
};
|
|
@@ -144,6 +142,25 @@ declare function requireAuth(event: AuthRequestInput, definition: AuthDefinition
|
|
|
144
142
|
*/
|
|
145
143
|
declare function requireAuthorization<TInput extends AuthRequestInput>(event: TInput, authorize: AccessAuthorizeOption<TInput & ViteHubContext>, definition?: undefined): Promise<AuthAuthorization>;
|
|
146
144
|
declare function requireAuthorization<TInput extends AuthRequestInput>(event: TInput, authorize: AccessAuthorizeOption<TInput & ViteHubContext, false>, definition: AuthDefinition | undefined): Promise<CoreAuthorization>;
|
|
145
|
+
/**
|
|
146
|
+
* Route middleware that checks access before H3 applies `validate.query` and `validate.headers`.
|
|
147
|
+
* Put it in `middleware` of `defineHandler()` or `defineValidatedHandler()`.
|
|
148
|
+
* It returns nothing when the check passes, so the route answers with its handler.
|
|
149
|
+
* Without `authorize`, it rejects like `requireAuth()`. With `authorize`, it rejects like `requireAuthorization()`.
|
|
150
|
+
* For path parameters, call H3's `getValidatedRouterParams(event, schema)` in the handler after checking access.
|
|
151
|
+
*
|
|
152
|
+
* ```ts [server/api/inbox.get.ts]
|
|
153
|
+
* export default defineValidatedHandler({
|
|
154
|
+
* middleware: [authMiddleware()],
|
|
155
|
+
* validate: { query: v.object({ view: v.picklist(["open", "archived"]) }) },
|
|
156
|
+
* handler: async (event) => {
|
|
157
|
+
* const { user } = await requireAuth(event)
|
|
158
|
+
* return listInbox(user.id, event.url.searchParams.get("view"))
|
|
159
|
+
* },
|
|
160
|
+
* })
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
declare function authMiddleware<TInput extends AuthRequestInput>(authorize?: AccessAuthorizeOption<TInput & ViteHubContext>): (event: TInput) => Promise<void>;
|
|
147
164
|
/**
|
|
148
165
|
* Return who calls: a person with an Auth Session (`kind: "browser"`), or an Agent with an MCP access token of
|
|
149
166
|
* `mcpOAuth()` (`kind: "agent"`), checked like `verifyMcpRequest()`. The longest matching resource path wins. At that
|
|
@@ -212,4 +229,4 @@ declare function aggregateAuthEvents(window: AuthEventWindow, definition?: AuthD
|
|
|
212
229
|
* `host.impersonation` lets the Console start impersonation. It is off by default.
|
|
213
230
|
*/
|
|
214
231
|
declare function getAuthConsoleForRequest(request: Request, event?: ViteHubContext, host?: AuthConsoleHostOptions): AuthConsole;
|
|
215
|
-
export {
|
|
232
|
+
export { withAuthorization as A, AuthCallerUser as B, requireAuthorization as C, useAuth as D, toAuthRequest as E, getAuthForDefinition as F, AuthCaller as I, AuthCallerError as L, authForRequest as M, createBetterAuthOptions as N, withAnonymousAuthorization as O, findVerifiedAuthUserId as P, AuthCallerErrorCode as R, requireAuthAccessRoutes as S, signOut as T, AuthMemberErrorCode as V, handleAuth as _, authMiddleware as a, requireAbility as b, checkAuthMember as c, createAuthForRequest as d, createAuthHandler as f, getAuthEvents as g, getAuthConsoleForRequest as h, assertAuthOrigin as i, sendSessionCookies as j, withAuth as k, createAuth as l, getAuth as m, AuthSignOutOptions as n, authRoute as o, createAuthRequestRuntimeOptions as p, aggregateAuthEvents as r, can as s, AuthEventReadErrorCode as t, createAuthAccessHandler as u, handleAuthRequest as v, requireCaller as w, requireAuth as x, listAuthEvents as y, AuthCallerResult as z };
|