@vite-hub/auth 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -5
- package/dist/{abilities-CfvuGrBv.d.ts → abilities-IOwpkcz4.d.ts} +1 -1
- package/dist/abilities.d.ts +1 -1
- package/dist/{ability-error-OKoyOwPM.js → ability-error-DgR91Jwc.js} +1 -1
- package/dist/{access-pages-Bej95blM.js → access-pages-C69nwa99.js} +1 -1
- package/dist/agent.js +11 -11
- package/dist/{auth-instance-5RSiFTDC.js → auth-instance-WeEK1zDd.js} +39 -17
- package/dist/cli.js +1 -1
- package/dist/client-extension-BgUlm6hy.d.ts +33 -0
- package/dist/client-request-B1DCz3a9.js +29 -0
- package/dist/{console-runtime-XcplYv4R.d.ts → console-runtime-C71weVrt.d.ts} +1 -1
- package/dist/{console-runtime-Bg_PAl7e.js → console-runtime-Dk3j4Jmz.js} +2 -2
- package/dist/console-runtime.d.ts +2 -2
- package/dist/console-runtime.js +1 -1
- package/dist/console.d.ts +1 -1
- package/dist/{database-options-DE9lMwu1.js → database-options-Cms7BI3c.js} +12 -4
- package/dist/{database-schema-options-CCQsNhjc.js → database-schema-options-IlHEeUBK.js} +1 -1
- package/dist/database.d.ts +1 -1
- package/dist/database.js +12 -7
- package/dist/{definition-DeEeqTLC.js → definition-EpeI5LUG.js} +3 -3
- package/dist/{error-diagnostics-DkzL9ltR.js → error-diagnostics-DZHuHXPP.js} +33 -1
- package/dist/{events-BUaoHFoC.js → events-Cm7Iwq47.js} +1 -1
- package/dist/extension-BWmjJhoN.d.ts +59 -0
- package/dist/extension-mCx4TrsO.js +133 -0
- package/dist/forward.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/internal/server.d.ts +3 -3
- package/dist/internal/server.js +5 -5
- package/dist/{mcp-config-C7srUMIZ.js → mcp-config-Bbr8kQxm.js} +9 -1
- package/dist/{mcp-token-DgveSGEl.js → mcp-token-BleQZK6H.js} +28 -5
- package/dist/{mcp-token-DG1jmw4o.d.ts → mcp-token-CxpopXmK.d.ts} +4 -2
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +26 -5
- package/dist/{members-CRlYyxVk.js → members-7OMdqha_.js} +2 -2
- package/dist/nuxt.d.ts +4 -14
- package/dist/nuxt.js +29 -9
- package/dist/{own-access-BvVUjaeL.d.ts → own-access-CGiai2L3.d.ts} +1 -1
- package/dist/presets.js +1 -1
- package/dist/runtime/client-request-plugin.d.ts +2 -1
- package/dist/runtime/client-request-plugin.js +8 -5
- package/dist/runtime/console.d.ts +1 -1
- package/dist/runtime/console.js +2 -2
- package/dist/runtime/empty-abilities.d.ts +1 -1
- package/dist/runtime/empty-client.d.ts +3 -0
- package/dist/runtime/empty-client.js +3 -1
- package/dist/runtime/empty-definition.d.ts +1 -1
- package/dist/runtime/server.d.ts +4 -3
- package/dist/runtime/server.js +3 -2
- package/dist/runtime/vue-nuxt.js +1 -1
- package/dist/schema.d.ts +32 -14
- package/dist/schema.js +21 -14
- package/dist/{server-iQNOXyfS.js → server-5t-HA7I1.js} +41 -316
- package/dist/{server-1G_BbfBD.d.ts → server-DyP1v-sZ.d.ts} +25 -6
- package/dist/{server-B8kTFrHP.d.ts → server-mmp8EfcE.d.ts} +3 -2
- package/dist/server.d.ts +3 -3
- package/dist/server.js +4 -4
- package/dist/{session-cookies-DN0svCKj.js → session-cookies-BNtY3hMp.js} +4 -16
- package/dist/{set-cookie-CMB3t4NF.js → set-cookie-Bva-P-_C.js} +1 -1
- package/dist/{table-specs-C3-bLOSF.js → table-specs-Bm7QJCbu.js} +1 -1
- package/dist/{table-specs-P4LvbOlX.d.ts → table-specs-BxKeFD_y.d.ts} +5 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +2 -2
- package/dist/{types-BmRGse4l.d.ts → types-CnO5bHEF.d.ts} +20 -2
- package/dist/{vite-GRzej8Cs.js → vite-7I1bJvqA.js} +641 -240
- package/dist/vite-CZ_Z6IR3.d.ts +28 -0
- package/dist/vite.d.ts +33 -13
- package/dist/vite.js +1 -1
- package/dist/vue.d.ts +4 -3
- package/dist/vue.js +39 -4
- package/package.json +8 -8
- package/dist/client-request-BzMKtfCY.js +0 -52
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import "vite";
|
|
2
|
+
interface NuxtLayerDirectoryConfig {
|
|
3
|
+
rootDir?: string;
|
|
4
|
+
serverDir?: string;
|
|
5
|
+
srcDir?: string;
|
|
6
|
+
}
|
|
7
|
+
/** The Nuxt options that locate the server directory of each layer. */
|
|
8
|
+
interface NuxtServerDirOptions extends NuxtLayerDirectoryConfig {
|
|
9
|
+
_layers?: ReadonlyArray<{
|
|
10
|
+
config?: NuxtLayerDirectoryConfig;
|
|
11
|
+
cwd?: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Server directories that ViteHub scans for Definitions. The first entry is the application.
|
|
16
|
+
* Later entries are Nuxt layers in Nuxt priority order.
|
|
17
|
+
*/
|
|
18
|
+
declare const VITEHUB_SERVER_DIRS: "__vitehubServerDirs";
|
|
19
|
+
declare const VITEHUB_NUXT_AUTH_DISCOVERY: "__vitehubNuxtAuthDiscovery";
|
|
20
|
+
interface NuxtAuthDiscovery {
|
|
21
|
+
appDir: string | undefined;
|
|
22
|
+
layerAppDirs: string[];
|
|
23
|
+
layerAliases: Readonly<Record<string, string>>;
|
|
24
|
+
}
|
|
25
|
+
declare function resolveNuxtAuthDiscovery(options: NuxtServerDirOptions & {
|
|
26
|
+
alias?: Record<string, string>;
|
|
27
|
+
}): NuxtAuthDiscovery;
|
|
28
|
+
export { NuxtServerDirOptions as i, VITEHUB_SERVER_DIRS as n, resolveNuxtAuthDiscovery as r, VITEHUB_NUXT_AUTH_DISCOVERY as t };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference path="./host-declarations.d.ts" />
|
|
2
|
-
import {
|
|
2
|
+
import { r as resolveNuxtAuthDiscovery } from "./vite-CZ_Z6IR3.js";
|
|
3
|
+
import { V as DiscoveredAuthDefinition, W as ResolvedAuthViteConfig, w as AuthOptions } from "./types-CnO5bHEF.js";
|
|
3
4
|
import { n as ViteHubCliPluginMetadata } from "./cli-DL7uCAvz.js";
|
|
4
5
|
import { Plugin } from "vite";
|
|
5
6
|
interface ViteHubDefinitionField {
|
|
@@ -63,23 +64,21 @@ type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor |
|
|
|
63
64
|
interface ViteHubInspectionPluginMetadata {
|
|
64
65
|
inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
-
projectRoot: string;
|
|
68
|
-
viteRoot?: string;
|
|
69
|
-
serverDirs?: readonly string[];
|
|
70
|
-
}): {
|
|
71
|
-
definition: DiscoveredAuthDefinition;
|
|
72
|
-
rootDir: string;
|
|
73
|
-
} | undefined;
|
|
67
|
+
type LayerRootsByAlias = Readonly<Record<string, string>>;
|
|
74
68
|
/**
|
|
75
69
|
* Whether the Auth Definition of the project keeps users in the app Database with `authDatabase()`. ViteHub turns the
|
|
76
70
|
* Database on for it, as it does for Connections.
|
|
77
71
|
*/
|
|
78
|
-
|
|
79
|
-
export declare function resolveAuthViteConfig(options?: AuthOptions, rootDir?: string, discovery?: {
|
|
72
|
+
interface AuthDiscovery {
|
|
80
73
|
projectRoot?: string;
|
|
81
74
|
serverDirs?: readonly string[];
|
|
82
|
-
|
|
75
|
+
layerAliases?: LayerRootsByAlias;
|
|
76
|
+
}
|
|
77
|
+
export declare function usesAuthDatabase(project: AuthDiscovery & {
|
|
78
|
+
projectRoot: string;
|
|
79
|
+
viteRoot?: string;
|
|
80
|
+
}): boolean;
|
|
81
|
+
export declare function resolveAuthViteConfig(options?: AuthOptions, rootDir?: string, discovery?: AuthDiscovery): ResolvedAuthViteConfig | undefined;
|
|
83
82
|
/** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
|
|
84
83
|
type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
|
|
85
84
|
/**
|
|
@@ -122,6 +121,21 @@ interface ContributionContext {
|
|
|
122
121
|
/** The flat list of Vite plugins, so a factory can read what sibling plugins declare. */
|
|
123
122
|
plugins?: readonly unknown[];
|
|
124
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* The parts of the Auth Definition, `server/auth.extend.ts`: the file of the application first, then the files of
|
|
126
|
+
* Nuxt layers in priority order.
|
|
127
|
+
*/
|
|
128
|
+
export declare function discoverAuthExtensions(rootDir: string, options?: {
|
|
129
|
+
serverDirs?: readonly string[];
|
|
130
|
+
}): string[];
|
|
131
|
+
export declare function discoverProjectAuthDefinition(project: {
|
|
132
|
+
projectRoot: string;
|
|
133
|
+
viteRoot?: string;
|
|
134
|
+
serverDirs?: readonly string[];
|
|
135
|
+
}): {
|
|
136
|
+
definition: DiscoveredAuthDefinition;
|
|
137
|
+
rootDir: string;
|
|
138
|
+
} | undefined;
|
|
125
139
|
export declare const AUTH_ABILITIES_ID = "#vitehub/auth/abilities";
|
|
126
140
|
export declare const AUTH_CLIENT_ID = "#vitehub/auth/client";
|
|
127
141
|
export declare const AUTH_DEFINITION_ID = "#vitehub/auth/definition";
|
|
@@ -144,7 +158,7 @@ export interface AuthDatabaseContribution {
|
|
|
144
158
|
name: "auth";
|
|
145
159
|
database: string;
|
|
146
160
|
dialect: "postgresql" | "sqlite";
|
|
147
|
-
/** The
|
|
161
|
+
/** The generated module of the Auth tables, with the plugins and additional fields of the Definition. */
|
|
148
162
|
definition: {
|
|
149
163
|
module: string;
|
|
150
164
|
export: "authPostgresSchema" | "authSqliteSchema";
|
|
@@ -159,14 +173,20 @@ export type AuthVitePlugin = Plugin & {
|
|
|
159
173
|
databases: (context: AuthDatabaseContributionContext) => Promise<AuthDatabaseContribution[]>;
|
|
160
174
|
};
|
|
161
175
|
};
|
|
176
|
+
/** The specifiers of the Auth tables. Each host resolves them to the generated module, so an app imports the tables that Auth adds. */
|
|
177
|
+
export declare const authSchemaSpecifiers: readonly ["@vite-hub/auth/schema", "vite-hub/auth/schema"];
|
|
178
|
+
/** The generated module of the Auth tables, which `authSchemaSpecifiers` resolve to when the Definition uses `authDatabase()`. */
|
|
179
|
+
export declare function authSchemaModule(config: Pick<ResolvedAuthViteConfig, "projectRoot">): string;
|
|
162
180
|
export declare function createAuthNitroConfig(plugin: AuthVitePlugin, options: {
|
|
163
181
|
nitro: Record<string, unknown>;
|
|
164
182
|
projectRoot: string;
|
|
165
183
|
serverDirs?: string[];
|
|
184
|
+
nuxtDiscovery?: ReturnType<typeof resolveNuxtAuthDiscovery>;
|
|
166
185
|
}): Record<string, unknown>;
|
|
167
186
|
interface InternalAuthModuleOptions {
|
|
168
187
|
databaseDisabled?: boolean;
|
|
169
188
|
importBase?: string;
|
|
189
|
+
layerAliases?: Readonly<Record<string, string>>;
|
|
170
190
|
}
|
|
171
191
|
export declare function writeNuxtAuthDefinition(root: string, config: ResolvedAuthViteConfig): Promise<string>;
|
|
172
192
|
export declare function hubAuth(options?: AuthOptions, internalOptions?: InternalAuthModuleOptions): AuthVitePlugin;
|
package/dist/vite.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as AUTH_ABILITIES_ID, n as AUTH_CLIENT_ID, r as AUTH_DEFINITION_ID, i as AUTH_SERVER_ID, a as AUTH_VITE_PLUGIN_NAME, o as createAuthNitroConfig,
|
|
1
|
+
export { t as AUTH_ABILITIES_ID, n as AUTH_CLIENT_ID, r as AUTH_DEFINITION_ID, i as AUTH_SERVER_ID, a as AUTH_VITE_PLUGIN_NAME, o as authSchemaModule, s as authSchemaSpecifiers, c as createAuthNitroConfig, m as discoverAuthExtensions, h as discoverProjectAuthDefinition, l as hubAuth, d as resolveAuthViteConfig, f as usesAuthDatabase, u as writeNuxtAuthDefinition } from "./vite-7I1bJvqA.js";
|
package/dist/vue.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference path="./host-declarations.d.ts" />
|
|
2
|
-
import { a as AbilityRefusal, i as AbilityName, t as AbilityArgs } from "./abilities-
|
|
3
|
-
import { S as AuthFor, _ as AuthDefinition } from "./types-
|
|
2
|
+
import { a as AbilityRefusal, i as AbilityName, t as AbilityArgs } from "./abilities-IOwpkcz4.js";
|
|
3
|
+
import { S as AuthFor, _ as AuthDefinition } from "./types-CnO5bHEF.js";
|
|
4
|
+
import { a as extendAuthClient, i as ExtendedAuthClientOptions, n as AuthClientExtensionOptions, t as AuthClientExtension } from "./client-extension-BgUlm6hy.js";
|
|
4
5
|
import { n as AbilityErrorData } from "./ability-error-C1c30O6E.js";
|
|
5
6
|
import { BetterAuthClientOptions } from "better-auth";
|
|
6
7
|
import { ComputedRef, VNode } from "vue";
|
|
@@ -291,4 +292,4 @@ export type AuthPermissionComponent = <const Name extends AbilityName>(props: Au
|
|
|
291
292
|
};
|
|
292
293
|
/** Render the allowed or denied slot. The default slot is shorthand for allowed. */
|
|
293
294
|
export declare const AuthPermission: AuthPermissionComponent;
|
|
294
|
-
export type
|
|
295
|
+
export { type AuthClientExtension, type AuthClientExtensionOptions, type ExtendedAuthClientOptions, type RequestFetch, type VueAuthClient, extendAuthClient };
|
package/dist/vue.js
CHANGED
|
@@ -1,8 +1,43 @@
|
|
|
1
|
-
import { n as checkAbility, t as AbilityError } from "./ability-error-
|
|
1
|
+
import { n as checkAbility, t as AbilityError } from "./ability-error-DgR91Jwc.js";
|
|
2
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-DZHuHXPP.js";
|
|
3
|
+
import { n as assertUniquePluginIds } from "./extension-mCx4TrsO.js";
|
|
2
4
|
import { i as resolveAuthMountPath } from "./application-path-zKi7NrvK.js";
|
|
3
5
|
import { a as setRequestFetchResolver, i as setNuxtErrorFactory, n as setDefaultAuthBasePath, o as setSessionSeedResolver, r as setNuxtAppResolver, s as setSignOutHandler, t as authNuxtBridge } from "./nuxt-bridge-pRyfYD5c.js";
|
|
4
6
|
import abilities from "#vitehub/auth/abilities";
|
|
5
7
|
import { computed, defineComponent, effectScope, getCurrentInstance, getCurrentScope, inject, onScopeDispose, onServerPrefetch, provide, shallowRef, watch } from "vue";
|
|
8
|
+
// src/client-extension.ts
|
|
9
|
+
/**
|
|
10
|
+
* A part of the Auth client options: Better Auth client plugins that a Nuxt layer, or the app, adds to the options of
|
|
11
|
+
* `auth.client.ts`. Export it as the default export of `auth.client.extend.ts`, which is in `app/` in a Nuxt app.
|
|
12
|
+
*/
|
|
13
|
+
function extendAuthClient(options) {
|
|
14
|
+
const option = Object.keys(options).find((key) => key !== "plugins");
|
|
15
|
+
if (option) throw authErrorDiagnostics.AUTH_EXTENSION_OPTION_INVALID({
|
|
16
|
+
file: "`extendAuthClient()`",
|
|
17
|
+
option
|
|
18
|
+
});
|
|
19
|
+
return { extension: options };
|
|
20
|
+
}
|
|
21
|
+
const pluginIds = (options) => (options?.plugins ?? []).map((plugin) => plugin.id);
|
|
22
|
+
/** The client options with the plugins of their parts: the options first, then each part in the order of `extensions`. */
|
|
23
|
+
function applyAuthClientExtensions(options, extensions = []) {
|
|
24
|
+
if (!extensions.length) return options;
|
|
25
|
+
const sources = [{
|
|
26
|
+
file: "auth.client.ts",
|
|
27
|
+
options
|
|
28
|
+
}, ...extensions.map(({ file, extension }) => ({
|
|
29
|
+
file,
|
|
30
|
+
options: extension.extension
|
|
31
|
+
}))];
|
|
32
|
+
assertUniquePluginIds(sources.map((source) => ({
|
|
33
|
+
file: source.file,
|
|
34
|
+
ids: pluginIds(source.options)
|
|
35
|
+
})));
|
|
36
|
+
return {
|
|
37
|
+
...options,
|
|
38
|
+
plugins: sources.flatMap((source) => source.options?.plugins ?? [])
|
|
39
|
+
};
|
|
40
|
+
}
|
|
6
41
|
// src/vue.ts
|
|
7
42
|
const LOAD = Symbol.for("vitehub.auth.client.load");
|
|
8
43
|
const ON_LOAD = Symbol.for("vitehub.auth.client.on-load");
|
|
@@ -402,8 +437,8 @@ function defineAuthClient(options) {
|
|
|
402
437
|
* Auth Definition's `basePath` below the `app.baseURL` of the page, also when `NUXT_APP_BASE_URL` sets it at runtime.
|
|
403
438
|
*/
|
|
404
439
|
const authClient = createLazyAuthClient(async () => {
|
|
405
|
-
const { default: options } = await import("#vitehub/auth/client");
|
|
406
|
-
return withDefaultBasePath(options);
|
|
440
|
+
const { default: options, extensions } = await import("#vitehub/auth/client");
|
|
441
|
+
return withDefaultBasePath(applyAuthClientExtensions(options, extensions));
|
|
407
442
|
});
|
|
408
443
|
/** Provide the app's configured client to Auth composables and `<AuthPermission>` in descendant components. */
|
|
409
444
|
function provideAuthClient(client) {
|
|
@@ -605,4 +640,4 @@ const AuthPermission = defineComponent({
|
|
|
605
640
|
};
|
|
606
641
|
}
|
|
607
642
|
});
|
|
608
|
-
export { AuthPermission, authClient, createAuthClient, defineAuthClient, loadAuthClient, onSignOut, provideAuthClient, setDefaultAuthBasePath, setNuxtAppResolver, setNuxtErrorFactory, setRequestFetchResolver, setSessionSeedResolver, setSignOutHandler, useAbility, useAuthClient, useUserSession };
|
|
643
|
+
export { AuthPermission, authClient, createAuthClient, defineAuthClient, extendAuthClient, loadAuthClient, onSignOut, provideAuthClient, setDefaultAuthBasePath, setNuxtAppResolver, setNuxtErrorFactory, setRequestFetchResolver, setSessionSeedResolver, setSignOutHandler, useAbility, useAuthClient, useUserSession };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Better Auth-powered authentication primitives and Vite integration for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"auth",
|
|
@@ -144,9 +144,9 @@
|
|
|
144
144
|
"dependencies": {
|
|
145
145
|
"@noble/hashes": "^2.4.0",
|
|
146
146
|
"@types/node": "^24.19.2",
|
|
147
|
-
"@vite-hub/env": "0.
|
|
148
|
-
"@vite-hub/runtime": "0.
|
|
149
|
-
"@vite-hub/web-container": "0.
|
|
147
|
+
"@vite-hub/env": "0.8.0",
|
|
148
|
+
"@vite-hub/runtime": "0.8.0",
|
|
149
|
+
"@vite-hub/web-container": "0.8.0",
|
|
150
150
|
"better-auth": "^1.7.27",
|
|
151
151
|
"better-auth-rou3": "npm:rou3@0.9.2",
|
|
152
152
|
"h3": "^2.0.8",
|
|
@@ -166,8 +166,8 @@
|
|
|
166
166
|
"@types/json-schema": "^7.0.15",
|
|
167
167
|
"@types/mdast": "^4.0.4",
|
|
168
168
|
"@types/node": "^24.19.2",
|
|
169
|
-
"@vite-hub/agent": "0.
|
|
170
|
-
"@vite-hub/database": "0.
|
|
169
|
+
"@vite-hub/agent": "0.8.0",
|
|
170
|
+
"@vite-hub/database": "0.8.0",
|
|
171
171
|
"@vite-hub/internal": "0.0.1",
|
|
172
172
|
"bun-types": "^1.4.5",
|
|
173
173
|
"evlog": "2.37.1",
|
|
@@ -190,8 +190,8 @@
|
|
|
190
190
|
"@better-auth/oauth-provider": "^1.7.27",
|
|
191
191
|
"@types/json-schema": "^7.0.15",
|
|
192
192
|
"@types/mdast": "^4.0.4",
|
|
193
|
-
"@vite-hub/agent": "0.
|
|
194
|
-
"@vite-hub/database": "0.
|
|
193
|
+
"@vite-hub/agent": "0.8.0",
|
|
194
|
+
"@vite-hub/database": "0.8.0",
|
|
195
195
|
"nitro": "3.0.261102-rc || ^3.0.261103-rc",
|
|
196
196
|
"vite": ">=8.0.0",
|
|
197
197
|
"vue": "^3.5.0",
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
// ../internal/src/runtime/request-origin.ts
|
|
3
|
-
function firstHeaderValue(headers, name) {
|
|
4
|
-
return headers.get(name)?.split(",", 1)[0]?.trim() || void 0;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* The origin that the client used for `request`. A TLS-terminating proxy sends the client scheme in
|
|
8
|
-
* `X-Forwarded-Proto` and the client host in `X-Forwarded-Host`. Each proxy appends its value, so the first value wins.
|
|
9
|
-
* Without these headers, or with values that are not valid, the result is the origin of `request.url`.
|
|
10
|
-
*/
|
|
11
|
-
function forwardedRequestOrigin(request) {
|
|
12
|
-
const url = new URL(request.url);
|
|
13
|
-
const forwardedProtocol = firstHeaderValue(request.headers, "x-forwarded-proto")?.toLowerCase();
|
|
14
|
-
const protocol = forwardedProtocol === "http" || forwardedProtocol === "https" ? forwardedProtocol : url.protocol.slice(0, -1);
|
|
15
|
-
const host = firstHeaderValue(request.headers, "x-forwarded-host") ?? url.host;
|
|
16
|
-
if (/[\u0000-\u001F\s/\\?#@]/.test(host)) return url.origin;
|
|
17
|
-
try {
|
|
18
|
-
return new URL(`${protocol}://${host}`).origin;
|
|
19
|
-
} catch {
|
|
20
|
-
return url.origin;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
// src/client-request.ts
|
|
24
|
-
const storageKey = Symbol.for("vitehub.auth.client-request");
|
|
25
|
-
const runtimeGlobal = globalThis;
|
|
26
|
-
const clientRequests = runtimeGlobal[storageKey] ||= new AsyncLocalStorage();
|
|
27
|
-
function isRelativeInProcessRequest(request, client) {
|
|
28
|
-
const url = new URL(request.url);
|
|
29
|
-
if (url.protocol !== "http:") return false;
|
|
30
|
-
if (url.host === "localhost") return true;
|
|
31
|
-
const clientUrl = new URL(client.url);
|
|
32
|
-
url.protocol = clientUrl.protocol;
|
|
33
|
-
return url.host === clientUrl.host;
|
|
34
|
-
}
|
|
35
|
-
function runWithClientRequest(request, next) {
|
|
36
|
-
const client = clientRequests.getStore();
|
|
37
|
-
return client && isRelativeInProcessRequest(request, client) ? next() : clientRequests.run(request, next);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Nitro builds a relative request that the server sends to itself, such as a Nuxt `useFetch()` during server rendering
|
|
41
|
-
* or `serverFetch("/api/...")`, at `http://localhost` or `http://<forwarded Host>`, so the URL of that request does not
|
|
42
|
-
* show the origin of the page.
|
|
43
|
-
*/
|
|
44
|
-
function clientRequest(request) {
|
|
45
|
-
const client = clientRequests.getStore();
|
|
46
|
-
return client && isRelativeInProcessRequest(request, client) ? client : request;
|
|
47
|
-
}
|
|
48
|
-
function clientRequestOrigin(request, trustProxyHeaders = false) {
|
|
49
|
-
const client = clientRequest(request);
|
|
50
|
-
return trustProxyHeaders ? forwardedRequestOrigin(client) : new URL(client.url).origin;
|
|
51
|
-
}
|
|
52
|
-
export { forwardedRequestOrigin as i, clientRequestOrigin as n, runWithClientRequest as r, clientRequest as t };
|