@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.
Files changed (50) hide show
  1. package/README.md +140 -13
  2. package/dist/agent.d.ts +24 -13
  3. package/dist/agent.js +19 -5
  4. package/dist/application-path-C290OAIs.js +18 -0
  5. package/dist/cli-mgXvsBtA.d.ts +85 -0
  6. package/dist/cli.d.ts +7 -0
  7. package/dist/cli.js +68 -0
  8. package/dist/console-B7eERmGv.d.ts +180 -0
  9. package/dist/console-runtime-bZQtnX2Y.d.ts +39 -0
  10. package/dist/console-runtime.d.ts +3 -0
  11. package/dist/console-runtime.js +819 -0
  12. package/dist/console-types-CmmnKGMx.js +38 -0
  13. package/dist/console.d.ts +7 -0
  14. package/dist/console.js +15 -0
  15. package/dist/error-diagnostics-CL0yjHiM.js +79 -0
  16. package/dist/events-BkmK2dFY.d.ts +486 -0
  17. package/dist/events-P7mI4IQb.js +196 -0
  18. package/dist/events-config-CjcFOhTE.js +177 -0
  19. package/dist/host-declarations.d.ts +4 -0
  20. package/dist/index.d.ts +5 -5
  21. package/dist/index.js +36 -29
  22. package/dist/inspect-DPtsW8dB.d.ts +36 -0
  23. package/dist/nuxt.d.ts +27 -6
  24. package/dist/nuxt.js +35 -3
  25. package/dist/presets-BGZi6Dfu.d.ts +25 -0
  26. package/dist/presets.d.ts +2 -0
  27. package/dist/presets.js +32 -0
  28. package/dist/runtime/console.d.ts +7 -0
  29. package/dist/runtime/console.js +42 -0
  30. package/dist/runtime/empty-definition.d.ts +1 -2
  31. package/dist/runtime/nuxt.d.ts +2 -3
  32. package/dist/runtime/nuxt.js +2 -1
  33. package/dist/runtime/vue-nuxt.d.ts +3 -0
  34. package/dist/runtime/vue-nuxt.js +8 -0
  35. package/dist/server-B7LU19dS.js +1730 -0
  36. package/dist/server-CTD_JAww.d.ts +77 -0
  37. package/dist/server.d.ts +2 -22
  38. package/dist/server.js +3 -2
  39. package/dist/set-cookie-2as_DbHe.js +75 -0
  40. package/dist/shared-DnpgYiLF.js +15 -0
  41. package/dist/vite-COWkwxsj.js +990 -0
  42. package/dist/vite.d.ts +21 -12
  43. package/dist/vite.js +2 -2
  44. package/dist/vue.d.ts +28 -11
  45. package/dist/vue.js +82 -4
  46. package/package.json +84 -24
  47. package/dist/server-BZn8iQrB.js +0 -370
  48. package/dist/shared-QSYBHaMG.js +0 -12
  49. package/dist/types-jaRlW3D1.d.ts +0 -117
  50. package/dist/vite-Cmey8ODS.js +0 -1018
