@vite-hub/auth 0.0.4 → 0.1.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 +140 -13
- package/dist/agent.d.ts +24 -13
- package/dist/agent.js +19 -5
- package/dist/application-path-C290OAIs.js +18 -0
- package/dist/cli-mgXvsBtA.d.ts +85 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +68 -0
- package/dist/console-B7eERmGv.d.ts +180 -0
- package/dist/console-runtime-bZQtnX2Y.d.ts +39 -0
- package/dist/console-runtime.d.ts +3 -0
- package/dist/console-runtime.js +819 -0
- package/dist/console-types-CmmnKGMx.js +38 -0
- package/dist/console.d.ts +7 -0
- package/dist/console.js +15 -0
- package/dist/error-diagnostics-CL0yjHiM.js +79 -0
- package/dist/events-BkmK2dFY.d.ts +486 -0
- package/dist/events-P7mI4IQb.js +196 -0
- package/dist/events-config-CjcFOhTE.js +177 -0
- package/dist/host-declarations.d.ts +4 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +36 -29
- package/dist/inspect-DPtsW8dB.d.ts +36 -0
- package/dist/nuxt.d.ts +27 -6
- package/dist/nuxt.js +35 -3
- package/dist/presets-BGZi6Dfu.d.ts +25 -0
- package/dist/presets.d.ts +2 -0
- package/dist/presets.js +32 -0
- package/dist/runtime/console.d.ts +7 -0
- package/dist/runtime/console.js +42 -0
- package/dist/runtime/empty-definition.d.ts +1 -2
- package/dist/runtime/nuxt.d.ts +2 -3
- package/dist/runtime/nuxt.js +2 -1
- package/dist/runtime/vue-nuxt.d.ts +3 -0
- package/dist/runtime/vue-nuxt.js +8 -0
- package/dist/server-B7LU19dS.js +1730 -0
- package/dist/server-CTD_JAww.d.ts +77 -0
- package/dist/server.d.ts +2 -22
- package/dist/server.js +3 -2
- package/dist/set-cookie-2as_DbHe.js +75 -0
- package/dist/shared-DnpgYiLF.js +15 -0
- package/dist/vite-COWkwxsj.js +990 -0
- package/dist/vite.d.ts +21 -12
- package/dist/vite.js +2 -2
- package/dist/vue.d.ts +28 -11
- package/dist/vue.js +82 -4
- package/package.json +84 -24
- 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
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/console-types.ts
|
|
2
|
+
const authConsoleEventGroups = {
|
|
3
|
+
"sign-in": [
|
|
4
|
+
"user.signed_up",
|
|
5
|
+
"user.signed_in",
|
|
6
|
+
"user.signed_out",
|
|
7
|
+
"sign_in.failed"
|
|
8
|
+
],
|
|
9
|
+
admin: [
|
|
10
|
+
"session.revoked",
|
|
11
|
+
"user.banned",
|
|
12
|
+
"user.unbanned",
|
|
13
|
+
"user.role_changed",
|
|
14
|
+
"user.updated",
|
|
15
|
+
"user.removed",
|
|
16
|
+
"impersonation.started",
|
|
17
|
+
"impersonation.stopped"
|
|
18
|
+
],
|
|
19
|
+
agents: ["oauth.consent_granted", "oauth.consent_revoked"],
|
|
20
|
+
organizations: [
|
|
21
|
+
"organization.member_added",
|
|
22
|
+
"organization.member_removed",
|
|
23
|
+
"organization.member_role_changed"
|
|
24
|
+
]
|
|
25
|
+
};
|
|
26
|
+
const authConsoleActionNames = [
|
|
27
|
+
"ban",
|
|
28
|
+
"unban",
|
|
29
|
+
"remove",
|
|
30
|
+
"revokeSession",
|
|
31
|
+
"revokeSessions",
|
|
32
|
+
"setRole",
|
|
33
|
+
"editField",
|
|
34
|
+
"impersonate",
|
|
35
|
+
"revokeConsent"
|
|
36
|
+
];
|
|
37
|
+
//#endregion
|
|
38
|
+
export { authConsoleEventGroups as n, authConsoleActionNames as t };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { At as AuthConsoleOverview, Ct as AuthConsoleHostOptions, Dt as AuthConsoleOptions, Et as AuthConsoleMutation, Ft as AuthConsoleUser, It as AuthConsoleUserDetail, Lt as AuthConsoleValue, Mt as AuthConsolePolicy, Nt as AuthConsoleQuery, Ot as AuthConsoleOrganization, Pt as AuthConsoleSession, Rt as authConsoleActionNames, St as AuthConsoleFieldType, Tt as AuthConsoleList, _t as AuthConsoleEvent, bt as AuthConsoleField, dt as AuthConsoleActivity, ft as AuthConsoleActivityQuery, gt as AuthConsoleDescription, ht as AuthConsoleColumn, jt as AuthConsolePage, kt as AuthConsoleOrganizationDetail, mt as AuthConsoleCapability, pt as AuthConsoleAgent, ut as AuthConsoleAction, vt as AuthConsoleEventGroup, wt as AuthConsoleImpersonation, xt as AuthConsoleFieldPolicy, yt as AuthConsoleEventUser, zt as authConsoleEventGroups } from "./events-BkmK2dFY.js";
|
|
2
|
+
import { t as ViteHubConsoleAuthSection } from "./console-B7eERmGv.js";
|
|
3
|
+
//#region src/console.d.ts
|
|
4
|
+
/** The owner descriptor. The host supplies the navigation and renders the Auth views. */
|
|
5
|
+
export declare const authConsoleSection: ViteHubConsoleAuthSection;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type AuthConsoleAction, type AuthConsoleActivity, type AuthConsoleActivityQuery, type AuthConsoleAgent, type AuthConsoleCapability, type AuthConsoleColumn, type AuthConsoleDescription, type AuthConsoleEvent, type AuthConsoleEventGroup, type AuthConsoleEventUser, type AuthConsoleField, type AuthConsoleFieldPolicy, type AuthConsoleFieldType, type AuthConsoleHostOptions, type AuthConsoleImpersonation, type AuthConsoleList, type AuthConsoleMutation, type AuthConsoleOptions, type AuthConsoleOrganization, type AuthConsoleOrganizationDetail, type AuthConsoleOverview, type AuthConsolePage, type AuthConsolePolicy, type AuthConsoleQuery, type AuthConsoleSession, type AuthConsoleUser, type AuthConsoleUserDetail, type AuthConsoleValue, type authConsoleActionNames, authConsoleEventGroups };
|
package/dist/console.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { n as authConsoleEventGroups } from "./console-types-CmmnKGMx.js";
|
|
2
|
+
//#region src/console.ts
|
|
3
|
+
/** The owner descriptor. The host supplies the navigation and renders the Auth views. */
|
|
4
|
+
const authConsoleSection = {
|
|
5
|
+
id: "auth",
|
|
6
|
+
label: "Auth",
|
|
7
|
+
icon: "i-lucide-users-round",
|
|
8
|
+
description: "Manage users, sessions, organizations, and approved OAuth clients.",
|
|
9
|
+
view: {
|
|
10
|
+
kind: "auth-management",
|
|
11
|
+
notice: "Better Auth owns user data and runs each change through its APIs."
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { authConsoleEventGroups, authConsoleSection };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { defineDiagnostics } from "nostics";
|
|
2
|
+
//#region src/error-diagnostics.ts
|
|
3
|
+
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
4
|
+
const authErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
5
|
+
docsBase: () => "https://vitehub.dev/docs/reference/diagnostics",
|
|
6
|
+
codes: {
|
|
7
|
+
AUTH_R0001: dynamicError,
|
|
8
|
+
AUTH_R0002: dynamicError,
|
|
9
|
+
AUTH_C0001: dynamicError,
|
|
10
|
+
AUTH_C0002: dynamicError,
|
|
11
|
+
AUTH_C0003: dynamicError,
|
|
12
|
+
AUTH_C0004: dynamicError,
|
|
13
|
+
AUTH_C0005: dynamicError,
|
|
14
|
+
AUTH_C0006: dynamicError,
|
|
15
|
+
AUTH_C0007: dynamicError,
|
|
16
|
+
AUTH_C0008: dynamicError,
|
|
17
|
+
AUTH_C0009: dynamicError,
|
|
18
|
+
AUTH_C0010: dynamicError,
|
|
19
|
+
AUTH_C0011: dynamicError,
|
|
20
|
+
AUTH_C0012: dynamicError,
|
|
21
|
+
AUTH_C0013: dynamicError,
|
|
22
|
+
AUTH_C0014: dynamicError,
|
|
23
|
+
AUTH_C0015: dynamicError,
|
|
24
|
+
AUTH_C0016: dynamicError,
|
|
25
|
+
AUTH_C0017: dynamicError,
|
|
26
|
+
AUTH_C0018: dynamicError,
|
|
27
|
+
AUTH_C0019: dynamicError,
|
|
28
|
+
AUTH_C0020: dynamicError,
|
|
29
|
+
AUTH_C0021: dynamicError,
|
|
30
|
+
AUTH_C0022: dynamicError,
|
|
31
|
+
AUTH_C0023: dynamicError,
|
|
32
|
+
AUTH_C0024: dynamicError,
|
|
33
|
+
AUTH_C0025: dynamicError,
|
|
34
|
+
AUTH_C0026: dynamicError,
|
|
35
|
+
AUTH_C0027: dynamicError,
|
|
36
|
+
AUTH_C0028: dynamicError,
|
|
37
|
+
AUTH_C0029: dynamicError,
|
|
38
|
+
AUTH_C0030: dynamicError,
|
|
39
|
+
AUTH_C0031: dynamicError,
|
|
40
|
+
AUTH_C0032: dynamicError,
|
|
41
|
+
AUTH_C0033: dynamicError,
|
|
42
|
+
AUTH_C0034: dynamicError,
|
|
43
|
+
AUTH_C0035: dynamicError,
|
|
44
|
+
AUTH_C0036: dynamicError,
|
|
45
|
+
AUTH_C0037: dynamicError,
|
|
46
|
+
AUTH_C0038: dynamicError,
|
|
47
|
+
AUTH_C0039: dynamicError,
|
|
48
|
+
AUTH_C0040: dynamicError,
|
|
49
|
+
AUTH_C0041: dynamicError,
|
|
50
|
+
AUTH_C0042: dynamicError,
|
|
51
|
+
AUTH_C0043: dynamicError,
|
|
52
|
+
AUTH_C0044: dynamicError,
|
|
53
|
+
AUTH_C0045: dynamicError,
|
|
54
|
+
AUTH_C0046: dynamicError,
|
|
55
|
+
AUTH_C0047: dynamicError,
|
|
56
|
+
AUTH_C0048: dynamicError,
|
|
57
|
+
AUTH_C0049: dynamicError,
|
|
58
|
+
AUTH_C0050: dynamicError,
|
|
59
|
+
AUTH_R0018: dynamicError,
|
|
60
|
+
AUTH_R0003: dynamicError,
|
|
61
|
+
AUTH_R0004: dynamicError,
|
|
62
|
+
AUTH_B0001: dynamicError,
|
|
63
|
+
AUTH_R0005: dynamicError,
|
|
64
|
+
AUTH_R0006: dynamicError,
|
|
65
|
+
AUTH_R0007: dynamicError,
|
|
66
|
+
AUTH_R0008: dynamicError,
|
|
67
|
+
AUTH_R0009: dynamicError,
|
|
68
|
+
AUTH_R0010: dynamicError,
|
|
69
|
+
AUTH_R0011: dynamicError,
|
|
70
|
+
AUTH_R0012: dynamicError,
|
|
71
|
+
AUTH_R0013: dynamicError,
|
|
72
|
+
AUTH_R0014: dynamicError,
|
|
73
|
+
AUTH_R0015: dynamicError,
|
|
74
|
+
AUTH_R0016: dynamicError,
|
|
75
|
+
AUTH_R0017: dynamicError
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
//#endregion
|
|
79
|
+
export { authErrorDiagnostics as t };
|
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import { n as AuthPreset } from "./presets-BGZi6Dfu.js";
|
|
2
|
+
import { AccessAuthorizationContext, AccessAuthorize, AccessAuthorizeResult } from "@vite-hub/runtime";
|
|
3
|
+
import { Auth, BetterAuthOptions, Session, User } from "better-auth";
|
|
4
|
+
import { EnvDatabase } from "@vite-hub/env/database";
|
|
5
|
+
//#region src/console-types.d.ts
|
|
6
|
+
type AuthConsoleValue = string | number | boolean | null | string[] | number[];
|
|
7
|
+
type AuthConsoleFieldType = "string" | "number" | "boolean" | "date" | "string[]" | "number[]" | "json";
|
|
8
|
+
type AuthConsoleAction = "ban" | "unban" | "remove" | "revokeSession" | "revokeSessions" | "setRole" | "editField" | "impersonate" | "revokeConsent";
|
|
9
|
+
/** A reason makes the action read-only. `false` uses the default reason. */
|
|
10
|
+
type AuthConsolePolicy = boolean | {
|
|
11
|
+
editable: false;
|
|
12
|
+
reason: string;
|
|
13
|
+
};
|
|
14
|
+
interface AuthConsoleFieldPolicy {
|
|
15
|
+
label?: string;
|
|
16
|
+
/** Fields are read-only unless the app opts in. */
|
|
17
|
+
editable?: boolean;
|
|
18
|
+
reason?: string;
|
|
19
|
+
}
|
|
20
|
+
type ColumnValues<T> = Readonly<Record<string, T | null>>;
|
|
21
|
+
type ColumnReader<T> = (users: readonly User[]) => Promise<ColumnValues<T>> | ColumnValues<T>;
|
|
22
|
+
/** One server call per page. Return computed values keyed by user id. */
|
|
23
|
+
type AuthConsoleColumn = {
|
|
24
|
+
label: string;
|
|
25
|
+
} & ({
|
|
26
|
+
type: "string" | "date";
|
|
27
|
+
read: ColumnReader<string>;
|
|
28
|
+
} | {
|
|
29
|
+
type: "number";
|
|
30
|
+
read: ColumnReader<number>;
|
|
31
|
+
} | {
|
|
32
|
+
type: "boolean";
|
|
33
|
+
read: ColumnReader<boolean>;
|
|
34
|
+
});
|
|
35
|
+
/** Host-independent display and edit policy. It does not grant Better Auth permissions. */
|
|
36
|
+
interface AuthConsoleOptions {
|
|
37
|
+
access?: readonly string[];
|
|
38
|
+
actions?: Partial<Record<AuthConsoleAction, AuthConsolePolicy>>;
|
|
39
|
+
columns?: Readonly<Record<string, AuthConsoleColumn>>;
|
|
40
|
+
fields?: Readonly<Record<string, AuthConsoleFieldPolicy | undefined>>;
|
|
41
|
+
roles?: AuthConsolePolicy;
|
|
42
|
+
}
|
|
43
|
+
interface AuthConsoleCapability {
|
|
44
|
+
enabled: boolean;
|
|
45
|
+
reason?: string;
|
|
46
|
+
}
|
|
47
|
+
interface AuthConsoleField {
|
|
48
|
+
key: string;
|
|
49
|
+
label: string;
|
|
50
|
+
type: AuthConsoleFieldType;
|
|
51
|
+
values?: string[];
|
|
52
|
+
required: boolean;
|
|
53
|
+
computed: boolean;
|
|
54
|
+
edit: AuthConsoleCapability;
|
|
55
|
+
}
|
|
56
|
+
type AuthConsolePage = "overview" | "activity" | "users" | "sessions" | "organizations" | "agents";
|
|
57
|
+
interface AuthConsoleDescription {
|
|
58
|
+
access: string[];
|
|
59
|
+
actions: Record<AuthConsoleAction, AuthConsoleCapability>;
|
|
60
|
+
fields: AuthConsoleField[];
|
|
61
|
+
pages: AuthConsolePage[];
|
|
62
|
+
storage: AuthConsoleCapability;
|
|
63
|
+
events: AuthConsoleCapability;
|
|
64
|
+
/** Present only when the host enables impersonation. */
|
|
65
|
+
impersonation?: AuthConsoleImpersonation;
|
|
66
|
+
}
|
|
67
|
+
/** What the host allows. A host that renders the Console passes it with the Definition's own policy. */
|
|
68
|
+
interface AuthConsoleHostOptions {
|
|
69
|
+
/** Let the Console start and stop Better Auth admin impersonation. Off by default. */
|
|
70
|
+
impersonation?: boolean;
|
|
71
|
+
}
|
|
72
|
+
interface AuthConsoleImpersonation {
|
|
73
|
+
/** Seconds until an impersonation session ends. Better Auth's `admin({ impersonationSessionDuration })` sets it. */
|
|
74
|
+
duration: number;
|
|
75
|
+
/** The user that the app session of this request impersonates, or `null`. */
|
|
76
|
+
active: {
|
|
77
|
+
user: Pick<AuthConsoleUser, "id" | "name" | "email" | "image">;
|
|
78
|
+
expiresAt: string;
|
|
79
|
+
} | null;
|
|
80
|
+
}
|
|
81
|
+
type AuthConsoleEventGroup = "sign-in" | "admin" | "agents" | "organizations";
|
|
82
|
+
declare const authConsoleEventGroups: Readonly<Record<AuthConsoleEventGroup, readonly AuthEventType[]>>;
|
|
83
|
+
interface AuthConsoleActivityQuery {
|
|
84
|
+
group?: keyof typeof authConsoleEventGroups;
|
|
85
|
+
/** The subject user, as in AuthEventListInput. */
|
|
86
|
+
userId?: string;
|
|
87
|
+
cursor?: string;
|
|
88
|
+
limit?: number;
|
|
89
|
+
}
|
|
90
|
+
interface AuthConsoleEventUser {
|
|
91
|
+
id: string;
|
|
92
|
+
name: string;
|
|
93
|
+
available: boolean;
|
|
94
|
+
}
|
|
95
|
+
/** Explicit display projection. Event metadata and provider records stay on the server. */
|
|
96
|
+
interface AuthConsoleEvent {
|
|
97
|
+
id: string;
|
|
98
|
+
type: AuthEventType;
|
|
99
|
+
time: string;
|
|
100
|
+
actor: AuthConsoleEventUser | null;
|
|
101
|
+
subject: AuthConsoleEventUser | null;
|
|
102
|
+
}
|
|
103
|
+
interface AuthConsoleActivity {
|
|
104
|
+
enabled: boolean;
|
|
105
|
+
events: AuthConsoleEvent[];
|
|
106
|
+
nextCursor?: string;
|
|
107
|
+
}
|
|
108
|
+
interface AuthConsoleOverview {
|
|
109
|
+
users: number | null;
|
|
110
|
+
newUsers: number | null;
|
|
111
|
+
activeSessions: number | null;
|
|
112
|
+
/** Consent grants, one per user and client. Omitted without the OAuth provider plugin. */
|
|
113
|
+
approvedAgents?: number | null;
|
|
114
|
+
activeUsers: number | null;
|
|
115
|
+
window: AuthEventWindow;
|
|
116
|
+
analytics: AuthEventAggregates | null;
|
|
117
|
+
recent: AuthConsoleActivity;
|
|
118
|
+
}
|
|
119
|
+
interface AuthConsoleUser {
|
|
120
|
+
id: string;
|
|
121
|
+
name: string;
|
|
122
|
+
email: string;
|
|
123
|
+
image: string | null;
|
|
124
|
+
role: string;
|
|
125
|
+
banned: boolean;
|
|
126
|
+
banReason: string | null;
|
|
127
|
+
banExpires: string | null;
|
|
128
|
+
createdAt: string;
|
|
129
|
+
lastActive: string | null;
|
|
130
|
+
providers: string[];
|
|
131
|
+
fields: Record<string, AuthConsoleValue>;
|
|
132
|
+
}
|
|
133
|
+
interface AuthConsoleSession {
|
|
134
|
+
id: string;
|
|
135
|
+
user: Pick<AuthConsoleUser, "id" | "name" | "email" | "image">;
|
|
136
|
+
device: string;
|
|
137
|
+
createdAt: string;
|
|
138
|
+
expiresAt: string;
|
|
139
|
+
updatedAt: string;
|
|
140
|
+
}
|
|
141
|
+
interface AuthConsoleAgent {
|
|
142
|
+
id: string;
|
|
143
|
+
clientId: string;
|
|
144
|
+
name: string;
|
|
145
|
+
user: Pick<AuthConsoleUser, "id" | "name" | "email" | "image">;
|
|
146
|
+
scopes: string[];
|
|
147
|
+
createdAt: string;
|
|
148
|
+
lastUsed: string | null;
|
|
149
|
+
}
|
|
150
|
+
interface AuthConsoleOrganization {
|
|
151
|
+
id: string;
|
|
152
|
+
name: string;
|
|
153
|
+
slug: string;
|
|
154
|
+
createdAt: string;
|
|
155
|
+
}
|
|
156
|
+
interface AuthConsoleOrganizationDetail extends AuthConsoleOrganization {
|
|
157
|
+
members: Array<{
|
|
158
|
+
id: string;
|
|
159
|
+
role: string;
|
|
160
|
+
user: Pick<AuthConsoleUser, "id" | "name" | "email" | "image">;
|
|
161
|
+
}>;
|
|
162
|
+
invitations: Array<{
|
|
163
|
+
id: string;
|
|
164
|
+
email: string;
|
|
165
|
+
role: string;
|
|
166
|
+
expiresAt: string;
|
|
167
|
+
}>;
|
|
168
|
+
membersTotal: number;
|
|
169
|
+
invitationsTotal: number;
|
|
170
|
+
}
|
|
171
|
+
interface AuthConsoleUserDetail {
|
|
172
|
+
user: AuthConsoleUser;
|
|
173
|
+
sessions: AuthConsoleList<AuthConsoleSession>;
|
|
174
|
+
accounts: Array<{
|
|
175
|
+
id: string;
|
|
176
|
+
provider: string;
|
|
177
|
+
accountId: string;
|
|
178
|
+
createdAt: string;
|
|
179
|
+
}>;
|
|
180
|
+
agents: AuthConsoleList<AuthConsoleAgent>;
|
|
181
|
+
organizations: Array<AuthConsoleOrganization & {
|
|
182
|
+
role: string;
|
|
183
|
+
}>;
|
|
184
|
+
accountsTotal: number;
|
|
185
|
+
organizationsTotal: number;
|
|
186
|
+
/** Whether Better Auth accepts this user as an impersonation target. Present only when the host enables impersonation. */
|
|
187
|
+
impersonation?: AuthConsoleCapability;
|
|
188
|
+
}
|
|
189
|
+
interface AuthConsoleList<T> {
|
|
190
|
+
items: T[];
|
|
191
|
+
total: number;
|
|
192
|
+
offset: number;
|
|
193
|
+
limit: number;
|
|
194
|
+
}
|
|
195
|
+
interface AuthConsoleQuery {
|
|
196
|
+
search?: string;
|
|
197
|
+
filter?: "all" | "admins" | "banned" | "agents";
|
|
198
|
+
offset?: number;
|
|
199
|
+
limit?: number;
|
|
200
|
+
userId?: string;
|
|
201
|
+
}
|
|
202
|
+
type AuthConsoleMutation = {
|
|
203
|
+
action: "ban";
|
|
204
|
+
userId: string;
|
|
205
|
+
reason?: string;
|
|
206
|
+
expiresIn?: number;
|
|
207
|
+
} | {
|
|
208
|
+
action: "unban" | "remove" | "revokeSessions" | "impersonate";
|
|
209
|
+
userId: string;
|
|
210
|
+
} | {
|
|
211
|
+
action: "setRole";
|
|
212
|
+
userId: string;
|
|
213
|
+
role: string;
|
|
214
|
+
} | {
|
|
215
|
+
action: "editField";
|
|
216
|
+
userId: string;
|
|
217
|
+
field: string;
|
|
218
|
+
value: AuthConsoleValue;
|
|
219
|
+
} | {
|
|
220
|
+
action: "revokeSession" | "revokeConsent";
|
|
221
|
+
id: string;
|
|
222
|
+
};
|
|
223
|
+
declare const authConsoleActionNames: readonly AuthConsoleAction[];
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/types.d.ts
|
|
226
|
+
declare global {
|
|
227
|
+
namespace ViteHub {
|
|
228
|
+
interface AuthRuntimeEnv extends Record<string, unknown> {}
|
|
229
|
+
/** Generated declarations set `definition` to the type of the app's Auth Definition. */
|
|
230
|
+
interface AuthRegistry {}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
type AuthRuntimeOption = "baseURL" | "secret" | "secrets";
|
|
234
|
+
type AuthReservedOption = AuthRuntimeOption | "events" | "console" | "access" | "basePath" | "database" | "preset" | "route" | "runtime" | "secondaryStorage";
|
|
235
|
+
type AuthBetterAuthOptions = Omit<BetterAuthOptions, AuthReservedOption | "session"> & {
|
|
236
|
+
session?: AuthSessionOptions;
|
|
237
|
+
};
|
|
238
|
+
/** Session fields to write when a refresh extends the session. */
|
|
239
|
+
type AuthSessionRefreshFields = Partial<Session> & Record<string, unknown>;
|
|
240
|
+
interface AuthSessionRefreshContext {
|
|
241
|
+
/** The stored session before the refresh. */
|
|
242
|
+
session: Session & Record<string, unknown>;
|
|
243
|
+
/** The user of the session, as stored before the refresh. */
|
|
244
|
+
user: User & Record<string, unknown>;
|
|
245
|
+
/** Extend the session. Pass fields to also write them to the session. */
|
|
246
|
+
refresh: (fields?: AuthSessionRefreshFields) => void;
|
|
247
|
+
/** End the session. It wins over `refresh()`. */
|
|
248
|
+
clear: () => void;
|
|
249
|
+
}
|
|
250
|
+
/** Runs when Better Auth refreshes a stored session. Call neither `refresh()` nor `clear()` to keep the current expiry. */
|
|
251
|
+
type AuthSessionRefresh = (context: AuthSessionRefreshContext) => void | Promise<void>;
|
|
252
|
+
type AuthSessionOptions = NonNullable<BetterAuthOptions["session"]> & {
|
|
253
|
+
/** Runs when a stored session passes `updateAge`. Needs a Better Auth `database` or `secondaryStorage` adapter. */
|
|
254
|
+
onRefresh?: AuthSessionRefresh;
|
|
255
|
+
};
|
|
256
|
+
interface AuthRuntimeEnv extends ViteHub.AuthRuntimeEnv {}
|
|
257
|
+
interface AuthRuntimeContext<TEnv extends Record<string, unknown> = AuthRuntimeEnv> {
|
|
258
|
+
env: TEnv;
|
|
259
|
+
request?: Pick<Request, "headers" | "url">;
|
|
260
|
+
requestOrigin: string;
|
|
261
|
+
}
|
|
262
|
+
type AuthRuntimeOptions = Partial<Omit<BetterAuthOptions, "basePath">> & {
|
|
263
|
+
events?: AuthEventsConfiguration | false;
|
|
264
|
+
};
|
|
265
|
+
type AuthRuntimeOptionsResolver = (context: AuthRuntimeContext) => AuthRuntimeOptions;
|
|
266
|
+
type AuthRuntimeConfiguration = AuthRuntimeOptions | AuthRuntimeOptionsResolver;
|
|
267
|
+
interface AuthSignInConfiguration {
|
|
268
|
+
callbackURL?: string;
|
|
269
|
+
errorCallbackURL?: string;
|
|
270
|
+
provider: string;
|
|
271
|
+
requestSignUp?: boolean;
|
|
272
|
+
scopes?: string[];
|
|
273
|
+
}
|
|
274
|
+
interface AuthAccessRouteConfiguration {
|
|
275
|
+
authorize?: AuthAccessAuthorize;
|
|
276
|
+
method?: string;
|
|
277
|
+
route: string;
|
|
278
|
+
}
|
|
279
|
+
type AuthAccessRoute = string | AuthAccessRouteConfiguration;
|
|
280
|
+
type AuthAccessAuthorizationContext = AccessAuthorizationContext;
|
|
281
|
+
type AuthAccessAuthorizeResult = AccessAuthorizeResult;
|
|
282
|
+
type AuthAccessAuthorize = AccessAuthorize;
|
|
283
|
+
/** The checked request, Session, and user that a guarded handler receives. Only Auth guards create it. */
|
|
284
|
+
type AuthAuthorization = Readonly<AuthAccessAuthorizationContext & {
|
|
285
|
+
/** `impersonatedBy` is the id of the administrator who opened this session as `user`. Better Auth's admin plugin sets it. */
|
|
286
|
+
session: AuthAccessAuthorizationContext["session"] & {
|
|
287
|
+
impersonatedBy?: string | null;
|
|
288
|
+
};
|
|
289
|
+
}>;
|
|
290
|
+
/** A server handler that runs only after an Auth guard accepts the request. */
|
|
291
|
+
type AuthGuardedHandler<TInput, TResult> = (input: TInput, authorization: AuthAuthorization) => TResult | Promise<TResult>;
|
|
292
|
+
/**
|
|
293
|
+
* Route middleware with the `(event, next)` contract of H3 2.
|
|
294
|
+
* It returns the rejection `Response`, or the result of `next()` after the check passes.
|
|
295
|
+
*/
|
|
296
|
+
type AuthMiddleware = (event: AuthRequestInput, next: () => unknown) => Promise<unknown>;
|
|
297
|
+
interface AuthAccessConfiguration {
|
|
298
|
+
routes?: AuthAccessRoute[];
|
|
299
|
+
signIn?: AuthSignInConfiguration;
|
|
300
|
+
}
|
|
301
|
+
interface AuthDatabaseReference {
|
|
302
|
+
dedicated?: boolean;
|
|
303
|
+
name: string;
|
|
304
|
+
}
|
|
305
|
+
type AuthDatabaseConfiguration = true | AuthDatabaseReference;
|
|
306
|
+
interface AuthSecondaryStorageReference {
|
|
307
|
+
store: string;
|
|
308
|
+
}
|
|
309
|
+
type AuthSecondaryStorageConfiguration = true | AuthSecondaryStorageReference;
|
|
310
|
+
interface AuthViteHubOptions {
|
|
311
|
+
/** Opt in to durable auth events with an explicit store. */
|
|
312
|
+
events?: AuthEventsConfiguration | false;
|
|
313
|
+
console?: AuthConsoleOptions;
|
|
314
|
+
access?: AuthAccessConfiguration;
|
|
315
|
+
basePath?: string;
|
|
316
|
+
database?: AuthDatabaseConfiguration;
|
|
317
|
+
/** A ViteHub Auth preset, such as `stateless()` from `@vite-hub/auth/presets`. ViteHub checks it against the other options. */
|
|
318
|
+
preset?: AuthPreset;
|
|
319
|
+
route?: false;
|
|
320
|
+
runtime?: AuthRuntimeConfiguration;
|
|
321
|
+
secondaryStorage?: AuthSecondaryStorageConfiguration;
|
|
322
|
+
}
|
|
323
|
+
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" | "runtime" | "secondaryStorage"> & Omit<AuthRuntimeOptions, "database" | "secondaryStorage"> & {
|
|
326
|
+
database?: AuthDatabaseConfiguration | BetterAuthOptions["database"];
|
|
327
|
+
secondaryStorage?: AuthSecondaryStorageConfiguration | BetterAuthOptions["secondaryStorage"];
|
|
328
|
+
};
|
|
329
|
+
type AuthDefinitionResolver<TOptions extends AuthResolvedDefinitionOptions = AuthResolvedDefinitionOptions> = (context: AuthRuntimeContext) => TOptions;
|
|
330
|
+
type AuthDefinitionInput = AuthDefinitionOptions | AuthDefinitionResolver;
|
|
331
|
+
interface AuthDefinition<TOptions extends AuthDefinitionInput = AuthDefinitionInput> {
|
|
332
|
+
options: TOptions;
|
|
333
|
+
}
|
|
334
|
+
interface DiscoveredAuthDefinition {
|
|
335
|
+
handler: string;
|
|
336
|
+
name: "default";
|
|
337
|
+
source: "server-auth" | "server-auth-suffix";
|
|
338
|
+
}
|
|
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
|
+
interface ResolvedAuthAccessRoute {
|
|
353
|
+
authorize?: true;
|
|
354
|
+
method?: string;
|
|
355
|
+
route: string;
|
|
356
|
+
}
|
|
357
|
+
interface ResolvedAuthViteConfig {
|
|
358
|
+
access: {
|
|
359
|
+
routes: ResolvedAuthAccessRoute[];
|
|
360
|
+
};
|
|
361
|
+
basePath: string;
|
|
362
|
+
database: ResolvedAuthDatabaseConfiguration;
|
|
363
|
+
definition: DiscoveredAuthDefinition;
|
|
364
|
+
rootDir: string;
|
|
365
|
+
route: false | string;
|
|
366
|
+
secondaryStorage: false | ResolvedAuthSecondaryStorageConfiguration;
|
|
367
|
+
}
|
|
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;
|
|
369
|
+
type AuthRequest = Pick<Request, "body" | "headers" | "method" | "signal" | "url">;
|
|
370
|
+
/** The Node request fields that ViteHub Auth reads from an H3 1 event, such as a Nuxt 4 server event. */
|
|
371
|
+
interface AuthNodeRequest extends AsyncIterable<unknown> {
|
|
372
|
+
body?: unknown;
|
|
373
|
+
connection?: {
|
|
374
|
+
encrypted?: boolean;
|
|
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;
|
|
399
|
+
type ViteHubAuth<Options extends BetterAuthOptions = BetterAuthOptions> = Auth<Options>;
|
|
400
|
+
/** The Better Auth instance of an Auth Definition, with the endpoints and fields of its plugins. */
|
|
401
|
+
type AuthFor<TDefinition extends AuthDefinition> = ViteHubAuth<Extract<Omit<TDefinition["options"] extends AuthDefinitionResolver<infer TResolved> ? TResolved : TDefinition["options"], AuthReservedOption>, BetterAuthOptions>>;
|
|
402
|
+
/** The Better Auth instance of the app's discovered Auth Definition. Without generated types, the plain instance. */
|
|
403
|
+
type RegisteredAuth<TRegistry = ViteHub.AuthRegistry> = TRegistry extends {
|
|
404
|
+
definition: infer TDefinition extends AuthDefinition;
|
|
405
|
+
} ? AuthFor<TDefinition> : ViteHubAuth;
|
|
406
|
+
type AuthModuleOptions = false | Record<string, never>;
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/events.d.ts
|
|
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;
|
|
464
|
+
}
|
|
465
|
+
interface AuthEventRetention {
|
|
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;
|
|
485
|
+
//#endregion
|
|
486
|
+
export { AuthSessionRefreshContext as $, AuthDefinitionOptions as A, AuthConsoleOverview as At, AuthReservedOption as B, AuthAuthorization as C, AuthConsoleHostOptions as Ct, AuthDatabaseReference as D, AuthConsoleOptions as Dt, AuthDatabaseConfiguration as E, AuthConsoleMutation as Et, AuthModuleOptions as F, AuthConsoleUser as Ft, AuthRuntimeOnlyOptions as G, AuthRuntimeConfiguration as H, AuthNodeRequest as I, AuthConsoleUserDetail as It, AuthRuntimeOptionsResolver as J, AuthRuntimeOption as K, AuthNodeRequestEvent as L, AuthConsoleValue as Lt, AuthFor as M, AuthConsolePolicy as Mt, AuthGuardedHandler as N, AuthConsoleQuery as Nt, AuthDefinition as O, AuthConsoleOrganization as Ot, AuthMiddleware as P, AuthConsoleSession as Pt, AuthSessionRefresh as Q, AuthRequest as R, authConsoleActionNames as Rt, AuthAccessRouteConfiguration as S, AuthConsoleFieldType as St, AuthBetterAuthRuntimeOptions as T, AuthConsoleList as Tt, AuthRuntimeContext as U, AuthResolvedDefinitionOptions as V, AuthRuntimeEnv as W, AuthSecondaryStorageReference as X, AuthSecondaryStorageConfiguration as Y, AuthSessionOptions as Z, AuthAccessAuthorizationContext as _, AuthConsoleEvent as _t, AuthEventCounts as a, ResolvedAuthAccessRoute as at, AuthAccessConfiguration as b, AuthConsoleField as bt, AuthEventPage as c, ResolvedAuthViteConfig as ct, AuthEventType as d, AuthConsoleActivity as dt, AuthSessionRefreshFields as et, AuthEventWindow as f, AuthConsoleActivityQuery as ft, defaultAuthEventRetention as g, AuthConsoleDescription as gt, createDatabaseAuthEventStore as h, AuthConsoleColumn as ht, AuthEventAggregates as i, RegisteredAuth as it, AuthDefinitionResolver as j, AuthConsolePage as jt, AuthDefinitionInput as k, AuthConsoleOrganizationDetail as kt, AuthEventRetention as l, ViteHubAuth as lt, authEventTypes as m, AuthConsoleCapability as mt, AuthEvent as n, AuthViteHubOptions as nt, AuthEventListInput as o, ResolvedAuthDatabaseConfiguration as ot, AuthEventsConfiguration as p, AuthConsoleAgent as pt, AuthRuntimeOptions as q, AuthEventActor as r, DiscoveredAuthDefinition as rt, AuthEventMetadata as s, ResolvedAuthSecondaryStorageConfiguration as st, AuthDevice as t, AuthSignInConfiguration as tt, AuthEventStore as u, AuthConsoleAction as ut, AuthAccessAuthorize as v, AuthConsoleEventGroup as vt, AuthBetterAuthOptions as w, AuthConsoleImpersonation as wt, AuthAccessRoute as x, AuthConsoleFieldPolicy as xt, AuthAccessAuthorizeResult as y, AuthConsoleEventUser as yt, AuthRequestInput as z, authConsoleEventGroups as zt };
|