@vite-hub/auth 0.0.2

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.
@@ -0,0 +1,322 @@
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
+ function handleAuth(input, runtimeOptions) {
255
+ const request = unwrapAuthRequest(input);
256
+ return handleAuthRequest(resolveDefaultDefinition(), request, runtimeOptions, input);
257
+ }
258
+ function authRequestBasePath(definition, request, event) {
259
+ const options = createAuthRequestRuntimeOptions(definition, request, {}, event);
260
+ return normalizeAuthBasePath(typeof options.basePath === "string" ? options.basePath : definitionBasePath(definition));
261
+ }
262
+ function authBaseURL(definition, request, event) {
263
+ return new URL(createAuthRequestRuntimeOptions(definition, request, {}, event).baseURL).origin;
264
+ }
265
+ function wantsHtml(request) {
266
+ return request.method === "GET" && request.headers.get("accept")?.includes("text/html") === true;
267
+ }
268
+ async function createSignInResponse(definition, request, signIn, event) {
269
+ const origin = authBaseURL(definition, request, event);
270
+ const response = await handleAuthRequest(definition, new Request(`${origin}${authRequestBasePath(definition, request, event)}/sign-in/social`, {
271
+ body: JSON.stringify({
272
+ callbackURL: signIn.callbackURL,
273
+ errorCallbackURL: signIn.errorCallbackURL,
274
+ provider: signIn.provider,
275
+ requestSignUp: signIn.requestSignUp,
276
+ scopes: signIn.scopes
277
+ }),
278
+ headers: {
279
+ "content-type": "application/json",
280
+ "accept": "application/json",
281
+ "origin": origin
282
+ },
283
+ method: "POST"
284
+ }), void 0, event);
285
+ if (!response.ok) return response;
286
+ const body = await response.json().catch(() => void 0);
287
+ if (typeof body?.url !== "string") return Response.json({ error: "Auth sign-in did not return a redirect URL." }, { status: 502 });
288
+ const headers = new Headers(response.headers);
289
+ headers.delete("content-type");
290
+ headers.set("location", body.url);
291
+ return new Response(null, {
292
+ headers,
293
+ status: 302
294
+ });
295
+ }
296
+ async function requireAuth(input, definition = resolveDefaultDefinition()) {
297
+ const request = unwrapAuthRequest(input);
298
+ if (await getAuthenticationSession(createAuthenticationProvider(resolveBetterAuthOptionsForRequest(definition, request, void 0, input)), { headers: request.headers })) return;
299
+ if (!wantsHtml(request)) return Response.json({ error: "Unauthorized." }, { status: 401 });
300
+ if (new URL(request.url).searchParams.has("auth_error")) return new Response("Unauthorized.", {
301
+ headers: { "content-type": "text/plain; charset=utf-8" },
302
+ status: 403
303
+ });
304
+ const signIn = resolveDefinitionOptions(definition, request, input).access?.signIn;
305
+ return signIn ? await createSignInResponse(definition, request, signIn, input) : Response.json({ error: "Unauthorized." }, { status: 401 });
306
+ }
307
+ const auth = new Proxy({}, {
308
+ get(_target, property, receiver) {
309
+ return Reflect.get(getAuth(), property, receiver);
310
+ },
311
+ getOwnPropertyDescriptor(_target, property) {
312
+ return Reflect.getOwnPropertyDescriptor(getAuth(), property);
313
+ },
314
+ has(_target, property) {
315
+ return Reflect.has(getAuth(), property);
316
+ },
317
+ ownKeys() {
318
+ return Reflect.ownKeys(getAuth());
319
+ }
320
+ });
321
+ //#endregion
322
+ export { throwAuthenticationProviderError as _, createAuthRequestRuntimeOptions as a, getAuthForDefinition as c, handleAuthRequest as d, requireAuth as f, invalidAuthenticationErrorOptions as g, getAuthenticationSession as h, createAuthHandler as i, getAuthForRequest as l, setAuthRuntimeEnvResolver as m, createAuth as n, createBetterAuthOptions as o, resetAuth as p, createAuthForRequest as r, getAuth as s, auth as t, handleAuth as u };
@@ -0,0 +1,20 @@
1
+ import { M as ViteHubAuth, S as AuthRuntimeOptions, a as AuthBetterAuthRuntimeOptions, c as AuthDefinition, m as AuthRequestInput, p as AuthRequest } from "./types-B0fg9XFd.js";
2
+
3
+ //#region src/server.d.ts
4
+ type AuthRuntimeEnvResolver = (event?: unknown) => Record<string, unknown>;
5
+ declare function setAuthRuntimeEnvResolver(resolver: AuthRuntimeEnvResolver | undefined): void;
6
+ declare function createAuthRequestRuntimeOptions(definition: AuthDefinition, request: Pick<Request, "headers" | "url">, runtimeOptions?: AuthRuntimeOptions, event?: unknown): AuthRuntimeOptions;
7
+ declare function createBetterAuthOptions(definition: AuthDefinition, runtimeOptions?: AuthRuntimeOptions): AuthBetterAuthRuntimeOptions;
8
+ declare function createAuth(definition: AuthDefinition, runtimeOptions?: AuthRuntimeOptions): ViteHubAuth;
9
+ declare function createAuthForRequest(definition: AuthDefinition, request: Pick<Request, "headers" | "url">, runtimeOptions?: AuthRuntimeOptions, event?: unknown): ViteHubAuth;
10
+ declare function handleAuthRequest(definition: AuthDefinition, request: AuthRequest, runtimeOptions?: AuthRuntimeOptions, event?: unknown): Promise<Response>;
11
+ declare function createAuthHandler(definition: AuthDefinition, runtimeOptions?: AuthRuntimeOptions): ViteHubAuth["handler"];
12
+ declare function resetAuth(): void;
13
+ declare function getAuthForDefinition(definition: AuthDefinition, runtimeOptions?: AuthRuntimeOptions): ViteHubAuth;
14
+ declare function getAuth(runtimeOptions?: AuthRuntimeOptions): ViteHubAuth;
15
+ declare function getAuthForRequest(request: Pick<Request, "headers" | "url">, runtimeOptions?: AuthRuntimeOptions, event?: unknown): ViteHubAuth;
16
+ declare function handleAuth(input: AuthRequestInput, runtimeOptions?: AuthRuntimeOptions): Promise<Response>;
17
+ declare function requireAuth(input: AuthRequestInput, definition?: AuthDefinition): Promise<Response | undefined>;
18
+ declare const auth: ViteHubAuth;
19
+ //#endregion
20
+ export { auth, createAuth, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, handleAuth as default, handleAuth, getAuth, getAuthForDefinition, getAuthForRequest, handleAuthRequest, requireAuth, resetAuth, setAuthRuntimeEnvResolver };
package/dist/server.js ADDED
@@ -0,0 +1,2 @@
1
+ import { a as createAuthRequestRuntimeOptions, c as getAuthForDefinition, d as handleAuthRequest, f as requireAuth, i as createAuthHandler, l as getAuthForRequest, m as setAuthRuntimeEnvResolver, n as createAuth, o as createBetterAuthOptions, p as resetAuth, r as createAuthForRequest, s as getAuth, t as auth, u as handleAuth } from "./server-Diw3mAbX.js";
2
+ export { auth, createAuth, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, handleAuth as default, handleAuth, getAuth, getAuthForDefinition, getAuthForRequest, handleAuthRequest, requireAuth, resetAuth, setAuthRuntimeEnvResolver };
@@ -0,0 +1,12 @@
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 };
@@ -0,0 +1,106 @@
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
+ method?: string;
30
+ route: string;
31
+ }
32
+ type AuthAccessRoute = string | AuthAccessRouteConfiguration;
33
+ interface AuthAccessConfiguration {
34
+ routes?: AuthAccessRoute[];
35
+ signIn?: AuthSignInConfiguration;
36
+ }
37
+ interface AuthDatabaseReference {
38
+ dedicated?: boolean;
39
+ name: string;
40
+ }
41
+ type AuthDatabaseConfiguration = true | AuthDatabaseReference;
42
+ interface AuthSecondaryStorageReference {
43
+ store: string;
44
+ }
45
+ type AuthSecondaryStorageConfiguration = true | AuthSecondaryStorageReference;
46
+ interface AuthViteHubOptions {
47
+ access?: AuthAccessConfiguration;
48
+ basePath?: string;
49
+ database?: AuthDatabaseConfiguration;
50
+ route?: false;
51
+ runtime?: AuthRuntimeConfiguration;
52
+ secondaryStorage?: AuthSecondaryStorageConfiguration;
53
+ }
54
+ type AuthRuntimeOnlyOptions = { [Key in AuthRuntimeOption]?: never };
55
+ type AuthDefinitionOptions<TOptions extends AuthBetterAuthOptions = AuthBetterAuthOptions> = TOptions & AuthViteHubOptions & AuthRuntimeOnlyOptions;
56
+ type AuthResolvedDefinitionOptions<TOptions extends AuthBetterAuthOptions = AuthBetterAuthOptions> = TOptions & Omit<AuthViteHubOptions, "database" | "runtime" | "secondaryStorage"> & Omit<AuthRuntimeOptions, "database" | "secondaryStorage"> & {
57
+ database?: AuthDatabaseConfiguration | BetterAuthOptions["database"];
58
+ secondaryStorage?: AuthSecondaryStorageConfiguration | BetterAuthOptions["secondaryStorage"];
59
+ };
60
+ type AuthDefinitionResolver<TOptions extends AuthResolvedDefinitionOptions = AuthResolvedDefinitionOptions> = (context: AuthRuntimeContext) => TOptions;
61
+ type AuthDefinitionInput = AuthDefinitionOptions | AuthDefinitionResolver;
62
+ interface AuthDefinition<TOptions extends AuthDefinitionInput = AuthDefinitionInput> {
63
+ options: TOptions;
64
+ }
65
+ interface DiscoveredAuthDefinition {
66
+ handler: string;
67
+ name: "default";
68
+ source: "server-auth" | "server-auth-suffix";
69
+ }
70
+ type ResolvedAuthDatabaseConfiguration = {
71
+ mode: "default";
72
+ } | {
73
+ dedicated: boolean;
74
+ mode: "named";
75
+ name: string;
76
+ };
77
+ type ResolvedAuthSecondaryStorageConfiguration = {
78
+ mode: "default";
79
+ } | {
80
+ mode: "named";
81
+ store: string;
82
+ };
83
+ interface ResolvedAuthAccessRoute {
84
+ method?: string;
85
+ route: string;
86
+ }
87
+ interface ResolvedAuthViteConfig {
88
+ access: {
89
+ routes: ResolvedAuthAccessRoute[];
90
+ };
91
+ basePath: string;
92
+ database: ResolvedAuthDatabaseConfiguration;
93
+ definition: DiscoveredAuthDefinition;
94
+ rootDir: string;
95
+ route: false | string;
96
+ secondaryStorage: false | ResolvedAuthSecondaryStorageConfiguration;
97
+ }
98
+ 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;
99
+ type AuthRequest = Pick<Request, "body" | "headers" | "method" | "signal" | "url">;
100
+ type AuthRequestInput = AuthRequest | {
101
+ req: AuthRequest;
102
+ };
103
+ type ViteHubAuth<Options extends BetterAuthOptions = BetterAuthOptions> = Auth<Options>;
104
+ type AuthModuleOptions = false | Record<string, never>;
105
+ //#endregion
106
+ export { ResolvedAuthSecondaryStorageConfiguration as A, AuthRuntimeOptionsResolver as C, AuthViteHubOptions as D, AuthSignInConfiguration as E, ViteHubAuth as M, DiscoveredAuthDefinition as O, AuthRuntimeOptions as S, AuthSecondaryStorageReference as T, AuthRuntimeConfiguration as _, AuthBetterAuthRuntimeOptions as a, AuthRuntimeOnlyOptions as b, AuthDefinition as c, AuthDefinitionResolver as d, AuthModuleOptions as f, AuthResolvedDefinitionOptions as g, AuthReservedOption as h, AuthBetterAuthOptions as i, ResolvedAuthViteConfig as j, ResolvedAuthDatabaseConfiguration as k, AuthDefinitionInput as l, AuthRequestInput as m, AuthAccessRoute as n, AuthDatabaseConfiguration as o, AuthRequest as p, AuthAccessRouteConfiguration as r, AuthDatabaseReference as s, AuthAccessConfiguration as t, AuthDefinitionOptions as u, AuthRuntimeContext as v, AuthSecondaryStorageConfiguration as w, AuthRuntimeOption as x, AuthRuntimeEnv as y };
package/dist/vite.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { f as AuthModuleOptions, j as ResolvedAuthViteConfig } from "./types-B0fg9XFd.js";
2
+ import { Plugin } from "vite";
3
+
4
+ //#region src/vite.d.ts
5
+ declare const AUTH_DEFINITION_ID = "#vitehub/auth/definition";
6
+ declare const AUTH_SERVER_ID = "#vitehub/auth/server";
7
+ declare const AUTH_VITE_PLUGIN_NAME = "@vite-hub/auth/vite";
8
+ interface AuthVitePluginAPI {
9
+ getConfig: () => ResolvedAuthViteConfig | undefined;
10
+ refresh: () => ResolvedAuthViteConfig | undefined;
11
+ }
12
+ type AuthVitePlugin = Plugin & {
13
+ api: AuthVitePluginAPI;
14
+ };
15
+ declare function hubAuth(options?: AuthModuleOptions): AuthVitePlugin;
16
+ declare module "vite" {
17
+ interface UserConfig {
18
+ auth?: AuthModuleOptions;
19
+ }
20
+ }
21
+ //#endregion
22
+ export { AUTH_DEFINITION_ID, AUTH_SERVER_ID, AUTH_VITE_PLUGIN_NAME, AuthVitePlugin, AuthVitePluginAPI, hubAuth };