@vite-hub/auth 0.1.0 → 0.3.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 +333 -49
- package/dist/abilities-DfAnFYwG.d.ts +93 -0
- package/dist/abilities.d.ts +2 -0
- package/dist/abilities.js +43 -0
- package/dist/ability-error-CqgBrBfR.js +91 -0
- package/dist/ability-error-DcgChwCN.d.ts +34 -0
- package/dist/admin-claim-code-CDipqeAU.js +22 -0
- package/dist/agent.d.ts +5 -5
- package/dist/agent.js +17 -9
- package/dist/application-path-DuTpfGFj.js +62 -0
- package/dist/auth-instance-CR6b1W80.js +1168 -0
- package/dist/bun-sqlite.d.ts +8 -0
- package/dist/cli-ubYJpAL_.d.ts +163 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +47 -7
- package/dist/console-runtime-DTopBP-x.d.ts +71 -0
- package/dist/console-runtime-J9_Vx9pT.js +1166 -0
- package/dist/console-runtime.d.ts +3 -3
- package/dist/console-runtime.js +2 -819
- package/dist/console.d.ts +215 -3
- package/dist/console.js +1 -1
- package/dist/database-options-BRNef9oy.js +29 -0
- package/dist/database-schema-options-ENuRMduM.js +12 -0
- package/dist/database.d.ts +12 -0
- package/dist/database.js +45 -0
- package/dist/definition-CqQMcDEK.js +280 -0
- package/dist/error-diagnostics-C8XtVz0i.js +138 -0
- package/dist/{events-P7mI4IQb.js → events-ByzenEVj.js} +122 -4
- package/dist/forward.d.ts +50 -0
- package/dist/forward.js +120 -0
- package/dist/host-declarations.d.ts +2 -1
- package/dist/index.d.ts +24 -3
- package/dist/index.js +3 -102
- package/dist/internal/server.d.ts +5 -0
- package/dist/internal/server.js +858 -0
- package/dist/invariant-D8_xBqmZ.js +22 -0
- package/dist/mcp.d.ts +187 -0
- package/dist/mcp.js +353 -0
- package/dist/members-D9lfaEO_.js +533 -0
- package/dist/nuxt-bridge-Cl988STZ.js +44 -0
- package/dist/nuxt.d.ts +13 -5
- package/dist/nuxt.js +90 -13
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/page-tools-shared-l4eyj53D.js +19 -0
- package/dist/presets.js +1 -1
- package/dist/request-z6DHHmrb.js +47 -0
- package/dist/runtime/console.d.ts +3 -7
- package/dist/runtime/console.js +4 -42
- package/dist/runtime/empty-abilities.d.ts +5 -0
- package/dist/runtime/empty-abilities.js +4 -0
- package/dist/runtime/empty-client.d.ts +6 -0
- package/dist/runtime/empty-client.js +5 -0
- package/dist/runtime/empty-definition.d.ts +1 -1
- package/dist/runtime/nuxt.js +1 -1
- package/dist/runtime/server.d.ts +2 -0
- package/dist/runtime/server.js +77 -0
- package/dist/runtime/vue-nuxt.d.ts +3 -2
- package/dist/runtime/vue-nuxt.js +157 -5
- package/dist/runtime-state-ojQCzKOc.js +25 -0
- package/dist/schema.d.ts +137 -0
- package/dist/schema.js +147 -0
- package/dist/server-C0qnKN2W.d.ts +143 -0
- package/dist/server-bQGzVQ--.d.ts +41 -0
- package/dist/server.d.ts +3 -2
- package/dist/server.js +3 -3
- package/dist/session-cookies-BbH3UR2m.js +227 -0
- package/dist/{set-cookie-2as_DbHe.js → set-cookie-C8NOhdRE.js} +27 -12
- package/dist/{shared-DnpgYiLF.js → shared-BwcdRGxD.js} +2 -5
- package/dist/table-specs-8gq_FCaq.js +771 -0
- package/dist/table-specs-DbXyaXWs.d.ts +842 -0
- package/dist/test.d.ts +26 -0
- package/dist/test.js +25 -0
- package/dist/{events-BkmK2dFY.d.ts → types-CNaeH2Fd.d.ts} +240 -157
- package/dist/vite-CV400XXY.js +1556 -0
- package/dist/vite.d.ts +138 -20
- package/dist/vite.js +2 -2
- package/dist/vue.d.ts +330 -21
- package/dist/vue.js +583 -36
- package/package.json +84 -15
- package/dist/application-path-C290OAIs.js +0 -18
- package/dist/cli-mgXvsBtA.d.ts +0 -85
- package/dist/console-B7eERmGv.d.ts +0 -180
- package/dist/console-runtime-bZQtnX2Y.d.ts +0 -39
- package/dist/error-diagnostics-CL0yjHiM.js +0 -79
- package/dist/events-config-CjcFOhTE.js +0 -177
- package/dist/inspect-DPtsW8dB.d.ts +0 -36
- package/dist/server-B7LU19dS.js +0 -1730
- package/dist/server-CTD_JAww.d.ts +0 -77
- package/dist/vite-COWkwxsj.js +0 -990
package/dist/test.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { g as AuthDefinition } from "./types-CNaeH2Fd.js";
|
|
2
|
+
import { Session, User } from "better-auth";
|
|
3
|
+
//#region src/test.d.ts
|
|
4
|
+
/** The user to sign in. Auth creates it when no user has this email. Other fields, such as `role`, go to the new user. */
|
|
5
|
+
export interface SignInTestUser {
|
|
6
|
+
email?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
[field: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
/** A signed-in session for app tests. */
|
|
11
|
+
export interface TestSignIn {
|
|
12
|
+
/** The `cookie` header of the session, such as `better-auth.session_token=…`. */
|
|
13
|
+
cookie: string;
|
|
14
|
+
/** Headers with the session cookie. Pass them to a `Request` so that `requireAuth()` accepts it. */
|
|
15
|
+
headers: Headers;
|
|
16
|
+
session: Session;
|
|
17
|
+
user: User;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Signs in a user of the app's Auth Definition and returns the session cookie. It writes the user and the session to the
|
|
21
|
+
* Auth database, as a real sign-in does, so `requireAuth()`, `useAuth().api.getSession()`, and abilities accept the
|
|
22
|
+
* request. It sends no email and calls no provider. A Definition with the `stateless()` preset has no database, so it
|
|
23
|
+
* fails with `AUTH_TEST_SIGN_IN_STATELESS`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function signIn(user?: SignInTestUser, definition?: AuthDefinition): Promise<TestSignIn>;
|
|
26
|
+
//#endregion
|
package/dist/test.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-C8XtVz0i.js";
|
|
2
|
+
import { o as resolveDefaultDefinition, t as authForRequest } from "./auth-instance-CR6b1W80.js";
|
|
3
|
+
import { testUtils } from "better-auth/plugins";
|
|
4
|
+
//#region src/test.ts
|
|
5
|
+
/**
|
|
6
|
+
* Signs in a user of the app's Auth Definition and returns the session cookie. It writes the user and the session to the
|
|
7
|
+
* Auth database, as a real sign-in does, so `requireAuth()`, `useAuth().api.getSession()`, and abilities accept the
|
|
8
|
+
* request. It sends no email and calls no provider. A Definition with the `stateless()` preset has no database, so it
|
|
9
|
+
* fails with `AUTH_TEST_SIGN_IN_STATELESS`.
|
|
10
|
+
*/
|
|
11
|
+
async function signIn(user = {}, definition = resolveDefaultDefinition()) {
|
|
12
|
+
const context = await authForRequest(new Request("http://localhost/"), void 0, definition).$context;
|
|
13
|
+
if (!context.options.database) throw authErrorDiagnostics.AUTH_TEST_SIGN_IN_STATELESS();
|
|
14
|
+
const helpers = testUtils().init(context).context.test;
|
|
15
|
+
const saved = (user.email ? await context.internalAdapter.findUserByEmail(user.email) : null)?.user ?? await helpers.saveUser(helpers.createUser(user));
|
|
16
|
+
const { headers, session } = await helpers.login({ userId: saved.id });
|
|
17
|
+
return {
|
|
18
|
+
cookie: headers.get("cookie"),
|
|
19
|
+
headers,
|
|
20
|
+
session,
|
|
21
|
+
user: saved
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { signIn };
|
|
@@ -1,7 +1,112 @@
|
|
|
1
1
|
import { n as AuthPreset } from "./presets-BGZi6Dfu.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { r as AuthSchemaOptions } from "./table-specs-DbXyaXWs.js";
|
|
3
|
+
import { AccessAuthorizationContext, AccessAuthorize, AccessAuthorizeResult, AnonymousAccessAuthorizationContext, AnonymousAccessAuthorize } from "@vite-hub/runtime";
|
|
4
|
+
import { ViteHubContext as ViteHubContext$1 } from "@vite-hub/runtime/internal/h3";
|
|
5
|
+
import { Auth, BetterAuthOptions, DBAdapter, Session, User } from "better-auth";
|
|
4
6
|
import { EnvDatabase } from "@vite-hub/env/database";
|
|
7
|
+
//#region src/events.d.ts
|
|
8
|
+
declare const authEventTypes: readonly ["user.signed_up", "user.signed_in", "user.signed_out", "sign_in.failed", "session.revoked", "user.banned", "user.unbanned", "user.role_changed", "user.updated", "user.removed", "impersonation.started", "impersonation.stopped", "oauth.consent_granted", "oauth.consent_revoked", "organization.member_added", "organization.member_removed", "organization.member_role_changed"];
|
|
9
|
+
type AuthEventType = typeof authEventTypes[number];
|
|
10
|
+
type AuthEventActor = "system" | `user:${string}`;
|
|
11
|
+
type AuthDevice = "desktop" | "mobile" | "tablet" | "bot" | "unknown";
|
|
12
|
+
/** Only these fields cross the persistence boundary. No request bodies or headers are stored. */
|
|
13
|
+
interface AuthEventMetadata {
|
|
14
|
+
method?: string;
|
|
15
|
+
device?: AuthDevice;
|
|
16
|
+
sessionId?: string;
|
|
17
|
+
fields?: string[];
|
|
18
|
+
role?: string;
|
|
19
|
+
clientId?: string;
|
|
20
|
+
organizationId?: string;
|
|
21
|
+
memberId?: string;
|
|
22
|
+
}
|
|
23
|
+
interface AuthEvent {
|
|
24
|
+
id: string;
|
|
25
|
+
type: AuthEventType;
|
|
26
|
+
time: string;
|
|
27
|
+
actor: AuthEventActor;
|
|
28
|
+
/** Unknown for failed sign-ins. The log does not look up untrusted email addresses. */
|
|
29
|
+
userId: string | null;
|
|
30
|
+
metadata: AuthEventMetadata;
|
|
31
|
+
}
|
|
32
|
+
interface AuthEventListInput {
|
|
33
|
+
type?: AuthEventType | readonly AuthEventType[];
|
|
34
|
+
userId?: string;
|
|
35
|
+
actor?: AuthEventActor;
|
|
36
|
+
/** Inclusive ISO timestamp. */
|
|
37
|
+
from?: string;
|
|
38
|
+
/** Exclusive ISO timestamp. */
|
|
39
|
+
to?: string;
|
|
40
|
+
cursor?: string;
|
|
41
|
+
limit?: number;
|
|
42
|
+
}
|
|
43
|
+
interface AuthEventPage {
|
|
44
|
+
events: AuthEvent[];
|
|
45
|
+
nextCursor?: string;
|
|
46
|
+
}
|
|
47
|
+
interface AuthEventWindow {
|
|
48
|
+
from: string;
|
|
49
|
+
to: string;
|
|
50
|
+
}
|
|
51
|
+
interface AuthEventCounts {
|
|
52
|
+
signUps: number;
|
|
53
|
+
signIns: number;
|
|
54
|
+
/** Distinct users with a recorded sign-in. Includes the session created at sign-up. */
|
|
55
|
+
activeUsers: number;
|
|
56
|
+
methods: Record<string, number>;
|
|
57
|
+
}
|
|
58
|
+
interface AuthEventAggregates {
|
|
59
|
+
days: Array<AuthEventCounts & {
|
|
60
|
+
day: string;
|
|
61
|
+
}>;
|
|
62
|
+
totals: AuthEventCounts;
|
|
63
|
+
}
|
|
64
|
+
interface AuthEventRetention {
|
|
65
|
+
maxAgeMs?: number;
|
|
66
|
+
maxRecords?: number;
|
|
67
|
+
}
|
|
68
|
+
interface AuthEventStore {
|
|
69
|
+
append: (event: AuthEvent) => Promise<void>;
|
|
70
|
+
list: (input?: AuthEventListInput) => Promise<AuthEventPage>;
|
|
71
|
+
aggregate: (window: AuthEventWindow) => Promise<AuthEventAggregates>;
|
|
72
|
+
}
|
|
73
|
+
interface AuthEventsConfiguration {
|
|
74
|
+
store: AuthEventStore;
|
|
75
|
+
/** Enable the CLI read endpoint. A session and an explicit true result are required. A Response is sent as the rejection. */
|
|
76
|
+
authorize?: AuthAccessAuthorize;
|
|
77
|
+
/**
|
|
78
|
+
* Runs for each event after the store records it, for example to send it to another service. With a host `waitUntil()`, it
|
|
79
|
+
* runs after the response. A failure is logged as `AUTH_EVENT_CALLBACK_FAILED` and never fails the auth request.
|
|
80
|
+
*/
|
|
81
|
+
onEvent?: (event: AuthEvent) => void | Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
declare const defaultAuthEventRetention: Required<AuthEventRetention>;
|
|
84
|
+
/** One SQLite store contract for Node SQLite, libSQL, and Cloudflare D1 Drizzle databases. */
|
|
85
|
+
declare function createDatabaseAuthEventStore(options: {
|
|
86
|
+
db: EnvDatabase;
|
|
87
|
+
retention?: AuthEventRetention | false;
|
|
88
|
+
}): AuthEventStore;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/nuxt-types.d.ts
|
|
91
|
+
/** Who may open a page: signed-in users (`user`) or signed-out visitors (`guest`). */
|
|
92
|
+
type AuthPageMode = "guest" | "user";
|
|
93
|
+
/**
|
|
94
|
+
* The `auth` key of `definePageMeta()` in Nuxt. `'user'` or `true` sends visitors without a session to the login
|
|
95
|
+
* page. `'guest'` sends signed-in users away, for example from the login page. `false` turns the guard off.
|
|
96
|
+
*/
|
|
97
|
+
type AuthPageMeta = boolean | AuthPageMode | {
|
|
98
|
+
only?: AuthPageMode;
|
|
99
|
+
/** Where to send the visitor instead of the configured redirect. */
|
|
100
|
+
redirectTo?: string;
|
|
101
|
+
};
|
|
102
|
+
/** Where the Nuxt page guard sends visitors. */
|
|
103
|
+
interface AuthRedirects {
|
|
104
|
+
/** The login page for `auth: 'user'` pages. The guard adds `?redirect=<the page>`. Default `/login`. */
|
|
105
|
+
login?: string;
|
|
106
|
+
/** Where signed-in users go from `auth: 'guest'` pages. Default `/`. */
|
|
107
|
+
guest?: string;
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
5
110
|
//#region src/console-types.d.ts
|
|
6
111
|
type AuthConsoleValue = string | number | boolean | null | string[] | number[];
|
|
7
112
|
type AuthConsoleFieldType = "string" | "number" | "boolean" | "date" | "string[]" | "number[]" | "json";
|
|
@@ -32,13 +137,22 @@ type AuthConsoleColumn = {
|
|
|
32
137
|
type: "boolean";
|
|
33
138
|
read: ColumnReader<boolean>;
|
|
34
139
|
});
|
|
140
|
+
/**
|
|
141
|
+
* Roles that the app computes, such as from an environment variable. The Console shows them and its Admins filter
|
|
142
|
+
* uses them. `null` keeps the stored role. Better Auth's own endpoints still read the stored `user.role`.
|
|
143
|
+
*/
|
|
144
|
+
interface AuthConsoleRoles {
|
|
145
|
+
editable: false;
|
|
146
|
+
reason: string;
|
|
147
|
+
read: ColumnReader<string>;
|
|
148
|
+
}
|
|
35
149
|
/** Host-independent display and edit policy. It does not grant Better Auth permissions. */
|
|
36
150
|
interface AuthConsoleOptions {
|
|
37
151
|
access?: readonly string[];
|
|
38
152
|
actions?: Partial<Record<AuthConsoleAction, AuthConsolePolicy>>;
|
|
39
153
|
columns?: Readonly<Record<string, AuthConsoleColumn>>;
|
|
40
154
|
fields?: Readonly<Record<string, AuthConsoleFieldPolicy | undefined>>;
|
|
41
|
-
roles?: AuthConsolePolicy;
|
|
155
|
+
roles?: AuthConsolePolicy | AuthConsoleRoles;
|
|
42
156
|
}
|
|
43
157
|
interface AuthConsoleCapability {
|
|
44
158
|
enabled: boolean;
|
|
@@ -68,6 +182,36 @@ interface AuthConsoleDescription {
|
|
|
68
182
|
interface AuthConsoleHostOptions {
|
|
69
183
|
/** Let the Console start and stop Better Auth admin impersonation. Off by default. */
|
|
70
184
|
impersonation?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* A verified OAuth user and the token's login session. Trusted server hosts set this only after checking the token
|
|
187
|
+
* and their access policy. Auth uses that stored session for its APIs; browser cookies cannot change the actor.
|
|
188
|
+
* Tokens without a login session cannot run Auth changes. Impersonation always needs the browser session.
|
|
189
|
+
*/
|
|
190
|
+
bearer?: {
|
|
191
|
+
user: Pick<User, "id">;
|
|
192
|
+
sessionId?: string;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* The person of a signed ViteHub Console call. Trusted server hosts set this only after they check the signature and
|
|
196
|
+
* their access policy. Auth changes run as the app user with this email, with the newest live app session of that
|
|
197
|
+
* user that is not an impersonation, and only inside this API. Browser cookies cannot change the actor. Without an
|
|
198
|
+
* app user or a live session, Auth changes are refused. Impersonation always needs the browser session.
|
|
199
|
+
*/
|
|
200
|
+
actor?: {
|
|
201
|
+
email: string;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/** The app session of a request, as `session(request)` returns it. */
|
|
205
|
+
interface AuthConsoleSessionUser {
|
|
206
|
+
user: {
|
|
207
|
+
id: string;
|
|
208
|
+
email: string;
|
|
209
|
+
};
|
|
210
|
+
/** The administrator who opened this session as `user`, or `null` when the session is not an impersonation. */
|
|
211
|
+
impersonatedBy: {
|
|
212
|
+
id: string;
|
|
213
|
+
email: string;
|
|
214
|
+
} | null;
|
|
71
215
|
}
|
|
72
216
|
interface AuthConsoleImpersonation {
|
|
73
217
|
/** Seconds until an impersonation session ends. Better Auth's `admin({ impersonationSessionDuration })` sets it. */
|
|
@@ -138,6 +282,24 @@ interface AuthConsoleSession {
|
|
|
138
282
|
expiresAt: string;
|
|
139
283
|
updatedAt: string;
|
|
140
284
|
}
|
|
285
|
+
/** A user that a host signs in without a password, such as a Console member or an invited guest. */
|
|
286
|
+
interface AuthConsoleHostUserInput {
|
|
287
|
+
/** The email of an existing person. Without it, the user is new and gets a placeholder email. */
|
|
288
|
+
email?: string;
|
|
289
|
+
name: string;
|
|
290
|
+
image?: string;
|
|
291
|
+
/** Roles to add to the comma-separated `user.role` of `admin()`. */
|
|
292
|
+
roles: readonly string[];
|
|
293
|
+
/**
|
|
294
|
+
* Roles that the host owns. An existing user loses those of them that `roles` does not name, so a host can take a
|
|
295
|
+
* role back. Other roles of the user stay.
|
|
296
|
+
*/
|
|
297
|
+
owned?: readonly string[];
|
|
298
|
+
}
|
|
299
|
+
/** A live session of a user that holds a host role, with the user's roles. */
|
|
300
|
+
interface AuthConsoleHostSession extends AuthConsoleSession {
|
|
301
|
+
roles: string[];
|
|
302
|
+
}
|
|
141
303
|
interface AuthConsoleAgent {
|
|
142
304
|
id: string;
|
|
143
305
|
clientId: string;
|
|
@@ -231,7 +393,7 @@ declare global {
|
|
|
231
393
|
}
|
|
232
394
|
}
|
|
233
395
|
type AuthRuntimeOption = "baseURL" | "secret" | "secrets";
|
|
234
|
-
type AuthReservedOption = AuthRuntimeOption | "events" | "console" | "access" | "basePath" | "database" | "preset" | "route" | "runtime" | "secondaryStorage";
|
|
396
|
+
type AuthReservedOption = AuthRuntimeOption | "events" | "console" | "access" | "adminClaim" | "basePath" | "database" | "preset" | "route" | "runtime" | "secondaryStorage";
|
|
235
397
|
type AuthBetterAuthOptions = Omit<BetterAuthOptions, AuthReservedOption | "session"> & {
|
|
236
398
|
session?: AuthSessionOptions;
|
|
237
399
|
};
|
|
@@ -259,11 +421,11 @@ interface AuthRuntimeContext<TEnv extends Record<string, unknown> = AuthRuntimeE
|
|
|
259
421
|
request?: Pick<Request, "headers" | "url">;
|
|
260
422
|
requestOrigin: string;
|
|
261
423
|
}
|
|
262
|
-
type AuthRuntimeOptions = Partial<Omit<BetterAuthOptions, "basePath">> & {
|
|
424
|
+
type AuthRuntimeOptions = Partial<Omit<BetterAuthOptions, "basePath" | "database">> & {
|
|
425
|
+
/** A Better Auth adapter, or `"memory"` to keep users and sessions in the memory of one server process. */
|
|
426
|
+
database?: BetterAuthOptions["database"] | "memory";
|
|
263
427
|
events?: AuthEventsConfiguration | false;
|
|
264
428
|
};
|
|
265
|
-
type AuthRuntimeOptionsResolver = (context: AuthRuntimeContext) => AuthRuntimeOptions;
|
|
266
|
-
type AuthRuntimeConfiguration = AuthRuntimeOptions | AuthRuntimeOptionsResolver;
|
|
267
429
|
interface AuthSignInConfiguration {
|
|
268
430
|
callbackURL?: string;
|
|
269
431
|
errorCallbackURL?: string;
|
|
@@ -277,11 +439,11 @@ interface AuthAccessRouteConfiguration {
|
|
|
277
439
|
route: string;
|
|
278
440
|
}
|
|
279
441
|
type AuthAccessRoute = string | AuthAccessRouteConfiguration;
|
|
280
|
-
type AuthAccessAuthorizationContext = AccessAuthorizationContext
|
|
442
|
+
type AuthAccessAuthorizationContext<TEvent = ViteHubContext$1> = AccessAuthorizationContext<TEvent>;
|
|
281
443
|
type AuthAccessAuthorizeResult = AccessAuthorizeResult;
|
|
282
|
-
type AuthAccessAuthorize = AccessAuthorize
|
|
444
|
+
type AuthAccessAuthorize<TEvent = ViteHubContext$1> = AccessAuthorize<TEvent>;
|
|
283
445
|
/** The checked request, Session, and user that a guarded handler receives. Only Auth guards create it. */
|
|
284
|
-
type AuthAuthorization = Readonly<AuthAccessAuthorizationContext & {
|
|
446
|
+
type AuthAuthorization = Readonly<Omit<AuthAccessAuthorizationContext, "event"> & {
|
|
285
447
|
/** `impersonatedBy` is the id of the administrator who opened this session as `user`. Better Auth's admin plugin sets it. */
|
|
286
448
|
session: AuthAccessAuthorizationContext["session"] & {
|
|
287
449
|
impersonatedBy?: string | null;
|
|
@@ -289,43 +451,63 @@ type AuthAuthorization = Readonly<AuthAccessAuthorizationContext & {
|
|
|
289
451
|
}>;
|
|
290
452
|
/** A server handler that runs only after an Auth guard accepts the request. */
|
|
291
453
|
type AuthGuardedHandler<TInput, TResult> = (input: TInput, authorization: AuthAuthorization) => TResult | Promise<TResult>;
|
|
292
|
-
/**
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
*/
|
|
296
|
-
type
|
|
454
|
+
/** The checked request of a signed-out caller that `withAnonymousAuthorization()` accepted. */
|
|
455
|
+
type AuthAnonymousAuthorization = Readonly<Omit<AnonymousAccessAuthorizationContext, "event">>;
|
|
456
|
+
type AuthAnonymousAuthorize<TEvent = ViteHubContext$1> = AnonymousAccessAuthorize<TEvent>;
|
|
457
|
+
/** A server handler that runs after `authorize` accepts a signed-in or signed-out caller. */
|
|
458
|
+
type AuthAnonymousGuardedHandler<TInput, TResult> = (input: TInput, authorization: AuthAuthorization | AuthAnonymousAuthorization) => TResult | Promise<TResult>;
|
|
459
|
+
/** What `access.policy.allow` gets: the user, and the provider access tokens of the user's accounts. */
|
|
460
|
+
interface AuthAccessPolicyContext {
|
|
461
|
+
user: User & Record<string, unknown>;
|
|
462
|
+
/** The access token of the user's account with this provider, such as `github`, or `null` when the user has none. */
|
|
463
|
+
accessToken: (providerId: string) => Promise<string | null>;
|
|
464
|
+
}
|
|
465
|
+
/** Who may use the app. Auth asks it at sign-in and again after `recheck`, for sessions and MCP access tokens. */
|
|
466
|
+
interface AuthAccessPolicy {
|
|
467
|
+
/**
|
|
468
|
+
* Return `true` to let the user in. Any other value refuses the sign-in, or ends the session. When it throws, the
|
|
469
|
+
* request fails and the session stays.
|
|
470
|
+
*/
|
|
471
|
+
allow: (context: AuthAccessPolicyContext) => boolean | Promise<boolean>;
|
|
472
|
+
/** Milliseconds that an allowed answer holds for one session or one MCP user. `0` asks on each request. Default: 300000. */
|
|
473
|
+
recheck?: number;
|
|
474
|
+
}
|
|
297
475
|
interface AuthAccessConfiguration {
|
|
298
476
|
routes?: AuthAccessRoute[];
|
|
477
|
+
/** Paths that no access route guards, in the same form as `routes`. With `routes: ['/**']`, these are the only paths a signed-out visitor reaches. */
|
|
478
|
+
public?: string[];
|
|
479
|
+
policy?: AuthAccessPolicy;
|
|
299
480
|
signIn?: AuthSignInConfiguration;
|
|
300
481
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
type AuthDatabaseConfiguration = true | AuthDatabaseReference;
|
|
306
|
-
interface AuthSecondaryStorageReference {
|
|
307
|
-
store: string;
|
|
308
|
-
}
|
|
309
|
-
type AuthSecondaryStorageConfiguration = true | AuthSecondaryStorageReference;
|
|
482
|
+
/** The Better Auth adapter of `authDatabase()`. `vitehubDatabase` names the app Database that holds the Auth tables. */
|
|
483
|
+
type AuthAppDatabase = ((options: BetterAuthOptions) => DBAdapter<BetterAuthOptions>) & {
|
|
484
|
+
readonly vitehubDatabase: string;
|
|
485
|
+
};
|
|
310
486
|
interface AuthViteHubOptions {
|
|
487
|
+
/** Ignore `VITEHUB_ADMIN_CLAIM` for this Auth Definition. Independent Console Auth sets this to `false`. */
|
|
488
|
+
adminClaim?: false;
|
|
311
489
|
/** Opt in to durable auth events with an explicit store. */
|
|
312
490
|
events?: AuthEventsConfiguration | false;
|
|
313
491
|
console?: AuthConsoleOptions;
|
|
314
492
|
access?: AuthAccessConfiguration;
|
|
315
493
|
basePath?: string;
|
|
316
|
-
|
|
317
|
-
|
|
494
|
+
/**
|
|
495
|
+
* `authDatabase()` from `vite-hub/auth/database` keeps users and sessions in the app Database. Return another Better
|
|
496
|
+
* Auth adapter from the Definition callback. `"memory"` keeps them in the memory of one server process,
|
|
497
|
+
* and a restart removes them. Without `database` or `preset`, Auth uses memory only on a development server.
|
|
498
|
+
*/
|
|
499
|
+
database?: AuthAppDatabase | "memory";
|
|
500
|
+
/** A ViteHub Auth preset, such as `stateless()` from `vite-hub/auth/presets`. ViteHub checks it against the other options. */
|
|
318
501
|
preset?: AuthPreset;
|
|
319
502
|
route?: false;
|
|
320
|
-
|
|
321
|
-
|
|
503
|
+
/** Removed. Pass a callback that returns all options: `defineAuth(({ env }) => ({ ... }))`. */
|
|
504
|
+
runtime?: never;
|
|
505
|
+
/** Return a Better Auth `secondaryStorage` adapter from the Definition callback. */
|
|
506
|
+
secondaryStorage?: never;
|
|
322
507
|
}
|
|
323
508
|
type AuthRuntimeOnlyOptions = { [Key in AuthRuntimeOption]?: never; };
|
|
324
|
-
type AuthDefinitionOptions<TOptions extends AuthBetterAuthOptions = AuthBetterAuthOptions> = TOptions & AuthViteHubOptions & AuthRuntimeOnlyOptions;
|
|
325
|
-
type AuthResolvedDefinitionOptions<TOptions extends AuthBetterAuthOptions = AuthBetterAuthOptions> = TOptions & Omit<AuthViteHubOptions, "database" | "
|
|
326
|
-
database?: AuthDatabaseConfiguration | BetterAuthOptions["database"];
|
|
327
|
-
secondaryStorage?: AuthSecondaryStorageConfiguration | BetterAuthOptions["secondaryStorage"];
|
|
328
|
-
};
|
|
509
|
+
type AuthDefinitionOptions<TOptions extends AuthBetterAuthOptions = AuthBetterAuthOptions> = TOptions & Omit<AuthViteHubOptions, Extract<keyof TOptions, "database">> & AuthRuntimeOnlyOptions;
|
|
510
|
+
type AuthResolvedDefinitionOptions<TOptions extends AuthBetterAuthOptions = AuthBetterAuthOptions> = TOptions & Omit<AuthViteHubOptions, "database" | "secondaryStorage"> & AuthRuntimeOptions;
|
|
329
511
|
type AuthDefinitionResolver<TOptions extends AuthResolvedDefinitionOptions = AuthResolvedDefinitionOptions> = (context: AuthRuntimeContext) => TOptions;
|
|
330
512
|
type AuthDefinitionInput = AuthDefinitionOptions | AuthDefinitionResolver;
|
|
331
513
|
interface AuthDefinition<TOptions extends AuthDefinitionInput = AuthDefinitionInput> {
|
|
@@ -336,66 +518,41 @@ interface DiscoveredAuthDefinition {
|
|
|
336
518
|
name: "default";
|
|
337
519
|
source: "server-auth" | "server-auth-suffix";
|
|
338
520
|
}
|
|
339
|
-
type ResolvedAuthDatabaseConfiguration = {
|
|
340
|
-
mode: "default";
|
|
341
|
-
} | {
|
|
342
|
-
dedicated: boolean;
|
|
343
|
-
mode: "named";
|
|
344
|
-
name: string;
|
|
345
|
-
};
|
|
346
|
-
type ResolvedAuthSecondaryStorageConfiguration = {
|
|
347
|
-
mode: "default";
|
|
348
|
-
} | {
|
|
349
|
-
mode: "named";
|
|
350
|
-
store: string;
|
|
351
|
-
};
|
|
352
521
|
interface ResolvedAuthAccessRoute {
|
|
353
522
|
authorize?: true;
|
|
354
523
|
method?: string;
|
|
355
524
|
route: string;
|
|
356
525
|
}
|
|
357
526
|
interface ResolvedAuthViteConfig {
|
|
527
|
+
/** The absolute path of `shared/abilities.ts`, when the app has rules. */
|
|
528
|
+
abilities?: string;
|
|
358
529
|
access: {
|
|
359
530
|
routes: ResolvedAuthAccessRoute[];
|
|
531
|
+
/** Paths that the access middleware leaves to the handler. Set only when the Definition lists some. */
|
|
532
|
+
public?: string[];
|
|
360
533
|
};
|
|
361
534
|
basePath: string;
|
|
362
|
-
|
|
535
|
+
/**
|
|
536
|
+
* The app Database that `authDatabase()` names, which gets the Better Auth tables, and the plugins and additional fields
|
|
537
|
+
* of the Definition that add tables and columns. `false` without the call.
|
|
538
|
+
*/
|
|
539
|
+
tables: false | {
|
|
540
|
+
database: string;
|
|
541
|
+
schema?: AuthSchemaOptions;
|
|
542
|
+
};
|
|
543
|
+
/** `true` when the static Definition sets no `database` or `preset`, so only a development server can run it. */
|
|
544
|
+
implicitMemory?: true;
|
|
363
545
|
definition: DiscoveredAuthDefinition;
|
|
364
546
|
rootDir: string;
|
|
365
547
|
route: false | string;
|
|
366
|
-
secondaryStorage: false | ResolvedAuthSecondaryStorageConfiguration;
|
|
367
548
|
}
|
|
368
|
-
type AuthBetterAuthRuntimeOptions<TOptions extends AuthDefinitionInput = AuthDefinitionInput> = (TOptions extends AuthDefinitionResolver<infer TResolved> ? Omit<TResolved, AuthRuntimeOption | "events" | "console" | "access" | "database" | "preset" | "route" | "runtime" | "secondaryStorage"> : Omit<TOptions, AuthRuntimeOption | "events" | "console" | "access" | "database" | "preset" | "route" | "runtime" | "secondaryStorage">) & AuthRuntimeOptions & BetterAuthOptions;
|
|
549
|
+
type AuthBetterAuthRuntimeOptions<TOptions extends AuthDefinitionInput = AuthDefinitionInput> = (TOptions extends AuthDefinitionResolver<infer TResolved> ? Omit<TResolved, AuthRuntimeOption | "events" | "console" | "access" | "adminClaim" | "database" | "preset" | "route" | "runtime" | "secondaryStorage"> : Omit<TOptions, AuthRuntimeOption | "events" | "console" | "access" | "adminClaim" | "database" | "preset" | "route" | "runtime" | "secondaryStorage">) & AuthRuntimeOptions & BetterAuthOptions;
|
|
369
550
|
type AuthRequest = Pick<Request, "body" | "headers" | "method" | "signal" | "url">;
|
|
370
|
-
/**
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
};
|
|
376
|
-
headers: Record<string, string | string[] | undefined>;
|
|
377
|
-
method?: string;
|
|
378
|
-
originalUrl?: string;
|
|
379
|
-
rawBody?: unknown;
|
|
380
|
-
socket?: {
|
|
381
|
-
encrypted?: boolean;
|
|
382
|
-
};
|
|
383
|
-
url?: string;
|
|
384
|
-
[key: symbol]: unknown;
|
|
385
|
-
}
|
|
386
|
-
/** An H3 1 event. ViteHub Auth builds a Web Request from `node.req`. */
|
|
387
|
-
interface AuthNodeRequestEvent {
|
|
388
|
-
_requestBody?: unknown;
|
|
389
|
-
node: {
|
|
390
|
-
req: AuthNodeRequest;
|
|
391
|
-
};
|
|
392
|
-
web?: {
|
|
393
|
-
request?: Request;
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
type AuthRequestInput = AuthRequest | {
|
|
397
|
-
req: AuthRequest;
|
|
398
|
-
} | AuthNodeRequestEvent;
|
|
551
|
+
/**
|
|
552
|
+
* A Web Request, or a request event with Standard Context properties, such as an H3 2 event in a ViteHub app.
|
|
553
|
+
* Auth reads the request and the Cloudflare bindings of an event from `event["~standard"]`.
|
|
554
|
+
*/
|
|
555
|
+
type AuthRequestInput = AuthRequest | ViteHubContext$1;
|
|
399
556
|
type ViteHubAuth<Options extends BetterAuthOptions = BetterAuthOptions> = Auth<Options>;
|
|
400
557
|
/** The Better Auth instance of an Auth Definition, with the endpoints and fields of its plugins. */
|
|
401
558
|
type AuthFor<TDefinition extends AuthDefinition> = ViteHubAuth<Extract<Omit<TDefinition["options"] extends AuthDefinitionResolver<infer TResolved> ? TResolved : TDefinition["options"], AuthReservedOption>, BetterAuthOptions>>;
|
|
@@ -403,84 +560,10 @@ type AuthFor<TDefinition extends AuthDefinition> = ViteHubAuth<Extract<Omit<TDef
|
|
|
403
560
|
type RegisteredAuth<TRegistry = ViteHub.AuthRegistry> = TRegistry extends {
|
|
404
561
|
definition: infer TDefinition extends AuthDefinition;
|
|
405
562
|
} ? AuthFor<TDefinition> : ViteHubAuth;
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
declare const authEventTypes: readonly ["user.signed_up", "user.signed_in", "user.signed_out", "sign_in.failed", "session.revoked", "user.banned", "user.unbanned", "user.role_changed", "user.updated", "user.removed", "impersonation.started", "impersonation.stopped", "oauth.consent_granted", "oauth.consent_revoked", "organization.member_added", "organization.member_removed", "organization.member_role_changed"];
|
|
410
|
-
type AuthEventType = typeof authEventTypes[number];
|
|
411
|
-
type AuthEventActor = "system" | `user:${string}`;
|
|
412
|
-
type AuthDevice = "desktop" | "mobile" | "tablet" | "bot" | "unknown";
|
|
413
|
-
/** Only these fields cross the persistence boundary. No request bodies or headers are stored. */
|
|
414
|
-
interface AuthEventMetadata {
|
|
415
|
-
method?: string;
|
|
416
|
-
device?: AuthDevice;
|
|
417
|
-
sessionId?: string;
|
|
418
|
-
fields?: string[];
|
|
419
|
-
role?: string;
|
|
420
|
-
clientId?: string;
|
|
421
|
-
organizationId?: string;
|
|
422
|
-
memberId?: string;
|
|
423
|
-
}
|
|
424
|
-
interface AuthEvent {
|
|
425
|
-
id: string;
|
|
426
|
-
type: AuthEventType;
|
|
427
|
-
time: string;
|
|
428
|
-
actor: AuthEventActor;
|
|
429
|
-
/** Unknown for failed sign-ins. The log does not look up untrusted email addresses. */
|
|
430
|
-
userId: string | null;
|
|
431
|
-
metadata: AuthEventMetadata;
|
|
432
|
-
}
|
|
433
|
-
interface AuthEventListInput {
|
|
434
|
-
type?: AuthEventType | readonly AuthEventType[];
|
|
435
|
-
userId?: string;
|
|
436
|
-
actor?: AuthEventActor;
|
|
437
|
-
/** Inclusive ISO timestamp. */
|
|
438
|
-
from?: string;
|
|
439
|
-
/** Exclusive ISO timestamp. */
|
|
440
|
-
to?: string;
|
|
441
|
-
cursor?: string;
|
|
442
|
-
limit?: number;
|
|
443
|
-
}
|
|
444
|
-
interface AuthEventPage {
|
|
445
|
-
events: AuthEvent[];
|
|
446
|
-
nextCursor?: string;
|
|
447
|
-
}
|
|
448
|
-
interface AuthEventWindow {
|
|
449
|
-
from: string;
|
|
450
|
-
to: string;
|
|
451
|
-
}
|
|
452
|
-
interface AuthEventCounts {
|
|
453
|
-
signUps: number;
|
|
454
|
-
signIns: number;
|
|
455
|
-
/** Distinct users with a recorded sign-in. Includes the session created at sign-up. */
|
|
456
|
-
activeUsers: number;
|
|
457
|
-
methods: Record<string, number>;
|
|
458
|
-
}
|
|
459
|
-
interface AuthEventAggregates {
|
|
460
|
-
days: Array<AuthEventCounts & {
|
|
461
|
-
day: string;
|
|
462
|
-
}>;
|
|
463
|
-
totals: AuthEventCounts;
|
|
563
|
+
interface AuthObjectOptions {
|
|
564
|
+
/** Where the Nuxt page guard of `definePageMeta({ auth })` sends visitors. Vite apps without Nuxt ignore it. */
|
|
565
|
+
redirects?: AuthRedirects;
|
|
464
566
|
}
|
|
465
|
-
|
|
466
|
-
maxAgeMs?: number;
|
|
467
|
-
maxRecords?: number;
|
|
468
|
-
}
|
|
469
|
-
interface AuthEventStore {
|
|
470
|
-
append: (event: AuthEvent) => Promise<void>;
|
|
471
|
-
list: (input?: AuthEventListInput) => Promise<AuthEventPage>;
|
|
472
|
-
aggregate: (window: AuthEventWindow) => Promise<AuthEventAggregates>;
|
|
473
|
-
}
|
|
474
|
-
interface AuthEventsConfiguration {
|
|
475
|
-
store: AuthEventStore;
|
|
476
|
-
/** Enable the CLI read endpoint. A session and an explicit true result are required. A Response is sent as the rejection. */
|
|
477
|
-
authorize?: AuthAccessAuthorize;
|
|
478
|
-
}
|
|
479
|
-
declare const defaultAuthEventRetention: Required<AuthEventRetention>;
|
|
480
|
-
/** One SQLite store contract for Node SQLite, libSQL, and Cloudflare D1 Drizzle databases. */
|
|
481
|
-
declare function createDatabaseAuthEventStore(options: {
|
|
482
|
-
db: EnvDatabase;
|
|
483
|
-
retention?: AuthEventRetention | false;
|
|
484
|
-
}): AuthEventStore;
|
|
567
|
+
type AuthOptions = false | AuthObjectOptions;
|
|
485
568
|
//#endregion
|
|
486
|
-
export {
|
|
569
|
+
export { AuthConsoleField as $, AuthRuntimeOption as A, AuthEventCounts as At, ResolvedAuthAccessRoute as B, defaultAuthEventRetention as Bt, AuthRequest as C, AuthPageMeta as Ct, AuthRuntimeContext as D, AuthEvent as Dt, AuthResolvedDefinitionOptions as E, AuthDevice as Et, AuthSessionRefreshFields as F, AuthEventStore as Ft, AuthConsoleActivityQuery as G, ViteHubAuth as H, AuthSignInConfiguration as I, AuthEventType as It, AuthConsoleColumn as J, AuthConsoleAgent as K, AuthViteHubOptions as L, AuthEventWindow as Lt, AuthSessionOptions as M, AuthEventMetadata as Mt, AuthSessionRefresh as N, AuthEventPage as Nt, AuthRuntimeEnv as O, AuthEventActor as Ot, AuthSessionRefreshContext as P, AuthEventRetention as Pt, AuthConsoleEventUser as Q, DiscoveredAuthDefinition as R, AuthEventsConfiguration as Rt, AuthOptions as S, authConsoleEventGroups as St, AuthReservedOption as T, AuthRedirects as Tt, AuthConsoleAction as U, ResolvedAuthViteConfig as V, AuthConsoleActivity as W, AuthConsoleEvent as X, AuthConsoleDescription as Y, AuthConsoleEventGroup as Z, AuthDefinitionInput as _, AuthConsoleSessionUser as _t, AuthAccessPolicy as a, AuthConsoleImpersonation as at, AuthFor as b, AuthConsoleValue as bt, AuthAccessRouteConfiguration as c, AuthConsoleOptions as ct, AuthAnonymousGuardedHandler as d, AuthConsoleOverview as dt, AuthConsoleFieldPolicy as et, AuthAppDatabase as f, AuthConsolePage as ft, AuthDefinition as g, AuthConsoleSession as gt, AuthBetterAuthRuntimeOptions as h, AuthConsoleRoles as ht, AuthAccessConfiguration as i, AuthConsoleHostUserInput as it, AuthRuntimeOptions as j, AuthEventListInput as jt, AuthRuntimeOnlyOptions as k, AuthEventAggregates as kt, AuthAnonymousAuthorization as l, AuthConsoleOrganization as lt, AuthBetterAuthOptions as m, AuthConsoleQuery as mt, AuthAccessAuthorize as n, AuthConsoleHostOptions as nt, AuthAccessPolicyContext as o, AuthConsoleList as ot, AuthAuthorization as p, AuthConsolePolicy as pt, AuthConsoleCapability as q, AuthAccessAuthorizeResult as r, AuthConsoleHostSession as rt, AuthAccessRoute as s, AuthConsoleMutation as st, AuthAccessAuthorizationContext as t, AuthConsoleFieldType as tt, AuthAnonymousAuthorize as u, AuthConsoleOrganizationDetail as ut, AuthDefinitionOptions as v, AuthConsoleUser as vt, AuthRequestInput as w, AuthPageMode as wt, AuthGuardedHandler as x, authConsoleActionNames as xt, AuthDefinitionResolver as y, AuthConsoleUserDetail as yt, RegisteredAuth as z, createDatabaseAuthEventStore as zt };
|