@@ -1,370 +0,0 @@
1
- import { n as normalizeAuthBasePath } from "./shared-QSYBHaMG.js";
2
- import discoveredDefinition from "#vitehub/auth/definition";
3
- import { betterAuth } from "better-auth";
4
- import { ViteHubError, isViteHubError } from "@vite-hub/runtime";
5
- //#region src/errors.ts
6
- function invalidAuthenticationErrorOptions() {
7
- throw new TypeError("[vitehub] Invalid authentication error options.");
8
- }
9
- function readAuthenticationErrorOption(value, key) {
10
- if (typeof value !== "object" || value === null) invalidAuthenticationErrorOptions();
11
- try {
12
- if (Array.isArray(value)) invalidAuthenticationErrorOptions();
13
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
14
- if (descriptor === void 0) return void 0;
15
- if (!("value" in descriptor)) invalidAuthenticationErrorOptions();
16
- return descriptor.value;
17
- } catch {
18
- invalidAuthenticationErrorOptions();
19
- }
20
- }
21
- function createAuthenticationProviderError(options) {
22
- const cause = readAuthenticationErrorOption(options, "cause");
23
- const operation = readAuthenticationErrorOption(options, "operation");
24
- if (operation !== "get-auth-for-request" && operation !== "get-session") invalidAuthenticationErrorOptions();
25
- return new ViteHubError("AUTH_PROVIDER_OPERATION_FAILED", "[vitehub] Authentication provider operation failed.", {
26
- cause,
27
- details: {
28
- operation,
29
- provider: "better-auth"
30
- }
31
- });
32
- }
33
- function throwAuthenticationProviderError(cause, operation) {
34
- if (isViteHubError(cause) || isAuthenticationAbortError(cause)) throw cause;
35
- throw createAuthenticationProviderError({
36
- cause,
37
- operation
38
- });
39
- }
40
- function isAuthenticationAbortError(error) {
41
- if (typeof error !== "object" || error === null) return false;
42
- try {
43
- return Reflect.get(error, "name") === "AbortError";
44
- } catch {
45
- return false;
46
- }
47
- }
48
- //#endregion
49
- //#region src/session.ts
50
- async function getAuthenticationSession(auth, input) {
51
- const [api, getSession] = await readProvider(() => {
52
- const api = readRecordProperty(auth, "api");
53
- return [api, api && readProperty(api, "getSession")];
54
- });
55
- if (typeof getSession !== "function") throw new TypeError("Better Auth did not expose api.getSession().");
56
- const value = await readProvider(() => Reflect.apply(getSession, api, [input]));
57
- if (value == null) return value;
58
- const session = await readProvider(() => resolveAuthenticationSession(value));
59
- if (!session) throw new TypeError("Better Auth returned an invalid session response.");
60
- return session;
61
- }
62
- async function readProvider(read) {
63
- try {
64
- return await read();
65
- } catch (cause) {
66
- throwAuthenticationProviderError(cause, "get-session");
67
- }
68
- }
69
- function readRecordProperty(value, property) {
70
- if (!isRecord(value)) return;
71
- const nested = readProperty(value, property);
72
- return isRecord(nested) ? nested : void 0;
73
- }
74
- function resolveAuthenticationSession(value) {
75
- if (!isRecord(value)) return;
76
- const session = value.session;
77
- const user = value.user;
78
- if (!isRecord(session) || !isRecord(user)) return;
79
- const userId = user.id;
80
- if (typeof userId !== "string" || userId.length === 0) return;
81
- return {
82
- auth: value,
83
- session,
84
- user,
85
- userId
86
- };
87
- }
88
- function readProperty(value, property) {
89
- return value[property];
90
- }
91
- function isRecord(value) {
92
- return typeof value === "object" && value !== null && !Array.isArray(value);
93
- }
94
- //#endregion
95
- //#region src/server.ts
96
- function hasRuntimeOptions(options) {
97
- return Boolean(options && Object.keys(options).length > 0);
98
- }
99
- function hasRequestRuntimeOptions(definition) {
100
- if (typeof definition.options === "function") return true;
101
- return typeof definition.options.runtime === "function";
102
- }
103
- let authRuntimeEnvResolver;
104
- function setAuthRuntimeEnvResolver(resolver) {
105
- authRuntimeEnvResolver = resolver;
106
- }
107
- function resolveAuthRuntimeEnv(event) {
108
- return authRuntimeEnvResolver?.(event) ?? {};
109
- }
110
- function requestOrigin(request) {
111
- return request ? new URL(request.url).origin : "http://localhost";
112
- }
113
- function createAuthRuntimeContext(request, event) {
114
- return {
115
- env: resolveAuthRuntimeEnv(event ?? request),
116
- ...request ? { request } : {},
117
- requestOrigin: requestOrigin(request)
118
- };
119
- }
120
- function isPlainObject(value) {
121
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
122
- }
123
- function isAuthDatabaseMetadata(value) {
124
- return value === true || isPlainObject(value) && typeof value.name === "string" && Object.keys(value).every((key) => key === "dedicated" || key === "name");
125
- }
126
- function isAuthSecondaryStorageMetadata(value) {
127
- return value === true || isPlainObject(value) && typeof value.store === "string" && Object.keys(value).every((key) => key === "store");
128
- }
129
- function resolveDefinitionOptions(definition, request, event, runtimeOptions = {}) {
130
- const context = createAuthRuntimeContext(request, event);
131
- const options = typeof definition.options === "function" ? definition.options(context) : definition.options;
132
- const runtime = options.runtime;
133
- const resolvedRuntime = !runtime ? {} : typeof runtime === "function" ? runtime(context) : runtime;
134
- return {
135
- ...options,
136
- ...resolvedRuntime,
137
- ...runtimeOptions
138
- };
139
- }
140
- function resolveRequestRuntimeOptions(definition, request, event) {
141
- if (typeof definition.options === "function") return resolveDefinitionOptions(definition, request, event);
142
- const runtime = definition.options.runtime;
143
- if (!runtime) return {};
144
- const context = createAuthRuntimeContext(request, event);
145
- return typeof runtime === "function" ? runtime(context) : runtime;
146
- }
147
- function hasStaticTrustedOrigins(definition) {
148
- return typeof definition.options !== "function" && "trustedOrigins" in definition.options;
149
- }
150
- function definitionBasePath(definition) {
151
- if (typeof definition.options === "function") return;
152
- return definition.options.basePath;
153
- }
154
- function stripViteHubOptions(options) {
155
- const { access: _access, database, route: _route, runtime: _runtime, secondaryStorage, ...rest } = options;
156
- return {
157
- ...rest,
158
- ...!isAuthDatabaseMetadata(database) ? { database } : {},
159
- ...!isAuthSecondaryStorageMetadata(secondaryStorage) ? { secondaryStorage } : {},
160
- basePath: normalizeAuthBasePath(typeof options.basePath === "string" ? options.basePath : void 0)
161
- };
162
- }
163
- function hasTrustedOrigins(options) {
164
- return "trustedOrigins" in options;
165
- }
166
- function toRequest(request) {
167
- if (request instanceof Request) return request;
168
- const init = {
169
- headers: request.headers,
170
- method: request.method,
171
- signal: request.signal
172
- };
173
- if (request.body) {
174
- init.body = request.body;
175
- init.duplex = "half";
176
- }
177
- return new Request(request.url, init);
178
- }
179
- function unwrapAuthRequest(input) {
180
- return "req" in input ? input.req : input;
181
- }
182
- function createAuthRequestRuntimeOptions(definition, request, runtimeOptions = {}, event) {
183
- const requestRuntimeOptions = {
184
- ...resolveRequestRuntimeOptions(definition, request, event),
185
- ...runtimeOptions
186
- };
187
- const baseURL = requestRuntimeOptions.baseURL || new URL(request.url).origin;
188
- return {
189
- baseURL,
190
- ...!hasTrustedOrigins(requestRuntimeOptions) && !hasStaticTrustedOrigins(definition) ? { trustedOrigins: [baseURL] } : {},
191
- ...requestRuntimeOptions
192
- };
193
- }
194
- const authRuntimeStateKey = Symbol.for("vitehub.auth.runtime");
195
- function getAuthRuntimeState() {
196
- const globalScope = globalThis;
197
- globalScope[authRuntimeStateKey] ??= {};
198
- return globalScope[authRuntimeStateKey];
199
- }
200
- function resolveDefaultDefinition() {
201
- if (!discoveredDefinition) throw new Error("[vitehub] No Auth Definition was discovered. Add `server/auth.ts` or `server.auth.ts`.");
202
- return discoveredDefinition;
203
- }
204
- function createBetterAuthOptions(definition, runtimeOptions = {}) {
205
- return stripViteHubOptions(resolveDefinitionOptions(definition, void 0, void 0, runtimeOptions));
206
- }
207
- function createBetterAuthOptionsFromResolved(options) {
208
- return stripViteHubOptions(options);
209
- }
210
- function createAuthenticationProvider(options) {
211
- try {
212
- return betterAuth(options);
213
- } catch (cause) {
214
- throwAuthenticationProviderError(cause, "get-auth-for-request");
215
- }
216
- }
217
- function resolveBetterAuthOptionsForRequest(definition, request, runtimeOptions, event) {
218
- return createBetterAuthOptionsFromResolved(resolveDefinitionOptions(definition, request, event, createAuthRequestRuntimeOptions(definition, request, runtimeOptions, event)));
219
- }
220
- function createAuth(definition, runtimeOptions) {
221
- return betterAuth(createBetterAuthOptions(definition, runtimeOptions));
222
- }
223
- function createAuthForRequest(definition, request, runtimeOptions, event) {
224
- return betterAuth(resolveBetterAuthOptionsForRequest(definition, request, runtimeOptions, event));
225
- }
226
- function handleAuthRequest(definition, request, runtimeOptions, event) {
227
- return createAuthForRequest(definition, request, runtimeOptions, event).handler(toRequest(request));
228
- }
229
- function createAuthHandler(definition, runtimeOptions) {
230
- return createAuth(definition, runtimeOptions).handler;
231
- }
232
- function resetAuth() {
233
- const state = getAuthRuntimeState();
234
- state.auth = void 0;
235
- state.definition = void 0;
236
- }
237
- function getAuthForDefinition(definition, runtimeOptions) {
238
- if (hasRuntimeOptions(runtimeOptions)) return createAuthenticationProvider(createBetterAuthOptions(definition, runtimeOptions));
239
- const state = getAuthRuntimeState();
240
- if (!state.auth || state.definition !== definition) {
241
- state.auth = createAuthenticationProvider(createBetterAuthOptions(definition));
242
- state.definition = definition;
243
- }
244
- return state.auth;
245
- }
246
- function getAuth(runtimeOptions) {
247
- return getAuthForDefinition(resolveDefaultDefinition(), runtimeOptions);
248
- }
249
- function getAuthForRequest(request, runtimeOptions, event) {
250
- const definition = resolveDefaultDefinition();
251
- if (!hasRequestRuntimeOptions(definition) && !hasRuntimeOptions(runtimeOptions)) return getAuthForDefinition(definition);
252
- return createAuthenticationProvider(resolveBetterAuthOptionsForRequest(definition, request, runtimeOptions, event));
253
- }
254
- async function assertAuthOrigin(request, event) {
255
- const origin = request.headers.get("origin");
256
- if (!origin) throw new TypeError("The request origin is required.");
257
- const auth = getAuthForRequest(request, void 0, event);
258
- if (!(await auth.$context).isTrustedOrigin(origin)) throw new TypeError("The request origin is not trusted.");
259
- return auth;
260
- }
261
- function handleAuth(input, runtimeOptions) {
262
- const request = unwrapAuthRequest(input);
263
- return handleAuthRequest(resolveDefaultDefinition(), request, runtimeOptions, input);
264
- }
265
- function authRequestBasePath(definition, request, event) {
266
- const options = createAuthRequestRuntimeOptions(definition, request, {}, event);
267
- return normalizeAuthBasePath(typeof options.basePath === "string" ? options.basePath : definitionBasePath(definition));
268
- }
269
- function authBaseURL(definition, request, event) {
270
- return new URL(createAuthRequestRuntimeOptions(definition, request, {}, event).baseURL).origin;
271
- }
272
- function wantsHtml(request) {
273
- return request.method === "GET" && request.headers.get("accept")?.includes("text/html") === true;
274
- }
275
- function createForbiddenResponse(request) {
276
- return wantsHtml(request) ? new Response("Forbidden.", {
277
- headers: { "content-type": "text/plain; charset=utf-8" },
278
- status: 403
279
- }) : Response.json({ error: "Forbidden." }, { status: 403 });
280
- }
281
- function authAccessRoutes(definition, request, event, routeIndexes) {
282
- const routes = resolveDefinitionOptions(definition, request, event).access?.routes;
283
- return routeIndexes.map((routeIndex) => {
284
- const route = routes?.[routeIndex];
285
- if (!route) throw new TypeError(`[vitehub] Auth access route ${routeIndex} is unavailable at runtime.`);
286
- return route;
287
- });
288
- }
289
- async function createSignInResponse(definition, request, signIn, event) {
290
- const origin = authBaseURL(definition, request, event);
291
- const response = await handleAuthRequest(definition, new Request(`${origin}${authRequestBasePath(definition, request, event)}/sign-in/social`, {
292
- body: JSON.stringify({
293
- callbackURL: signIn.callbackURL,
294
- errorCallbackURL: signIn.errorCallbackURL,
295
- provider: signIn.provider,
296
- requestSignUp: signIn.requestSignUp,
297
- scopes: signIn.scopes
298
- }),
299
- headers: {
300
- "content-type": "application/json",
301
- "accept": "application/json",
302
- "origin": origin
303
- },
304
- method: "POST"
305
- }), void 0, event);
306
- if (!response.ok) return response;
307
- const body = await response.json().catch(() => void 0);
308
- if (typeof body?.url !== "string") return Response.json({ error: "Auth sign-in did not return a redirect URL." }, { status: 502 });
309
- const headers = new Headers(response.headers);
310
- headers.delete("content-type");
311
- headers.set("location", body.url);
312
- return new Response(null, {
313
- headers,
314
- status: 302
315
- });
316
- }
317
- async function requireAuthRequest(input, definition, routeIndexes, requiredAuthorizeRouteIndexes = []) {
318
- const request = unwrapAuthRequest(input);
319
- const session = await getAuthenticationSession(createAuthenticationProvider(resolveBetterAuthOptionsForRequest(definition, request, void 0, input)), { headers: request.headers });
320
- if (session) {
321
- if (routeIndexes === void 0) return;
322
- const context = {
323
- request,
324
- session: session.session,
325
- user: session.user
326
- };
327
- const requiredAuthorizeRoutes = new Set(requiredAuthorizeRouteIndexes);
328
- const routes = authAccessRoutes(definition, request, input, routeIndexes);
329
- for (const [index, route] of routes.entries()) {
330
- const authorize = route instanceof Object ? route.authorize : void 0;
331
- if (!authorize && requiredAuthorizeRoutes.has(routeIndexes[index])) return createForbiddenResponse(request);
332
- if (!authorize) continue;
333
- const result = await authorize(context);
334
- if (result instanceof Response) return result;
335
- if (result !== true) return createForbiddenResponse(request);
336
- }
337
- return;
338
- }
339
- if (!wantsHtml(request)) return Response.json({ error: "Unauthorized." }, { status: 401 });
340
- if (new URL(request.url).searchParams.has("auth_error")) return new Response("Unauthorized.", {
341
- headers: { "content-type": "text/plain; charset=utf-8" },
342
- status: 403
343
- });
344
- const signIn = resolveDefinitionOptions(definition, request, input).access?.signIn;
345
- return signIn ? await createSignInResponse(definition, request, signIn, input) : Response.json({ error: "Unauthorized." }, { status: 401 });
346
- }
347
- async function requireAuth(input, definition = resolveDefaultDefinition()) {
348
- return requireAuthRequest(input, definition);
349
- }
350
- async function requireAuthAccessRoutes(input, routeIndexes, definition = resolveDefaultDefinition(), requiredAuthorizeRouteIndexes = []) {
351
- if (!Array.isArray(routeIndexes) || routeIndexes.length === 0 || routeIndexes.some((routeIndex) => !Number.isSafeInteger(routeIndex) || routeIndex < 0)) throw new TypeError("[vitehub] Auth access route indexes must be a non-empty array of non-negative integers.");
352
- if (!Array.isArray(requiredAuthorizeRouteIndexes) || requiredAuthorizeRouteIndexes.some((routeIndex) => !Number.isSafeInteger(routeIndex) || routeIndex < 0)) throw new TypeError("[vitehub] Required Auth authorize route indexes must be an array of non-negative integers.");
353
- return requireAuthRequest(input, definition, routeIndexes, requiredAuthorizeRouteIndexes);
354
- }
355
- const auth = new Proxy({}, {
356
- get(_target, property, receiver) {
357
- return Reflect.get(getAuth(), property, receiver);
358
- },
359
- getOwnPropertyDescriptor(_target, property) {
360
- return Reflect.getOwnPropertyDescriptor(getAuth(), property);
361
- },
362
- has(_target, property) {
363
- return Reflect.has(getAuth(), property);
364
- },
365
- ownKeys() {
366
- return Reflect.ownKeys(getAuth());
367
- }
368
- });
369
- //#endregion
370
- export { getAuthenticationSession as _, createAuthHandler as a, getAuth as c, handleAuth as d, handleAuthRequest as f, setAuthRuntimeEnvResolver as g, resetAuth as h, createAuthForRequest as i, getAuthForDefinition as l, requireAuthAccessRoutes as m, auth as n, createAuthRequestRuntimeOptions as o, requireAuth as p, createAuth as r, createBetterAuthOptions as s, assertAuthOrigin as t, getAuthForRequest as u, invalidAuthenticationErrorOptions as v, throwAuthenticationProviderError as y };
@@ -1,12 +0,0 @@
1
- //#region src/shared.ts
2
- const defaultAuthBasePath = "/api/auth";
3
- function normalizeAuthBasePath(value) {
4
- const path = value?.trim() || defaultAuthBasePath;
5
- if (!path.startsWith("/")) throw new TypeError("`defineAuth()` basePath must start with `/`.");
6
- return path.length > 1 ? path.replace(/\/+$/g, "") : path;
7
- }
8
- function isAuthRequestPath(pathname, basePath) {
9
- return pathname === basePath || pathname.startsWith(`${basePath}/`);
10
- }
11
- //#endregion
12
- export { normalizeAuthBasePath as n, isAuthRequestPath as t };
@@ -1,117 +0,0 @@
1
- import { Auth, BetterAuthOptions } from "better-auth";
2
-
3
- //#region src/types.d.ts
4
- declare global {
5
- namespace ViteHub {
6
- interface AuthRuntimeEnv extends Record<string, unknown> {}
7
- }
8
- }
9
- type AuthRuntimeOption = "baseURL" | "secret" | "secrets";
10
- type AuthReservedOption = AuthRuntimeOption | "access" | "basePath" | "database" | "route" | "runtime" | "secondaryStorage";
11
- type AuthBetterAuthOptions = Omit<BetterAuthOptions, AuthReservedOption>;
12
- interface AuthRuntimeEnv extends ViteHub.AuthRuntimeEnv {}
13
- interface AuthRuntimeContext<TEnv extends Record<string, unknown> = AuthRuntimeEnv> {
14
- env: TEnv;
15
- request?: Pick<Request, "headers" | "url">;
16
- requestOrigin: string;
17
- }
18
- type AuthRuntimeOptions = Partial<Omit<BetterAuthOptions, "basePath">>;
19
- type AuthRuntimeOptionsResolver = (context: AuthRuntimeContext) => AuthRuntimeOptions;
20
- type AuthRuntimeConfiguration = AuthRuntimeOptions | AuthRuntimeOptionsResolver;
21
- interface AuthSignInConfiguration {
22
- callbackURL?: string;
23
- errorCallbackURL?: string;
24
- provider: string;
25
- requestSignUp?: boolean;
26
- scopes?: string[];
27
- }
28
- interface AuthAccessRouteConfiguration {
29
- authorize?: AuthAccessAuthorize;
30
- method?: string;
31
- route: string;
32
- }
33
- type AuthAccessRoute = string | AuthAccessRouteConfiguration;
34
- interface AuthAccessAuthorizationContext {
35
- request: AuthRequest;
36
- session: Record<string, unknown>;
37
- user: Record<string, unknown> & {
38
- id: string;
39
- };
40
- }
41
- type AuthAccessAuthorizeResult = boolean | Response;
42
- type AuthAccessAuthorize = (context: AuthAccessAuthorizationContext) => AuthAccessAuthorizeResult | Promise<AuthAccessAuthorizeResult>;
43
- interface AuthAccessConfiguration {
44
- routes?: AuthAccessRoute[];
45
- signIn?: AuthSignInConfiguration;
46
- }
47
- interface AuthDatabaseReference {
48
- dedicated?: boolean;
49
- name: string;
50
- }
51
- type AuthDatabaseConfiguration = true | AuthDatabaseReference;
52
- interface AuthSecondaryStorageReference {
53
- store: string;
54
- }
55
- type AuthSecondaryStorageConfiguration = true | AuthSecondaryStorageReference;
56
- interface AuthViteHubOptions {
57
- access?: AuthAccessConfiguration;
58
- basePath?: string;
59
- database?: AuthDatabaseConfiguration;
60
- route?: false;
61
- runtime?: AuthRuntimeConfiguration;
62
- secondaryStorage?: AuthSecondaryStorageConfiguration;
63
- }
64
- type AuthRuntimeOnlyOptions = { [Key in AuthRuntimeOption]?: never };
65
- type AuthDefinitionOptions<TOptions extends AuthBetterAuthOptions = AuthBetterAuthOptions> = TOptions & AuthViteHubOptions & AuthRuntimeOnlyOptions;
66
- type AuthResolvedDefinitionOptions<TOptions extends AuthBetterAuthOptions = AuthBetterAuthOptions> = TOptions & Omit<AuthViteHubOptions, "database" | "runtime" | "secondaryStorage"> & Omit<AuthRuntimeOptions, "database" | "secondaryStorage"> & {
67
- database?: AuthDatabaseConfiguration | BetterAuthOptions["database"];
68
- secondaryStorage?: AuthSecondaryStorageConfiguration | BetterAuthOptions["secondaryStorage"];
69
- };
70
- type AuthDefinitionResolver<TOptions extends AuthResolvedDefinitionOptions = AuthResolvedDefinitionOptions> = (context: AuthRuntimeContext) => TOptions;
71
- type AuthDefinitionInput = AuthDefinitionOptions | AuthDefinitionResolver;
72
- interface AuthDefinition<TOptions extends AuthDefinitionInput = AuthDefinitionInput> {
73
- options: TOptions;
74
- }
75
- interface DiscoveredAuthDefinition {
76
- handler: string;
77
- name: "default";
78
- source: "server-auth" | "server-auth-suffix";
79
- }
80
- type ResolvedAuthDatabaseConfiguration = {
81
- mode: "default";
82
- } | {
83
- dedicated: boolean;
84
- mode: "named";
85
- name: string;
86
- };
87
- type ResolvedAuthSecondaryStorageConfiguration = {
88
- mode: "default";
89
- } | {
90
- mode: "named";
91
- store: string;
92
- };
93
- interface ResolvedAuthAccessRoute {
94
- authorize?: true;
95
- method?: string;
96
- route: string;
97
- }
98
- interface ResolvedAuthViteConfig {
99
- access: {
100
- routes: ResolvedAuthAccessRoute[];
101
- };
102
- basePath: string;
103
- database: ResolvedAuthDatabaseConfiguration;
104
- definition: DiscoveredAuthDefinition;
105
- rootDir: string;
106
- route: false | string;
107
- secondaryStorage: false | ResolvedAuthSecondaryStorageConfiguration;
108
- }
109
- type AuthBetterAuthRuntimeOptions<TOptions extends AuthDefinitionInput = AuthDefinitionInput> = (TOptions extends AuthDefinitionResolver<infer TResolved> ? Omit<TResolved, AuthRuntimeOption | "access" | "database" | "route" | "runtime" | "secondaryStorage"> : Omit<TOptions, AuthRuntimeOption | "access" | "database" | "route" | "runtime" | "secondaryStorage">) & AuthRuntimeOptions & BetterAuthOptions;
110
- type AuthRequest = Pick<Request, "body" | "headers" | "method" | "signal" | "url">;
111
- type AuthRequestInput = AuthRequest | {
112
- req: AuthRequest;
113
- };
114
- type ViteHubAuth<Options extends BetterAuthOptions = BetterAuthOptions> = Auth<Options>;
115
- type AuthModuleOptions = false | Record<string, never>;
116
- //#endregion
117
- export { AuthViteHubOptions as A, AuthRuntimeOnlyOptions as C, AuthSecondaryStorageConfiguration as D, AuthRuntimeOptionsResolver as E, ViteHubAuth as F, ResolvedAuthDatabaseConfiguration as M, ResolvedAuthSecondaryStorageConfiguration as N, AuthSecondaryStorageReference as O, ResolvedAuthViteConfig as P, AuthRuntimeEnv as S, AuthRuntimeOptions as T, AuthRequestInput as _, AuthAccessRoute as a, AuthRuntimeConfiguration as b, AuthBetterAuthRuntimeOptions as c, AuthDefinition as d, AuthDefinitionInput as f, AuthRequest as g, AuthModuleOptions as h, AuthAccessConfiguration as i, DiscoveredAuthDefinition as j, AuthSignInConfiguration as k, AuthDatabaseConfiguration as l, AuthDefinitionResolver as m, AuthAccessAuthorize as n, AuthAccessRouteConfiguration as o, AuthDefinitionOptions as p, AuthAccessAuthorizeResult as r, AuthBetterAuthOptions as s, AuthAccessAuthorizationContext as t, AuthDatabaseReference as u, AuthReservedOption as v, AuthRuntimeOption as w, AuthRuntimeContext as x, AuthResolvedDefinitionOptions as y };