@vite-hub/auth 0.0.3 → 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/LICENSE +201 -0
- package/README.md +213 -41
- package/dist/agent.d.ts +25 -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 +17 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +40 -28
- package/dist/inspect-DPtsW8dB.d.ts +36 -0
- package/dist/nuxt.d.ts +59 -0
- package/dist/nuxt.js +93 -0
- 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 +3 -0
- package/dist/runtime/nuxt.js +9 -0
- 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 +3 -20
- 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 +34 -10
- package/dist/vite.js +2 -995
- package/dist/vue.d.ts +55 -0
- package/dist/vue.js +112 -0
- package/package.json +92 -17
- package/dist/server-Diw3mAbX.js +0 -322
- package/dist/shared-QSYBHaMG.js +0 -12
- package/dist/types-B0fg9XFd.d.ts +0 -106
|
@@ -0,0 +1,819 @@
|
|
|
1
|
+
import { n as authConsoleEventGroups, t as authConsoleActionNames } from "./console-types-CmmnKGMx.js";
|
|
2
|
+
import { i as parseAuthEventList } from "./events-P7mI4IQb.js";
|
|
3
|
+
import { defineErrors } from "@vite-hub/runtime";
|
|
4
|
+
import { defineGrant } from "@vite-hub/runtime/internal/grant";
|
|
5
|
+
//#region src/console-runtime.ts
|
|
6
|
+
const string = (value) => typeof value === "string" ? value : "";
|
|
7
|
+
const date = (value) => {
|
|
8
|
+
const parsed = value instanceof Date ? value : new Date(typeof value === "string" || typeof value === "number" ? value : NaN);
|
|
9
|
+
return Number.isFinite(parsed.getTime()) ? parsed.toISOString() : "";
|
|
10
|
+
};
|
|
11
|
+
const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
12
|
+
const disabled = (reason) => ({
|
|
13
|
+
enabled: false,
|
|
14
|
+
reason
|
|
15
|
+
});
|
|
16
|
+
const policyReason = (policy) => policy === false ? "Read-only in the Auth Definition." : typeof policy === "object" ? policy.reason || "Read-only in the Auth Definition." : void 0;
|
|
17
|
+
const userSummary = (user) => ({
|
|
18
|
+
id: string(user.id),
|
|
19
|
+
name: string(user.name),
|
|
20
|
+
email: string(user.email),
|
|
21
|
+
image: typeof user.image === "string" ? user.image : null
|
|
22
|
+
});
|
|
23
|
+
const equality = (field, value) => [{
|
|
24
|
+
field,
|
|
25
|
+
value
|
|
26
|
+
}];
|
|
27
|
+
const strings = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
28
|
+
/** The admin plugin options, with roles and user ids read as Better Auth reads them. */
|
|
29
|
+
function adminPlugin(options) {
|
|
30
|
+
const plugin = options.plugins?.find((plugin) => plugin.id === "admin");
|
|
31
|
+
const settings = record(plugin?.options);
|
|
32
|
+
const configured = settings.adminRoles ?? ["admin"];
|
|
33
|
+
return {
|
|
34
|
+
settings,
|
|
35
|
+
roles: (Array.isArray(configured) ? strings(configured) : string(configured).split(",")).map((role) => role.trim()),
|
|
36
|
+
userIds: strings(settings.adminUserIds)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const endpoints = {
|
|
40
|
+
ban: "banUser",
|
|
41
|
+
unban: "unbanUser",
|
|
42
|
+
remove: "removeUser",
|
|
43
|
+
revokeSession: "revokeUserSession",
|
|
44
|
+
revokeSessions: "revokeUserSessions",
|
|
45
|
+
setRole: "setRole",
|
|
46
|
+
editField: "adminUpdateUser",
|
|
47
|
+
impersonate: "impersonateUser"
|
|
48
|
+
};
|
|
49
|
+
const permissions = {
|
|
50
|
+
ban: { user: ["ban"] },
|
|
51
|
+
unban: { user: ["ban"] },
|
|
52
|
+
remove: { user: ["delete"] },
|
|
53
|
+
revokeSession: { session: ["revoke"] },
|
|
54
|
+
revokeSessions: { session: ["revoke"] },
|
|
55
|
+
setRole: { user: ["set-role"] },
|
|
56
|
+
editField: { user: ["update"] },
|
|
57
|
+
impersonate: { user: ["impersonate"] }
|
|
58
|
+
};
|
|
59
|
+
var AuthConsoleError = class extends Error {
|
|
60
|
+
status;
|
|
61
|
+
constructor(status, message) {
|
|
62
|
+
super(message);
|
|
63
|
+
this.status = status;
|
|
64
|
+
this.name = "AuthConsoleError";
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const errors = defineErrors({
|
|
68
|
+
docs: "https://vitehub.dev/docs/auth/limits-and-errors",
|
|
69
|
+
codes: {
|
|
70
|
+
AUTH_CONSOLE_INVALID_REQUEST: {
|
|
71
|
+
why: "The Auth Console request does not match its field or pagination contract.",
|
|
72
|
+
fix: "Use a declared field value and a limit from 1 to 100."
|
|
73
|
+
},
|
|
74
|
+
AUTH_CONSOLE_FORBIDDEN: {
|
|
75
|
+
why: "The app policy or Better Auth session does not permit this action.",
|
|
76
|
+
fix: "Check describe(request) for the disabled action reason and use an app admin session."
|
|
77
|
+
},
|
|
78
|
+
AUTH_CONSOLE_NOT_FOUND: {
|
|
79
|
+
why: "The requested Auth record or plugin is not available.",
|
|
80
|
+
fix: "Refresh the list and check the Auth Definition's plugins."
|
|
81
|
+
},
|
|
82
|
+
AUTH_CONSOLE_UNAVAILABLE: {
|
|
83
|
+
why: "Auth does not have the database or plugin API needed for this operation.",
|
|
84
|
+
fix: "Configure a database adapter and the required Better Auth plugin."
|
|
85
|
+
},
|
|
86
|
+
AUTH_CONSOLE_PROVIDER_FAILED: {
|
|
87
|
+
why: "Better Auth or an app column reader could not complete the operation.",
|
|
88
|
+
fix: "Inspect the server-side cause and check the provider configuration."
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
async function result(run) {
|
|
93
|
+
try {
|
|
94
|
+
return [void 0, await run()];
|
|
95
|
+
} catch (cause) {
|
|
96
|
+
const status = cause instanceof AuthConsoleError ? cause.status : 500;
|
|
97
|
+
return [errors[status === 400 ? "AUTH_CONSOLE_INVALID_REQUEST" : status === 401 || status === 403 ? "AUTH_CONSOLE_FORBIDDEN" : status === 404 ? "AUTH_CONSOLE_NOT_FOUND" : status === 409 ? "AUTH_CONSOLE_UNAVAILABLE" : "AUTH_CONSOLE_PROVIDER_FAILED"]({ cause }), void 0];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function pagination(query) {
|
|
101
|
+
const offset = query.offset ?? 0;
|
|
102
|
+
const limit = query.limit ?? 25;
|
|
103
|
+
if (!Number.isSafeInteger(offset) || offset < 0 || !Number.isSafeInteger(limit) || limit < 1 || limit > 100) throw new AuthConsoleError(400, "Use a non-negative offset and a limit from 1 to 100.");
|
|
104
|
+
return {
|
|
105
|
+
offset,
|
|
106
|
+
limit
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function valueFor(value, field) {
|
|
110
|
+
if (value === null || value === void 0) return null;
|
|
111
|
+
if (field.type === "date") return date(value) || null;
|
|
112
|
+
if (field.type === "string" && typeof value === "string") return value;
|
|
113
|
+
if (field.type === "number" && typeof value === "number" && Number.isFinite(value)) return value;
|
|
114
|
+
if (field.type === "boolean" && typeof value === "boolean") return value;
|
|
115
|
+
if (field.type === "string[]" && Array.isArray(value) && value.every((item) => typeof item === "string")) return value;
|
|
116
|
+
if (field.type === "number[]" && Array.isArray(value) && value.every((item) => typeof item === "number" && Number.isFinite(item))) return value;
|
|
117
|
+
if (field.type === "json") return JSON.stringify(value);
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
/** Only additional fields that Better Auth allows in output reach the Console. */
|
|
121
|
+
function describeAuthConsoleFields(options, policy = {}) {
|
|
122
|
+
const fields = [];
|
|
123
|
+
for (const key of Object.keys(policy.fields ?? {})) if (!Object.hasOwn(options.user?.additionalFields ?? {}, key)) throw new AuthConsoleError(400, `The Console field ${key} is not an additional user field.`);
|
|
124
|
+
for (const [key, field] of Object.entries(options.user?.additionalFields ?? {})) {
|
|
125
|
+
if (field.returned === false) continue;
|
|
126
|
+
const configured = policy.fields?.[key];
|
|
127
|
+
const values = Array.isArray(field.type) ? [...field.type] : void 0;
|
|
128
|
+
const type = values ? "string" : field.type;
|
|
129
|
+
const supported = [
|
|
130
|
+
"string",
|
|
131
|
+
"number",
|
|
132
|
+
"boolean",
|
|
133
|
+
"date",
|
|
134
|
+
"string[]",
|
|
135
|
+
"number[]"
|
|
136
|
+
].includes(String(type));
|
|
137
|
+
fields.push({
|
|
138
|
+
key,
|
|
139
|
+
label: configured?.label ?? key,
|
|
140
|
+
type: supported ? type : "json",
|
|
141
|
+
values,
|
|
142
|
+
required: field.required === true,
|
|
143
|
+
computed: false,
|
|
144
|
+
edit: configured?.editable === true && supported ? { enabled: true } : disabled(configured?.reason ?? "This field is read-only in the Auth Definition.")
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
for (const [key, column] of Object.entries(policy.columns ?? {})) {
|
|
148
|
+
if (fields.some((field) => field.key === key) || Object.hasOwn(options.user?.additionalFields ?? {}, key)) throw new AuthConsoleError(400, `The computed column ${key} conflicts with a user field.`);
|
|
149
|
+
fields.push({
|
|
150
|
+
key,
|
|
151
|
+
label: column.label,
|
|
152
|
+
type: column.type,
|
|
153
|
+
required: false,
|
|
154
|
+
computed: true,
|
|
155
|
+
edit: disabled("Computed by the app.")
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return fields;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Read and manage the app's Better Auth data from trusted server code. HTTP hosts must check access before calling it.
|
|
162
|
+
* Writes require a real Better Auth session and pass through its plugin APIs. No adapter writes are used here.
|
|
163
|
+
* Impersonation stays off unless `host.impersonation` is `true`.
|
|
164
|
+
*/
|
|
165
|
+
function createAuthConsole(auth, policy = {}, events, host = {}) {
|
|
166
|
+
async function context() {
|
|
167
|
+
return await auth.$context;
|
|
168
|
+
}
|
|
169
|
+
function endpoint(name) {
|
|
170
|
+
const call = Reflect.get(auth.api, name);
|
|
171
|
+
if (typeof call !== "function") return void 0;
|
|
172
|
+
return call;
|
|
173
|
+
}
|
|
174
|
+
async function call(name, request, body, asResponse = false) {
|
|
175
|
+
const run = endpoint(name);
|
|
176
|
+
if (!run) throw new AuthConsoleError(409, "The required Better Auth plugin endpoint is not installed.");
|
|
177
|
+
return await run({
|
|
178
|
+
headers: request.headers,
|
|
179
|
+
body,
|
|
180
|
+
asResponse
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/** The stored app session of the request, without a cookie cache read or a refresh write. */
|
|
184
|
+
async function appSession(request) {
|
|
185
|
+
const value = record(await endpoint("getSession")({
|
|
186
|
+
headers: request.headers,
|
|
187
|
+
query: {
|
|
188
|
+
disableCookieCache: true,
|
|
189
|
+
disableRefresh: true
|
|
190
|
+
}
|
|
191
|
+
}));
|
|
192
|
+
return value.session && value.user ? {
|
|
193
|
+
session: record(value.session),
|
|
194
|
+
user: record(value.user)
|
|
195
|
+
} : null;
|
|
196
|
+
}
|
|
197
|
+
async function permitted(request, permissions) {
|
|
198
|
+
try {
|
|
199
|
+
return record(await call("userHasPermission", request, { permissions })).success === true;
|
|
200
|
+
} catch {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async function features() {
|
|
205
|
+
const ctx = await context();
|
|
206
|
+
const ids = new Set(ctx.options.plugins?.map((plugin) => plugin.id));
|
|
207
|
+
return {
|
|
208
|
+
ctx,
|
|
209
|
+
organization: ids.has("organization"),
|
|
210
|
+
oauth: ids.has("oauth-provider"),
|
|
211
|
+
mcp: ids.has("mcp")
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
async function describe(request) {
|
|
215
|
+
const { ctx, organization, oauth, mcp } = await features();
|
|
216
|
+
const storage = ctx.options.database ? { enabled: true } : disabled("Auth has no durable database. Configure a Better Auth database adapter to inspect stored users and sessions.");
|
|
217
|
+
const actions = {};
|
|
218
|
+
const session = host.impersonation && request && storage.enabled ? await appSession(request).catch(() => null) : null;
|
|
219
|
+
const impersonatedBy = string(session?.session.impersonatedBy);
|
|
220
|
+
await Promise.all(authConsoleActionNames.map(async (action) => {
|
|
221
|
+
let reason = action === "impersonate" && !host.impersonation ? "Impersonation is off in the Console configuration." : void 0;
|
|
222
|
+
reason ??= policyReason(policy.actions?.[action]) ?? (action === "setRole" ? policyReason(policy.roles) : void 0);
|
|
223
|
+
if (!reason && !storage.enabled) reason = storage.reason;
|
|
224
|
+
if (!reason && action === "revokeConsent") reason = "Better Auth has no admin endpoint to revoke one user's client grant. Deleting a consent alone does not revoke issued tokens.";
|
|
225
|
+
if (!reason && action !== "revokeConsent" && !endpoint(endpoints[action])) reason = "Enable the Better Auth admin plugin.";
|
|
226
|
+
if (!reason && action === "impersonate" && !events) reason = "Add events.store to defineAuth() so that impersonation is recorded.";
|
|
227
|
+
if (!reason && !request) reason = "Sign in with an app session to run this action.";
|
|
228
|
+
if (!reason && action === "impersonate" && impersonatedBy) reason = "This browser already impersonates a user. Stop impersonating first.";
|
|
229
|
+
if (!reason && request && action !== "revokeConsent") try {
|
|
230
|
+
if (record(await call("userHasPermission", request, { permissions: permissions[action] })).success !== true) reason = "Your app session does not have this Better Auth permission.";
|
|
231
|
+
} catch {
|
|
232
|
+
reason = "Sign in with an app admin session to run this action.";
|
|
233
|
+
}
|
|
234
|
+
actions[action] = reason ? disabled(reason) : { enabled: true };
|
|
235
|
+
}));
|
|
236
|
+
const fields = describeAuthConsoleFields(ctx.options, policy).map((field) => ({
|
|
237
|
+
...field,
|
|
238
|
+
edit: field.edit.enabled && !actions.editField.enabled ? actions.editField : field.edit
|
|
239
|
+
}));
|
|
240
|
+
return {
|
|
241
|
+
access: [...policy.access ?? []],
|
|
242
|
+
actions,
|
|
243
|
+
fields,
|
|
244
|
+
pages: [
|
|
245
|
+
"overview",
|
|
246
|
+
"users",
|
|
247
|
+
"sessions",
|
|
248
|
+
...organization ? ["organizations"] : [],
|
|
249
|
+
...oauth || mcp ? ["agents"] : [],
|
|
250
|
+
"activity"
|
|
251
|
+
],
|
|
252
|
+
storage,
|
|
253
|
+
events: events ? { enabled: true } : disabled("Add events.store to defineAuth() to record auth activity."),
|
|
254
|
+
...host.impersonation ? { impersonation: {
|
|
255
|
+
duration: impersonationDuration(ctx.options),
|
|
256
|
+
active: impersonatedBy && session ? {
|
|
257
|
+
user: userSummary(session.user),
|
|
258
|
+
expiresAt: date(session.session.expiresAt)
|
|
259
|
+
} : null
|
|
260
|
+
} } : {}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/** Better Auth's default is one hour. */
|
|
264
|
+
function impersonationDuration(options) {
|
|
265
|
+
const seconds = adminPlugin(options).settings.impersonationSessionDuration;
|
|
266
|
+
return typeof seconds === "number" && Number.isFinite(seconds) && seconds > 0 ? seconds : 3600;
|
|
267
|
+
}
|
|
268
|
+
/** Better Auth refuses banned users and, unless the admin plugin allows it, administrators. */
|
|
269
|
+
async function impersonationTarget(row, request) {
|
|
270
|
+
const ban = new Date(date(row.banExpires) || NaN).getTime();
|
|
271
|
+
if (row.banned === true && !(ban < Date.now())) return disabled("Better Auth does not open sessions for banned users.");
|
|
272
|
+
const admin = adminPlugin((await context()).options);
|
|
273
|
+
if (((string(row.role) || string(admin.settings.defaultRole) || "user").split(",").some((role) => admin.roles.includes(role)) || admin.userIds.includes(string(row.id))) && admin.settings.allowImpersonatingAdmins !== true && !(request && await permitted(request, { user: ["impersonate-admins"] }))) return disabled("Better Auth does not impersonate administrators.");
|
|
274
|
+
return { enabled: true };
|
|
275
|
+
}
|
|
276
|
+
async function activity(query = {}) {
|
|
277
|
+
let input;
|
|
278
|
+
try {
|
|
279
|
+
if (query.group !== void 0 && !Object.hasOwn(authConsoleEventGroups, query.group)) throw new TypeError("Unknown auth event group.");
|
|
280
|
+
input = parseAuthEventList({
|
|
281
|
+
type: query.group ? authConsoleEventGroups[query.group] : void 0,
|
|
282
|
+
userId: query.userId,
|
|
283
|
+
cursor: query.cursor,
|
|
284
|
+
limit: query.limit ?? 25
|
|
285
|
+
}).query;
|
|
286
|
+
} catch {
|
|
287
|
+
throw new AuthConsoleError(400, "Invalid auth activity filters or cursor.");
|
|
288
|
+
}
|
|
289
|
+
if (!events) return {
|
|
290
|
+
enabled: false,
|
|
291
|
+
events: []
|
|
292
|
+
};
|
|
293
|
+
const page = await events.list(input);
|
|
294
|
+
const ids = [...new Set(page.events.flatMap((event) => [...event.userId ? [event.userId] : [], ...event.actor.startsWith("user:") ? [event.actor.slice(5)] : []]))];
|
|
295
|
+
const ctx = await context();
|
|
296
|
+
const rows = ctx.options.database && ids.length ? await ctx.adapter.findMany({
|
|
297
|
+
model: "user",
|
|
298
|
+
where: [{
|
|
299
|
+
field: "id",
|
|
300
|
+
operator: "in",
|
|
301
|
+
value: ids
|
|
302
|
+
}],
|
|
303
|
+
select: ["id", "name"],
|
|
304
|
+
limit: ids.length
|
|
305
|
+
}) : [];
|
|
306
|
+
const names = new Map(rows.map((row) => [string(row.id), string(row.name)]));
|
|
307
|
+
const user = (id) => ({
|
|
308
|
+
id,
|
|
309
|
+
name: names.get(id) || id,
|
|
310
|
+
available: names.has(id)
|
|
311
|
+
});
|
|
312
|
+
return {
|
|
313
|
+
enabled: true,
|
|
314
|
+
events: page.events.map((event) => ({
|
|
315
|
+
id: event.id,
|
|
316
|
+
type: event.type,
|
|
317
|
+
time: event.time,
|
|
318
|
+
actor: event.actor.startsWith("user:") ? user(event.actor.slice(5)) : null,
|
|
319
|
+
subject: event.userId ? user(event.userId) : null
|
|
320
|
+
})),
|
|
321
|
+
...page.nextCursor ? { nextCursor: page.nextCursor } : {}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
async function overview() {
|
|
325
|
+
const { ctx, oauth } = await features();
|
|
326
|
+
const now = Date.now();
|
|
327
|
+
const week = /* @__PURE__ */ new Date(now - 6048e5);
|
|
328
|
+
const today = new Date(now).toISOString().slice(0, 10);
|
|
329
|
+
const window = {
|
|
330
|
+
from: (/* @__PURE__ */ new Date(Date.parse(`${today}T00:00:00.000Z`) - 25056e5)).toISOString(),
|
|
331
|
+
to: new Date(now + 1).toISOString()
|
|
332
|
+
};
|
|
333
|
+
const db = ctx.options.database ? ctx.adapter : void 0;
|
|
334
|
+
const persistedSessions = db && (!ctx.options.secondaryStorage || ctx.options.session?.storeSessionInDatabase);
|
|
335
|
+
const [users, newUsers, activeSessions, approvedAgents, analytics, recent, weekEvents] = await Promise.all([
|
|
336
|
+
db ? db.count({ model: "user" }) : null,
|
|
337
|
+
db ? db.count({
|
|
338
|
+
model: "user",
|
|
339
|
+
where: [{
|
|
340
|
+
field: "createdAt",
|
|
341
|
+
operator: "gte",
|
|
342
|
+
value: week
|
|
343
|
+
}, {
|
|
344
|
+
field: "createdAt",
|
|
345
|
+
operator: "lte",
|
|
346
|
+
value: new Date(now)
|
|
347
|
+
}]
|
|
348
|
+
}) : null,
|
|
349
|
+
persistedSessions ? db.count({
|
|
350
|
+
model: "session",
|
|
351
|
+
where: [{
|
|
352
|
+
field: "expiresAt",
|
|
353
|
+
operator: "gt",
|
|
354
|
+
value: new Date(now)
|
|
355
|
+
}]
|
|
356
|
+
}) : null,
|
|
357
|
+
oauth ? db ? db.count({ model: "oauthConsent" }) : null : void 0,
|
|
358
|
+
events ? events.aggregate(window) : null,
|
|
359
|
+
activity({ limit: 8 }),
|
|
360
|
+
events ? events.aggregate({
|
|
361
|
+
from: week.toISOString(),
|
|
362
|
+
to: window.to
|
|
363
|
+
}) : null
|
|
364
|
+
]);
|
|
365
|
+
const counts = (value) => ({
|
|
366
|
+
signIns: value.signIns,
|
|
367
|
+
signUps: value.signUps,
|
|
368
|
+
activeUsers: value.activeUsers,
|
|
369
|
+
methods: Object.fromEntries(Object.entries(value.methods))
|
|
370
|
+
});
|
|
371
|
+
return {
|
|
372
|
+
users,
|
|
373
|
+
newUsers,
|
|
374
|
+
activeSessions,
|
|
375
|
+
...oauth ? { approvedAgents } : {},
|
|
376
|
+
activeUsers: weekEvents?.totals.activeUsers ?? null,
|
|
377
|
+
window,
|
|
378
|
+
recent,
|
|
379
|
+
analytics: analytics ? {
|
|
380
|
+
days: analytics.days.map((day) => ({
|
|
381
|
+
day: day.day,
|
|
382
|
+
...counts(day)
|
|
383
|
+
})),
|
|
384
|
+
totals: counts(analytics.totals)
|
|
385
|
+
} : null
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
async function adapter() {
|
|
389
|
+
const ctx = await context();
|
|
390
|
+
if (!ctx.options.database) throw new AuthConsoleError(409, "Configure a Better Auth database adapter to inspect stored Auth data.");
|
|
391
|
+
return ctx.adapter;
|
|
392
|
+
}
|
|
393
|
+
async function find(model, where) {
|
|
394
|
+
return await (await adapter()).findOne({
|
|
395
|
+
model,
|
|
396
|
+
where
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
async function list(model, query, where = []) {
|
|
400
|
+
const db = await adapter();
|
|
401
|
+
const { offset, limit } = pagination(query);
|
|
402
|
+
const [items, total] = await Promise.all([db.findMany({
|
|
403
|
+
model,
|
|
404
|
+
where,
|
|
405
|
+
offset,
|
|
406
|
+
limit,
|
|
407
|
+
sortBy: {
|
|
408
|
+
field: "id",
|
|
409
|
+
direction: "asc"
|
|
410
|
+
}
|
|
411
|
+
}), db.count({
|
|
412
|
+
model,
|
|
413
|
+
where
|
|
414
|
+
})]);
|
|
415
|
+
return {
|
|
416
|
+
items,
|
|
417
|
+
total,
|
|
418
|
+
offset,
|
|
419
|
+
limit
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
async function ids(model, field, where = []) {
|
|
423
|
+
const db = await adapter();
|
|
424
|
+
const result = /* @__PURE__ */ new Set();
|
|
425
|
+
for (let offset = 0;; offset += 500) {
|
|
426
|
+
const rows = await db.findMany({
|
|
427
|
+
model,
|
|
428
|
+
where,
|
|
429
|
+
select: ["id", field],
|
|
430
|
+
offset,
|
|
431
|
+
limit: 500,
|
|
432
|
+
sortBy: {
|
|
433
|
+
field: "id",
|
|
434
|
+
direction: "asc"
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
for (const row of rows) if (typeof row[field] === "string") result.add(string(row[field]));
|
|
438
|
+
if (rows.length < 500) return [...result].sort();
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
async function users(query = {}) {
|
|
442
|
+
pagination(query);
|
|
443
|
+
if (query.search && query.search.length > 200) throw new AuthConsoleError(400, "Search must have at most 200 characters.");
|
|
444
|
+
if (query.filter && ![
|
|
445
|
+
"all",
|
|
446
|
+
"admins",
|
|
447
|
+
"banned",
|
|
448
|
+
"agents"
|
|
449
|
+
].includes(query.filter)) throw new AuthConsoleError(400, "Unknown user filter.");
|
|
450
|
+
const where = [];
|
|
451
|
+
const { ctx, oauth, mcp } = await features();
|
|
452
|
+
if (query.filter === "banned") where.push({
|
|
453
|
+
field: "banned",
|
|
454
|
+
value: true
|
|
455
|
+
});
|
|
456
|
+
if (["banned", "admins"].includes(query.filter ?? "") && !ctx.options.plugins?.some((plugin) => plugin.id === "admin")) return {
|
|
457
|
+
...pagination(query),
|
|
458
|
+
total: 0,
|
|
459
|
+
items: []
|
|
460
|
+
};
|
|
461
|
+
let matches;
|
|
462
|
+
if (query.search?.trim()) matches = await ids("user", "id", [{
|
|
463
|
+
field: "name",
|
|
464
|
+
operator: "contains",
|
|
465
|
+
value: query.search.trim(),
|
|
466
|
+
mode: "insensitive",
|
|
467
|
+
connector: "OR"
|
|
468
|
+
}, {
|
|
469
|
+
field: "email",
|
|
470
|
+
operator: "contains",
|
|
471
|
+
value: query.search.trim(),
|
|
472
|
+
mode: "insensitive",
|
|
473
|
+
connector: "OR"
|
|
474
|
+
}]);
|
|
475
|
+
if (query.filter === "admins") {
|
|
476
|
+
const admin = adminPlugin(ctx.options);
|
|
477
|
+
const matchesRole = admin.roles.flatMap((role) => [
|
|
478
|
+
{
|
|
479
|
+
field: "role",
|
|
480
|
+
value: role,
|
|
481
|
+
connector: "OR"
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
field: "role",
|
|
485
|
+
value: `${role},`,
|
|
486
|
+
operator: "starts_with",
|
|
487
|
+
connector: "OR"
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
field: "role",
|
|
491
|
+
value: `,${role}`,
|
|
492
|
+
operator: "ends_with",
|
|
493
|
+
connector: "OR"
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
field: "role",
|
|
497
|
+
value: `,${role},`,
|
|
498
|
+
operator: "contains",
|
|
499
|
+
connector: "OR"
|
|
500
|
+
}
|
|
501
|
+
]);
|
|
502
|
+
const adminIds = /* @__PURE__ */ new Set([...matchesRole.length ? await ids("user", "id", matchesRole) : [], ...admin.userIds]);
|
|
503
|
+
matches = matches ? matches.filter((id) => adminIds.has(id)) : [...adminIds].sort();
|
|
504
|
+
}
|
|
505
|
+
if (query.filter === "agents") {
|
|
506
|
+
const approved = oauth || mcp ? await ids("oauthConsent", "userId") : [];
|
|
507
|
+
const approvedSet = new Set(approved);
|
|
508
|
+
matches = matches ? matches.filter((id) => approvedSet.has(id)) : approved;
|
|
509
|
+
}
|
|
510
|
+
let result;
|
|
511
|
+
if (!matches) result = await list("user", query, where);
|
|
512
|
+
else {
|
|
513
|
+
const { offset, limit } = pagination(query);
|
|
514
|
+
result = {
|
|
515
|
+
offset,
|
|
516
|
+
limit,
|
|
517
|
+
total: 0,
|
|
518
|
+
items: []
|
|
519
|
+
};
|
|
520
|
+
for (let start = 0; start < matches.length; start += 400) {
|
|
521
|
+
const batchWhere = [...where, {
|
|
522
|
+
field: "id",
|
|
523
|
+
operator: "in",
|
|
524
|
+
value: matches.slice(start, start + 400)
|
|
525
|
+
}];
|
|
526
|
+
const batch = await list("user", {
|
|
527
|
+
offset: Math.max(0, offset - result.total),
|
|
528
|
+
limit
|
|
529
|
+
}, batchWhere);
|
|
530
|
+
result.total += batch.total;
|
|
531
|
+
result.items.push(...batch.items.slice(0, limit - result.items.length));
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return {
|
|
535
|
+
...result,
|
|
536
|
+
items: await enrichUsers(result.items)
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
async function enrichUsers(rows) {
|
|
540
|
+
const db = await adapter();
|
|
541
|
+
const fields = describeAuthConsoleFields((await context()).options, policy);
|
|
542
|
+
const computed = /* @__PURE__ */ new Map();
|
|
543
|
+
const publicUsers = rows.map((row) => ({
|
|
544
|
+
...userSummary(row),
|
|
545
|
+
emailVerified: row.emailVerified === true,
|
|
546
|
+
createdAt: new Date(date(row.createdAt)),
|
|
547
|
+
updatedAt: new Date(date(row.updatedAt))
|
|
548
|
+
}));
|
|
549
|
+
await Promise.all(Object.entries(policy.columns ?? {}).map(async ([key, column]) => {
|
|
550
|
+
computed.set(key, await column.read(publicUsers));
|
|
551
|
+
}));
|
|
552
|
+
return await Promise.all(rows.map(async (row) => {
|
|
553
|
+
const userId = string(row.id);
|
|
554
|
+
const [accounts, recent] = await Promise.all([db.findMany({
|
|
555
|
+
model: "account",
|
|
556
|
+
where: equality("userId", userId),
|
|
557
|
+
select: ["providerId"],
|
|
558
|
+
limit: 100
|
|
559
|
+
}), db.findMany({
|
|
560
|
+
model: "session",
|
|
561
|
+
where: equality("userId", userId),
|
|
562
|
+
select: ["updatedAt"],
|
|
563
|
+
limit: 1,
|
|
564
|
+
sortBy: {
|
|
565
|
+
field: "updatedAt",
|
|
566
|
+
direction: "desc"
|
|
567
|
+
}
|
|
568
|
+
})]);
|
|
569
|
+
return {
|
|
570
|
+
...userSummary(row),
|
|
571
|
+
role: string(row.role) || "user",
|
|
572
|
+
banned: row.banned === true,
|
|
573
|
+
banReason: typeof row.banReason === "string" ? row.banReason : null,
|
|
574
|
+
banExpires: date(row.banExpires) || null,
|
|
575
|
+
createdAt: date(row.createdAt),
|
|
576
|
+
lastActive: date(recent[0]?.updatedAt) || null,
|
|
577
|
+
providers: [...new Set(accounts.map((account) => string(account.providerId)))],
|
|
578
|
+
fields: Object.fromEntries(fields.map((field) => [field.key, valueFor(field.computed ? computed.get(field.key)?.[userId] : row[field.key], field)]))
|
|
579
|
+
};
|
|
580
|
+
}));
|
|
581
|
+
}
|
|
582
|
+
async function sessions(query = {}) {
|
|
583
|
+
const rows = await list("session", query, [{
|
|
584
|
+
field: "expiresAt",
|
|
585
|
+
operator: "gt",
|
|
586
|
+
value: /* @__PURE__ */ new Date()
|
|
587
|
+
}, ...query.userId ? equality("userId", query.userId) : []]);
|
|
588
|
+
return {
|
|
589
|
+
...rows,
|
|
590
|
+
items: await Promise.all(rows.items.map(async (row) => ({
|
|
591
|
+
id: string(row.id),
|
|
592
|
+
user: userSummary(await find("user", equality("id", string(row.userId))) ?? { id: row.userId }),
|
|
593
|
+
device: authConsoleDevice(string(row.userAgent)),
|
|
594
|
+
createdAt: date(row.createdAt),
|
|
595
|
+
expiresAt: date(row.expiresAt),
|
|
596
|
+
updatedAt: date(row.updatedAt)
|
|
597
|
+
})))
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
async function agents(query = {}) {
|
|
601
|
+
const { oauth, mcp } = await features();
|
|
602
|
+
if (!oauth && !mcp) throw new AuthConsoleError(404, "Enable the OAuth provider or MCP plugin to inspect approved clients.");
|
|
603
|
+
const rows = await list("oauthConsent", query, query.userId ? equality("userId", query.userId) : []);
|
|
604
|
+
return {
|
|
605
|
+
...rows,
|
|
606
|
+
items: await Promise.all(rows.items.map(async (row) => {
|
|
607
|
+
const clientId = string(row.clientId);
|
|
608
|
+
const client = await find(oauth ? "oauthClient" : "oauthApplication", equality("clientId", clientId));
|
|
609
|
+
return {
|
|
610
|
+
id: string(row.id),
|
|
611
|
+
clientId,
|
|
612
|
+
name: string(client?.name) || clientId,
|
|
613
|
+
user: userSummary(await find("user", equality("id", string(row.userId))) ?? { id: row.userId }),
|
|
614
|
+
scopes: Array.isArray(row.scopes) ? row.scopes.filter((value) => typeof value === "string") : string(row.scopes).split(/[ ,]+/).filter(Boolean),
|
|
615
|
+
createdAt: date(row.createdAt),
|
|
616
|
+
lastUsed: date(row.lastUsedAt) || null
|
|
617
|
+
};
|
|
618
|
+
}))
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
function organizationRow(row) {
|
|
622
|
+
return {
|
|
623
|
+
id: string(row.id),
|
|
624
|
+
name: string(row.name),
|
|
625
|
+
slug: string(row.slug),
|
|
626
|
+
createdAt: date(row.createdAt)
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
async function organizations(query = {}) {
|
|
630
|
+
if (!(await features()).organization) throw new AuthConsoleError(404, "Enable the Better Auth organization plugin.");
|
|
631
|
+
const rows = await list("organization", query);
|
|
632
|
+
return {
|
|
633
|
+
...rows,
|
|
634
|
+
items: rows.items.map(organizationRow)
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
async function organization(id, query = {}) {
|
|
638
|
+
if (!(await features()).organization) throw new AuthConsoleError(404, "Enable the Better Auth organization plugin.");
|
|
639
|
+
const row = await find("organization", equality("id", id));
|
|
640
|
+
if (!row) throw new AuthConsoleError(404, "Organization not found.");
|
|
641
|
+
const [members, invitations] = await Promise.all([list("member", query, equality("organizationId", id)), list("invitation", query, [
|
|
642
|
+
...equality("organizationId", id),
|
|
643
|
+
{
|
|
644
|
+
field: "status",
|
|
645
|
+
value: "pending"
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
field: "expiresAt",
|
|
649
|
+
value: /* @__PURE__ */ new Date(),
|
|
650
|
+
operator: "gt"
|
|
651
|
+
}
|
|
652
|
+
])]);
|
|
653
|
+
return {
|
|
654
|
+
...organizationRow(row),
|
|
655
|
+
membersTotal: members.total,
|
|
656
|
+
invitationsTotal: invitations.total,
|
|
657
|
+
members: await Promise.all(members.items.map(async (member) => ({
|
|
658
|
+
id: string(member.id),
|
|
659
|
+
role: string(member.role),
|
|
660
|
+
user: userSummary(await find("user", equality("id", string(member.userId))) ?? { id: member.userId })
|
|
661
|
+
}))),
|
|
662
|
+
invitations: invitations.items.map((invitation) => ({
|
|
663
|
+
id: string(invitation.id),
|
|
664
|
+
email: string(invitation.email),
|
|
665
|
+
role: string(invitation.role),
|
|
666
|
+
expiresAt: date(invitation.expiresAt)
|
|
667
|
+
}))
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
async function user(id, request) {
|
|
671
|
+
const row = await find("user", equality("id", id));
|
|
672
|
+
if (!row) throw new AuthConsoleError(404, "User not found.");
|
|
673
|
+
const { oauth, mcp, organization } = await features();
|
|
674
|
+
const [enriched, sessionRows, accounts, agentRows, memberships, target] = await Promise.all([
|
|
675
|
+
enrichUsers([row]),
|
|
676
|
+
sessions({ userId: id }),
|
|
677
|
+
list("account", { limit: 100 }, equality("userId", id)),
|
|
678
|
+
oauth || mcp ? agents({ userId: id }) : {
|
|
679
|
+
items: [],
|
|
680
|
+
total: 0,
|
|
681
|
+
offset: 0,
|
|
682
|
+
limit: 25
|
|
683
|
+
},
|
|
684
|
+
organization ? list("member", { limit: 100 }, equality("userId", id)) : {
|
|
685
|
+
items: [],
|
|
686
|
+
total: 0
|
|
687
|
+
},
|
|
688
|
+
host.impersonation ? impersonationTarget(row, request) : void 0
|
|
689
|
+
]);
|
|
690
|
+
return {
|
|
691
|
+
...target ? { impersonation: target } : {},
|
|
692
|
+
user: enriched[0],
|
|
693
|
+
sessions: sessionRows,
|
|
694
|
+
accountsTotal: accounts.total,
|
|
695
|
+
organizationsTotal: memberships.total,
|
|
696
|
+
accounts: accounts.items.map((account) => ({
|
|
697
|
+
id: string(account.id),
|
|
698
|
+
provider: string(account.providerId),
|
|
699
|
+
accountId: string(account.accountId),
|
|
700
|
+
createdAt: date(account.createdAt)
|
|
701
|
+
})),
|
|
702
|
+
agents: agentRows,
|
|
703
|
+
organizations: (await Promise.all(memberships.items.map(async (membership) => {
|
|
704
|
+
const org = await find("organization", equality("id", string(membership.organizationId)));
|
|
705
|
+
return org ? {
|
|
706
|
+
...organizationRow(org),
|
|
707
|
+
role: string(membership.role)
|
|
708
|
+
} : void 0;
|
|
709
|
+
}))).filter((org) => Boolean(org))
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
const actionGrant = defineGrant("vitehub.auth.console.action", (action) => action);
|
|
713
|
+
async function authorize(input, request) {
|
|
714
|
+
const description = await describe(request);
|
|
715
|
+
if (!description.actions[input.action]?.enabled) throw new AuthConsoleError(403, description.actions[input.action]?.reason ?? "Action not supported.");
|
|
716
|
+
if (input.action === "editField") {
|
|
717
|
+
const field = description.fields.find((field) => field.key === input.field);
|
|
718
|
+
if (!field?.edit.enabled || field.computed) throw new AuthConsoleError(403, field?.edit.reason ?? "Field not editable.");
|
|
719
|
+
if (input.value === null ? field.required : valueFor(input.value, field) === null) throw new AuthConsoleError(400, "The value does not match the declared field type.");
|
|
720
|
+
if (field.values && input.value !== null && !field.values.includes(String(input.value))) throw new AuthConsoleError(400, "Choose one of the declared field values.");
|
|
721
|
+
}
|
|
722
|
+
return actionGrant.issue(input.action);
|
|
723
|
+
}
|
|
724
|
+
async function mutate(input, request, grant) {
|
|
725
|
+
if (actionGrant.consume(grant) !== input.action) throw new AuthConsoleError(403, "The action grant does not match.");
|
|
726
|
+
let name;
|
|
727
|
+
let body;
|
|
728
|
+
switch (input.action) {
|
|
729
|
+
case "ban":
|
|
730
|
+
if (input.expiresIn !== void 0 && (!Number.isSafeInteger(input.expiresIn) || input.expiresIn <= 0)) throw new AuthConsoleError(400, "Ban expiry must be a positive number of seconds.");
|
|
731
|
+
name = endpoints.ban;
|
|
732
|
+
body = {
|
|
733
|
+
userId: input.userId,
|
|
734
|
+
banReason: input.reason,
|
|
735
|
+
banExpiresIn: input.expiresIn
|
|
736
|
+
};
|
|
737
|
+
break;
|
|
738
|
+
case "editField":
|
|
739
|
+
name = endpoints.editField;
|
|
740
|
+
body = {
|
|
741
|
+
userId: input.userId,
|
|
742
|
+
data: { [input.field]: input.value }
|
|
743
|
+
};
|
|
744
|
+
break;
|
|
745
|
+
case "setRole":
|
|
746
|
+
name = endpoints.setRole;
|
|
747
|
+
body = {
|
|
748
|
+
userId: input.userId,
|
|
749
|
+
role: input.role
|
|
750
|
+
};
|
|
751
|
+
break;
|
|
752
|
+
case "revokeSession": {
|
|
753
|
+
const session = await find("session", equality("id", input.id));
|
|
754
|
+
if (!session) throw new AuthConsoleError(404, "Session not found.");
|
|
755
|
+
name = endpoints.revokeSession;
|
|
756
|
+
body = { sessionToken: string(session.token) };
|
|
757
|
+
break;
|
|
758
|
+
}
|
|
759
|
+
case "revokeConsent": throw new AuthConsoleError(409, "Better Auth has no admin API to revoke this grant.");
|
|
760
|
+
default:
|
|
761
|
+
name = endpoints[input.action];
|
|
762
|
+
body = { userId: input.userId };
|
|
763
|
+
}
|
|
764
|
+
const session = record(await endpoint("getSession")({
|
|
765
|
+
headers: request.headers,
|
|
766
|
+
query: { disableCookieCache: true }
|
|
767
|
+
}));
|
|
768
|
+
const actorId = string(record(session.user).id);
|
|
769
|
+
if (!actorId) throw new AuthConsoleError(401, "Sign in with an app session to run this action.");
|
|
770
|
+
const result = await call(name, request, body, true);
|
|
771
|
+
if (!(result instanceof Response)) throw new AuthConsoleError(502, "Better Auth returned an invalid action response.");
|
|
772
|
+
if (!result.ok) {
|
|
773
|
+
const failure = record(await result.json().catch(() => ({})));
|
|
774
|
+
throw new AuthConsoleError(result.status, string(failure.message) || "Better Auth rejected the action.");
|
|
775
|
+
}
|
|
776
|
+
const headers = new Headers({ "cache-control": "no-store" });
|
|
777
|
+
if (input.action === "impersonate") for (const cookie of result.headers.getSetCookie()) headers.append("set-cookie", cookie);
|
|
778
|
+
return Response.json({
|
|
779
|
+
action: input.action,
|
|
780
|
+
actor: `user:${actorId}`,
|
|
781
|
+
target: "id" in input ? input.id : input.userId,
|
|
782
|
+
ok: true
|
|
783
|
+
}, { headers });
|
|
784
|
+
}
|
|
785
|
+
async function stopImpersonating(request) {
|
|
786
|
+
if (!host.impersonation) throw new AuthConsoleError(403, "Impersonation is off in the Console configuration.");
|
|
787
|
+
const response = await call("stopImpersonating", request, void 0, true);
|
|
788
|
+
if (!(response instanceof Response)) throw new AuthConsoleError(502, "Better Auth returned an invalid action response.");
|
|
789
|
+
if (!response.ok) {
|
|
790
|
+
const failure = record(await response.json().catch(() => ({})));
|
|
791
|
+
throw new AuthConsoleError(response.status, string(failure.message) || "Better Auth could not stop the impersonation.");
|
|
792
|
+
}
|
|
793
|
+
const headers = new Headers({ "cache-control": "no-store" });
|
|
794
|
+
for (const cookie of response.headers.getSetCookie()) headers.append("set-cookie", cookie);
|
|
795
|
+
return Response.json({
|
|
796
|
+
action: "stopImpersonating",
|
|
797
|
+
ok: true
|
|
798
|
+
}, { headers });
|
|
799
|
+
}
|
|
800
|
+
return {
|
|
801
|
+
describe: (request) => result(() => describe(request)),
|
|
802
|
+
overview: () => result(overview),
|
|
803
|
+
activity: (query) => result(() => activity(query)),
|
|
804
|
+
users: (query) => result(() => users(query)),
|
|
805
|
+
user: (id, request) => result(() => user(id, request)),
|
|
806
|
+
sessions: (query) => result(() => sessions(query)),
|
|
807
|
+
organizations: (query) => result(() => organizations(query)),
|
|
808
|
+
organization: (id, query) => result(() => organization(id, query)),
|
|
809
|
+
agents: (query) => result(() => agents(query)),
|
|
810
|
+
execute: (input, request) => result(async () => await mutate(input, request, await authorize(input, request))),
|
|
811
|
+
stopImpersonating: (request) => result(() => stopImpersonating(request))
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
/** A short device label. The full user agent is never returned to the browser. */
|
|
815
|
+
function authConsoleDevice(userAgent) {
|
|
816
|
+
return `${/Edg\//.test(userAgent) ? "Edge" : /Firefox\//.test(userAgent) ? "Firefox" : /Chrome\//.test(userAgent) ? "Chrome" : /Safari\//.test(userAgent) ? "Safari" : "Unknown browser"} · ${/iPhone|iPad/.test(userAgent) ? "iOS" : /Android/.test(userAgent) ? "Android" : /Windows/.test(userAgent) ? "Windows" : /Macintosh/.test(userAgent) ? "macOS" : /Linux/.test(userAgent) ? "Linux" : "Unknown device"}`;
|
|
817
|
+
}
|
|
818
|
+
//#endregion
|
|
819
|
+
export { authConsoleDevice, createAuthConsole, describeAuthConsoleFields };
|