@vite-hub/auth 0.0.4 → 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 +443 -32
- 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 +23 -12
- package/dist/agent.js +30 -8
- 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 +7 -0
- package/dist/cli.js +108 -0
- 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 -0
- package/dist/console-runtime.js +2 -0
- package/dist/console-types-CmmnKGMx.js +38 -0
- package/dist/console.d.ts +219 -0
- package/dist/console.js +15 -0
- 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-ByzenEVj.js +314 -0
- package/dist/forward.d.ts +50 -0
- package/dist/forward.js +120 -0
- package/dist/host-declarations.d.ts +6 -1
- package/dist/index.d.ts +26 -5
- package/dist/index.js +3 -95
- 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 +36 -7
- package/dist/nuxt.js +116 -7
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/page-tools-shared-l4eyj53D.js +19 -0
- package/dist/presets-BGZi6Dfu.d.ts +25 -0
- package/dist/presets.d.ts +2 -0
- package/dist/presets.js +32 -0
- package/dist/request-z6DHHmrb.js +47 -0
- package/dist/runtime/console.d.ts +3 -0
- package/dist/runtime/console.js +4 -0
- 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 -2
- package/dist/runtime/nuxt.d.ts +2 -3
- package/dist/runtime/nuxt.js +3 -2
- package/dist/runtime/server.d.ts +2 -0
- package/dist/runtime/server.js +77 -0
- package/dist/runtime/vue-nuxt.d.ts +4 -0
- package/dist/runtime/vue-nuxt.js +160 -0
- 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 -22
- package/dist/server.js +3 -2
- package/dist/session-cookies-BbH3UR2m.js +227 -0
- package/dist/set-cookie-C8NOhdRE.js +90 -0
- package/dist/shared-BwcdRGxD.js +12 -0
- 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/types-CNaeH2Fd.d.ts +569 -0
- package/dist/vite-CV400XXY.js +1556 -0
- package/dist/vite.d.ts +145 -18
- package/dist/vite.js +2 -2
- package/dist/vue.d.ts +343 -17
- package/dist/vue.js +640 -15
- package/package.json +156 -27
- package/dist/server-BZn8iQrB.js +0 -370
- package/dist/shared-QSYBHaMG.js +0 -12
- package/dist/types-jaRlW3D1.d.ts +0 -117
- package/dist/vite-Cmey8ODS.js +0 -1018
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 };
|
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
import { n as AuthPreset } from "./presets-BGZi6Dfu.js";
|
|
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";
|
|
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
|
|
110
|
+
//#region src/console-types.d.ts
|
|
111
|
+
type AuthConsoleValue = string | number | boolean | null | string[] | number[];
|
|
112
|
+
type AuthConsoleFieldType = "string" | "number" | "boolean" | "date" | "string[]" | "number[]" | "json";
|
|
113
|
+
type AuthConsoleAction = "ban" | "unban" | "remove" | "revokeSession" | "revokeSessions" | "setRole" | "editField" | "impersonate" | "revokeConsent";
|
|
114
|
+
/** A reason makes the action read-only. `false` uses the default reason. */
|
|
115
|
+
type AuthConsolePolicy = boolean | {
|
|
116
|
+
editable: false;
|
|
117
|
+
reason: string;
|
|
118
|
+
};
|
|
119
|
+
interface AuthConsoleFieldPolicy {
|
|
120
|
+
label?: string;
|
|
121
|
+
/** Fields are read-only unless the app opts in. */
|
|
122
|
+
editable?: boolean;
|
|
123
|
+
reason?: string;
|
|
124
|
+
}
|
|
125
|
+
type ColumnValues<T> = Readonly<Record<string, T | null>>;
|
|
126
|
+
type ColumnReader<T> = (users: readonly User[]) => Promise<ColumnValues<T>> | ColumnValues<T>;
|
|
127
|
+
/** One server call per page. Return computed values keyed by user id. */
|
|
128
|
+
type AuthConsoleColumn = {
|
|
129
|
+
label: string;
|
|
130
|
+
} & ({
|
|
131
|
+
type: "string" | "date";
|
|
132
|
+
read: ColumnReader<string>;
|
|
133
|
+
} | {
|
|
134
|
+
type: "number";
|
|
135
|
+
read: ColumnReader<number>;
|
|
136
|
+
} | {
|
|
137
|
+
type: "boolean";
|
|
138
|
+
read: ColumnReader<boolean>;
|
|
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
|
+
}
|
|
149
|
+
/** Host-independent display and edit policy. It does not grant Better Auth permissions. */
|
|
150
|
+
interface AuthConsoleOptions {
|
|
151
|
+
access?: readonly string[];
|
|
152
|
+
actions?: Partial<Record<AuthConsoleAction, AuthConsolePolicy>>;
|
|
153
|
+
columns?: Readonly<Record<string, AuthConsoleColumn>>;
|
|
154
|
+
fields?: Readonly<Record<string, AuthConsoleFieldPolicy | undefined>>;
|
|
155
|
+
roles?: AuthConsolePolicy | AuthConsoleRoles;
|
|
156
|
+
}
|
|
157
|
+
interface AuthConsoleCapability {
|
|
158
|
+
enabled: boolean;
|
|
159
|
+
reason?: string;
|
|
160
|
+
}
|
|
161
|
+
interface AuthConsoleField {
|
|
162
|
+
key: string;
|
|
163
|
+
label: string;
|
|
164
|
+
type: AuthConsoleFieldType;
|
|
165
|
+
values?: string[];
|
|
166
|
+
required: boolean;
|
|
167
|
+
computed: boolean;
|
|
168
|
+
edit: AuthConsoleCapability;
|
|
169
|
+
}
|
|
170
|
+
type AuthConsolePage = "overview" | "activity" | "users" | "sessions" | "organizations" | "agents";
|
|
171
|
+
interface AuthConsoleDescription {
|
|
172
|
+
access: string[];
|
|
173
|
+
actions: Record<AuthConsoleAction, AuthConsoleCapability>;
|
|
174
|
+
fields: AuthConsoleField[];
|
|
175
|
+
pages: AuthConsolePage[];
|
|
176
|
+
storage: AuthConsoleCapability;
|
|
177
|
+
events: AuthConsoleCapability;
|
|
178
|
+
/** Present only when the host enables impersonation. */
|
|
179
|
+
impersonation?: AuthConsoleImpersonation;
|
|
180
|
+
}
|
|
181
|
+
/** What the host allows. A host that renders the Console passes it with the Definition's own policy. */
|
|
182
|
+
interface AuthConsoleHostOptions {
|
|
183
|
+
/** Let the Console start and stop Better Auth admin impersonation. Off by default. */
|
|
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;
|
|
215
|
+
}
|
|
216
|
+
interface AuthConsoleImpersonation {
|
|
217
|
+
/** Seconds until an impersonation session ends. Better Auth's `admin({ impersonationSessionDuration })` sets it. */
|
|
218
|
+
duration: number;
|
|
219
|
+
/** The user that the app session of this request impersonates, or `null`. */
|
|
220
|
+
active: {
|
|
221
|
+
user: Pick<AuthConsoleUser, "id" | "name" | "email" | "image">;
|
|
222
|
+
expiresAt: string;
|
|
223
|
+
} | null;
|
|
224
|
+
}
|
|
225
|
+
type AuthConsoleEventGroup = "sign-in" | "admin" | "agents" | "organizations";
|
|
226
|
+
declare const authConsoleEventGroups: Readonly<Record<AuthConsoleEventGroup, readonly AuthEventType[]>>;
|
|
227
|
+
interface AuthConsoleActivityQuery {
|
|
228
|
+
group?: keyof typeof authConsoleEventGroups;
|
|
229
|
+
/** The subject user, as in AuthEventListInput. */
|
|
230
|
+
userId?: string;
|
|
231
|
+
cursor?: string;
|
|
232
|
+
limit?: number;
|
|
233
|
+
}
|
|
234
|
+
interface AuthConsoleEventUser {
|
|
235
|
+
id: string;
|
|
236
|
+
name: string;
|
|
237
|
+
available: boolean;
|
|
238
|
+
}
|
|
239
|
+
/** Explicit display projection. Event metadata and provider records stay on the server. */
|
|
240
|
+
interface AuthConsoleEvent {
|
|
241
|
+
id: string;
|
|
242
|
+
type: AuthEventType;
|
|
243
|
+
time: string;
|
|
244
|
+
actor: AuthConsoleEventUser | null;
|
|
245
|
+
subject: AuthConsoleEventUser | null;
|
|
246
|
+
}
|
|
247
|
+
interface AuthConsoleActivity {
|
|
248
|
+
enabled: boolean;
|
|
249
|
+
events: AuthConsoleEvent[];
|
|
250
|
+
nextCursor?: string;
|
|
251
|
+
}
|
|
252
|
+
interface AuthConsoleOverview {
|
|
253
|
+
users: number | null;
|
|
254
|
+
newUsers: number | null;
|
|
255
|
+
activeSessions: number | null;
|
|
256
|
+
/** Consent grants, one per user and client. Omitted without the OAuth provider plugin. */
|
|
257
|
+
approvedAgents?: number | null;
|
|
258
|
+
activeUsers: number | null;
|
|
259
|
+
window: AuthEventWindow;
|
|
260
|
+
analytics: AuthEventAggregates | null;
|
|
261
|
+
recent: AuthConsoleActivity;
|
|
262
|
+
}
|
|
263
|
+
interface AuthConsoleUser {
|
|
264
|
+
id: string;
|
|
265
|
+
name: string;
|
|
266
|
+
email: string;
|
|
267
|
+
image: string | null;
|
|
268
|
+
role: string;
|
|
269
|
+
banned: boolean;
|
|
270
|
+
banReason: string | null;
|
|
271
|
+
banExpires: string | null;
|
|
272
|
+
createdAt: string;
|
|
273
|
+
lastActive: string | null;
|
|
274
|
+
providers: string[];
|
|
275
|
+
fields: Record<string, AuthConsoleValue>;
|
|
276
|
+
}
|
|
277
|
+
interface AuthConsoleSession {
|
|
278
|
+
id: string;
|
|
279
|
+
user: Pick<AuthConsoleUser, "id" | "name" | "email" | "image">;
|
|
280
|
+
device: string;
|
|
281
|
+
createdAt: string;
|
|
282
|
+
expiresAt: string;
|
|
283
|
+
updatedAt: string;
|
|
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
|
+
}
|
|
303
|
+
interface AuthConsoleAgent {
|
|
304
|
+
id: string;
|
|
305
|
+
clientId: string;
|
|
306
|
+
name: string;
|
|
307
|
+
user: Pick<AuthConsoleUser, "id" | "name" | "email" | "image">;
|
|
308
|
+
scopes: string[];
|
|
309
|
+
createdAt: string;
|
|
310
|
+
lastUsed: string | null;
|
|
311
|
+
}
|
|
312
|
+
interface AuthConsoleOrganization {
|
|
313
|
+
id: string;
|
|
314
|
+
name: string;
|
|
315
|
+
slug: string;
|
|
316
|
+
createdAt: string;
|
|
317
|
+
}
|
|
318
|
+
interface AuthConsoleOrganizationDetail extends AuthConsoleOrganization {
|
|
319
|
+
members: Array<{
|
|
320
|
+
id: string;
|
|
321
|
+
role: string;
|
|
322
|
+
user: Pick<AuthConsoleUser, "id" | "name" | "email" | "image">;
|
|
323
|
+
}>;
|
|
324
|
+
invitations: Array<{
|
|
325
|
+
id: string;
|
|
326
|
+
email: string;
|
|
327
|
+
role: string;
|
|
328
|
+
expiresAt: string;
|
|
329
|
+
}>;
|
|
330
|
+
membersTotal: number;
|
|
331
|
+
invitationsTotal: number;
|
|
332
|
+
}
|
|
333
|
+
interface AuthConsoleUserDetail {
|
|
334
|
+
user: AuthConsoleUser;
|
|
335
|
+
sessions: AuthConsoleList<AuthConsoleSession>;
|
|
336
|
+
accounts: Array<{
|
|
337
|
+
id: string;
|
|
338
|
+
provider: string;
|
|
339
|
+
accountId: string;
|
|
340
|
+
createdAt: string;
|
|
341
|
+
}>;
|
|
342
|
+
agents: AuthConsoleList<AuthConsoleAgent>;
|
|
343
|
+
organizations: Array<AuthConsoleOrganization & {
|
|
344
|
+
role: string;
|
|
345
|
+
}>;
|
|
346
|
+
accountsTotal: number;
|
|
347
|
+
organizationsTotal: number;
|
|
348
|
+
/** Whether Better Auth accepts this user as an impersonation target. Present only when the host enables impersonation. */
|
|
349
|
+
impersonation?: AuthConsoleCapability;
|
|
350
|
+
}
|
|
351
|
+
interface AuthConsoleList<T> {
|
|
352
|
+
items: T[];
|
|
353
|
+
total: number;
|
|
354
|
+
offset: number;
|
|
355
|
+
limit: number;
|
|
356
|
+
}
|
|
357
|
+
interface AuthConsoleQuery {
|
|
358
|
+
search?: string;
|
|
359
|
+
filter?: "all" | "admins" | "banned" | "agents";
|
|
360
|
+
offset?: number;
|
|
361
|
+
limit?: number;
|
|
362
|
+
userId?: string;
|
|
363
|
+
}
|
|
364
|
+
type AuthConsoleMutation = {
|
|
365
|
+
action: "ban";
|
|
366
|
+
userId: string;
|
|
367
|
+
reason?: string;
|
|
368
|
+
expiresIn?: number;
|
|
369
|
+
} | {
|
|
370
|
+
action: "unban" | "remove" | "revokeSessions" | "impersonate";
|
|
371
|
+
userId: string;
|
|
372
|
+
} | {
|
|
373
|
+
action: "setRole";
|
|
374
|
+
userId: string;
|
|
375
|
+
role: string;
|
|
376
|
+
} | {
|
|
377
|
+
action: "editField";
|
|
378
|
+
userId: string;
|
|
379
|
+
field: string;
|
|
380
|
+
value: AuthConsoleValue;
|
|
381
|
+
} | {
|
|
382
|
+
action: "revokeSession" | "revokeConsent";
|
|
383
|
+
id: string;
|
|
384
|
+
};
|
|
385
|
+
declare const authConsoleActionNames: readonly AuthConsoleAction[];
|
|
386
|
+
//#endregion
|
|
387
|
+
//#region src/types.d.ts
|
|
388
|
+
declare global {
|
|
389
|
+
namespace ViteHub {
|
|
390
|
+
interface AuthRuntimeEnv extends Record<string, unknown> {}
|
|
391
|
+
/** Generated declarations set `definition` to the type of the app's Auth Definition. */
|
|
392
|
+
interface AuthRegistry {}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
type AuthRuntimeOption = "baseURL" | "secret" | "secrets";
|
|
396
|
+
type AuthReservedOption = AuthRuntimeOption | "events" | "console" | "access" | "adminClaim" | "basePath" | "database" | "preset" | "route" | "runtime" | "secondaryStorage";
|
|
397
|
+
type AuthBetterAuthOptions = Omit<BetterAuthOptions, AuthReservedOption | "session"> & {
|
|
398
|
+
session?: AuthSessionOptions;
|
|
399
|
+
};
|
|
400
|
+
/** Session fields to write when a refresh extends the session. */
|
|
401
|
+
type AuthSessionRefreshFields = Partial<Session> & Record<string, unknown>;
|
|
402
|
+
interface AuthSessionRefreshContext {
|
|
403
|
+
/** The stored session before the refresh. */
|
|
404
|
+
session: Session & Record<string, unknown>;
|
|
405
|
+
/** The user of the session, as stored before the refresh. */
|
|
406
|
+
user: User & Record<string, unknown>;
|
|
407
|
+
/** Extend the session. Pass fields to also write them to the session. */
|
|
408
|
+
refresh: (fields?: AuthSessionRefreshFields) => void;
|
|
409
|
+
/** End the session. It wins over `refresh()`. */
|
|
410
|
+
clear: () => void;
|
|
411
|
+
}
|
|
412
|
+
/** Runs when Better Auth refreshes a stored session. Call neither `refresh()` nor `clear()` to keep the current expiry. */
|
|
413
|
+
type AuthSessionRefresh = (context: AuthSessionRefreshContext) => void | Promise<void>;
|
|
414
|
+
type AuthSessionOptions = NonNullable<BetterAuthOptions["session"]> & {
|
|
415
|
+
/** Runs when a stored session passes `updateAge`. Needs a Better Auth `database` or `secondaryStorage` adapter. */
|
|
416
|
+
onRefresh?: AuthSessionRefresh;
|
|
417
|
+
};
|
|
418
|
+
interface AuthRuntimeEnv extends ViteHub.AuthRuntimeEnv {}
|
|
419
|
+
interface AuthRuntimeContext<TEnv extends Record<string, unknown> = AuthRuntimeEnv> {
|
|
420
|
+
env: TEnv;
|
|
421
|
+
request?: Pick<Request, "headers" | "url">;
|
|
422
|
+
requestOrigin: string;
|
|
423
|
+
}
|
|
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";
|
|
427
|
+
events?: AuthEventsConfiguration | false;
|
|
428
|
+
};
|
|
429
|
+
interface AuthSignInConfiguration {
|
|
430
|
+
callbackURL?: string;
|
|
431
|
+
errorCallbackURL?: string;
|
|
432
|
+
provider: string;
|
|
433
|
+
requestSignUp?: boolean;
|
|
434
|
+
scopes?: string[];
|
|
435
|
+
}
|
|
436
|
+
interface AuthAccessRouteConfiguration {
|
|
437
|
+
authorize?: AuthAccessAuthorize;
|
|
438
|
+
method?: string;
|
|
439
|
+
route: string;
|
|
440
|
+
}
|
|
441
|
+
type AuthAccessRoute = string | AuthAccessRouteConfiguration;
|
|
442
|
+
type AuthAccessAuthorizationContext<TEvent = ViteHubContext$1> = AccessAuthorizationContext<TEvent>;
|
|
443
|
+
type AuthAccessAuthorizeResult = AccessAuthorizeResult;
|
|
444
|
+
type AuthAccessAuthorize<TEvent = ViteHubContext$1> = AccessAuthorize<TEvent>;
|
|
445
|
+
/** The checked request, Session, and user that a guarded handler receives. Only Auth guards create it. */
|
|
446
|
+
type AuthAuthorization = Readonly<Omit<AuthAccessAuthorizationContext, "event"> & {
|
|
447
|
+
/** `impersonatedBy` is the id of the administrator who opened this session as `user`. Better Auth's admin plugin sets it. */
|
|
448
|
+
session: AuthAccessAuthorizationContext["session"] & {
|
|
449
|
+
impersonatedBy?: string | null;
|
|
450
|
+
};
|
|
451
|
+
}>;
|
|
452
|
+
/** A server handler that runs only after an Auth guard accepts the request. */
|
|
453
|
+
type AuthGuardedHandler<TInput, TResult> = (input: TInput, authorization: AuthAuthorization) => TResult | Promise<TResult>;
|
|
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
|
+
}
|
|
475
|
+
interface AuthAccessConfiguration {
|
|
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;
|
|
480
|
+
signIn?: AuthSignInConfiguration;
|
|
481
|
+
}
|
|
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
|
+
};
|
|
486
|
+
interface AuthViteHubOptions {
|
|
487
|
+
/** Ignore `VITEHUB_ADMIN_CLAIM` for this Auth Definition. Independent Console Auth sets this to `false`. */
|
|
488
|
+
adminClaim?: false;
|
|
489
|
+
/** Opt in to durable auth events with an explicit store. */
|
|
490
|
+
events?: AuthEventsConfiguration | false;
|
|
491
|
+
console?: AuthConsoleOptions;
|
|
492
|
+
access?: AuthAccessConfiguration;
|
|
493
|
+
basePath?: string;
|
|
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. */
|
|
501
|
+
preset?: AuthPreset;
|
|
502
|
+
route?: false;
|
|
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;
|
|
507
|
+
}
|
|
508
|
+
type AuthRuntimeOnlyOptions = { [Key in AuthRuntimeOption]?: never; };
|
|
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;
|
|
511
|
+
type AuthDefinitionResolver<TOptions extends AuthResolvedDefinitionOptions = AuthResolvedDefinitionOptions> = (context: AuthRuntimeContext) => TOptions;
|
|
512
|
+
type AuthDefinitionInput = AuthDefinitionOptions | AuthDefinitionResolver;
|
|
513
|
+
interface AuthDefinition<TOptions extends AuthDefinitionInput = AuthDefinitionInput> {
|
|
514
|
+
options: TOptions;
|
|
515
|
+
}
|
|
516
|
+
interface DiscoveredAuthDefinition {
|
|
517
|
+
handler: string;
|
|
518
|
+
name: "default";
|
|
519
|
+
source: "server-auth" | "server-auth-suffix";
|
|
520
|
+
}
|
|
521
|
+
interface ResolvedAuthAccessRoute {
|
|
522
|
+
authorize?: true;
|
|
523
|
+
method?: string;
|
|
524
|
+
route: string;
|
|
525
|
+
}
|
|
526
|
+
interface ResolvedAuthViteConfig {
|
|
527
|
+
/** The absolute path of `shared/abilities.ts`, when the app has rules. */
|
|
528
|
+
abilities?: string;
|
|
529
|
+
access: {
|
|
530
|
+
routes: ResolvedAuthAccessRoute[];
|
|
531
|
+
/** Paths that the access middleware leaves to the handler. Set only when the Definition lists some. */
|
|
532
|
+
public?: string[];
|
|
533
|
+
};
|
|
534
|
+
basePath: string;
|
|
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;
|
|
545
|
+
definition: DiscoveredAuthDefinition;
|
|
546
|
+
rootDir: string;
|
|
547
|
+
route: false | string;
|
|
548
|
+
}
|
|
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;
|
|
550
|
+
type AuthRequest = Pick<Request, "body" | "headers" | "method" | "signal" | "url">;
|
|
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;
|
|
556
|
+
type ViteHubAuth<Options extends BetterAuthOptions = BetterAuthOptions> = Auth<Options>;
|
|
557
|
+
/** The Better Auth instance of an Auth Definition, with the endpoints and fields of its plugins. */
|
|
558
|
+
type AuthFor<TDefinition extends AuthDefinition> = ViteHubAuth<Extract<Omit<TDefinition["options"] extends AuthDefinitionResolver<infer TResolved> ? TResolved : TDefinition["options"], AuthReservedOption>, BetterAuthOptions>>;
|
|
559
|
+
/** The Better Auth instance of the app's discovered Auth Definition. Without generated types, the plain instance. */
|
|
560
|
+
type RegisteredAuth<TRegistry = ViteHub.AuthRegistry> = TRegistry extends {
|
|
561
|
+
definition: infer TDefinition extends AuthDefinition;
|
|
562
|
+
} ? AuthFor<TDefinition> : ViteHubAuth;
|
|
563
|
+
interface AuthObjectOptions {
|
|
564
|
+
/** Where the Nuxt page guard of `definePageMeta({ auth })` sends visitors. Vite apps without Nuxt ignore it. */
|
|
565
|
+
redirects?: AuthRedirects;
|
|
566
|
+
}
|
|
567
|
+
type AuthOptions = false | AuthObjectOptions;
|
|
568
|
+
//#endregion
|
|
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 };
|