@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
package/dist/vite.d.ts CHANGED
@@ -1,24 +1,34 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
- import { P as ResolvedAuthViteConfig, h as AuthModuleOptions } from "./types-jaRlW3D1.js";
2
+ import { n as ViteHubCliPluginMetadata } from "./cli-mgXvsBtA.js";
3
+ import { F as AuthModuleOptions, ct as ResolvedAuthViteConfig } from "./events-BkmK2dFY.js";
4
+ import { n as ViteHubDefinitionSummary, r as ViteHubInspectionPluginMetadata } from "./inspect-DPtsW8dB.js";
3
5
  import { Plugin } from "vite";
4
-
5
6
  //#region src/config.d.ts
6
- declare function resolveAuthViteConfig(options?: AuthModuleOptions, rootDir?: string, discovery?: {
7
+ export declare function resolveAuthViteConfig(options?: AuthModuleOptions, rootDir?: string, discovery?: {
7
8
  serverDirs?: string[];
8
9
  }): ResolvedAuthViteConfig | undefined;
9
10
  //#endregion
10
11
  //#region src/vite.d.ts
11
- declare const AUTH_DEFINITION_ID = "#vitehub/auth/definition";
12
- declare const AUTH_SERVER_ID = "#vitehub/auth/server";
13
- declare const AUTH_VITE_PLUGIN_NAME = "@vite-hub/auth/vite";
14
- interface AuthVitePluginAPI {
12
+ export declare function shouldPassThroughAuthResponse(basePath: string, status: number): boolean;
13
+ export declare const AUTH_DEFINITION_ID = "#vitehub/auth/definition";
14
+ export declare const AUTH_SERVER_ID = "#vitehub/auth/server";
15
+ export declare const AUTH_VITE_PLUGIN_NAME = "@vite-hub/auth/vite";
16
+ export interface AuthVitePluginAPI {
15
17
  getConfig: () => ResolvedAuthViteConfig | undefined;
16
18
  refresh: () => ResolvedAuthViteConfig | undefined;
17
19
  }
18
- type AuthVitePlugin = Plugin & {
20
+ export type AuthVitePlugin = Plugin & {
19
21
  api: AuthVitePluginAPI;
22
+ vitehub: ViteHubInspectionPluginMetadata & ViteHubCliPluginMetadata;
20
23
  };
21
- declare function createAuthNitroConfig(plugin: AuthVitePlugin, options: {
24
+ export interface AuthInspectionOptions {
25
+ projectRoot: string;
26
+ rootDir: string;
27
+ serverDirs?: string[];
28
+ }
29
+ /** Lists the Auth Definition as a serializable inspection summary. */
30
+ export declare function inspectAuthDefinitions(options: AuthInspectionOptions): ViteHubDefinitionSummary[];
31
+ export declare function createAuthNitroConfig(plugin: AuthVitePlugin, options: {
22
32
  nitro: Record<string, unknown>;
23
33
  projectRoot: string;
24
34
  serverDirs?: string[];
@@ -27,11 +37,10 @@ declare function createAuthNitroConfig(plugin: AuthVitePlugin, options: {
27
37
  interface InternalAuthModuleOptions {
28
38
  importBase?: string;
29
39
  }
30
- declare function hubAuth(options?: AuthModuleOptions, internalOptions?: InternalAuthModuleOptions): AuthVitePlugin;
40
+ export declare function hubAuth(options?: AuthModuleOptions, internalOptions?: InternalAuthModuleOptions): AuthVitePlugin;
31
41
  declare module "vite" {
32
42
  interface UserConfig {
33
43
  auth?: AuthModuleOptions;
34
44
  }
35
45
  }
36
- //#endregion
37
- export { AUTH_DEFINITION_ID, AUTH_SERVER_ID, AUTH_VITE_PLUGIN_NAME, AuthVitePlugin, AuthVitePluginAPI, createAuthNitroConfig, hubAuth, resolveAuthViteConfig };
46
+ //#endregion
package/dist/vite.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as hubAuth, i as createAuthNitroConfig, n as AUTH_SERVER_ID, o as resolveAuthViteConfig, r as AUTH_VITE_PLUGIN_NAME, t as AUTH_DEFINITION_ID } from "./vite-Cmey8ODS.js";
2
- export { AUTH_DEFINITION_ID, AUTH_SERVER_ID, AUTH_VITE_PLUGIN_NAME, createAuthNitroConfig, hubAuth, resolveAuthViteConfig };
1
+ import { a as hubAuth, c as resolveAuthViteConfig, i as createAuthNitroConfig, n as AUTH_SERVER_ID, o as inspectAuthDefinitions, r as AUTH_VITE_PLUGIN_NAME, s as shouldPassThroughAuthResponse, t as AUTH_DEFINITION_ID } from "./vite-COWkwxsj.js";
2
+ export { AUTH_DEFINITION_ID, AUTH_SERVER_ID, AUTH_VITE_PLUGIN_NAME, createAuthNitroConfig, hubAuth, inspectAuthDefinitions, resolveAuthViteConfig, shouldPassThroughAuthResponse };
package/dist/vue.d.ts CHANGED
@@ -1,12 +1,25 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
2
  import { SessionQueryParams } from "better-auth";
3
- import { BetterFetchError, VueAuthClient, VueAuthClient as VueAuthClient$1, createAuthClient } from "better-auth/vue";
4
3
  import { ComputedRef, DeepReadonly, Ref } from "vue";
5
-
4
+ import { BetterFetchError, VueAuthClient, VueAuthClient as VueAuthClient$1, createAuthClient as createAuthClient$1 } from "better-auth/vue";
6
5
  //#region src/vue.d.ts
7
- declare const authClient: VueAuthClient$1<{}>;
8
- declare function useAuthClient(): typeof authClient;
9
- interface AuthSessionState<Client extends VueAuthClient$1<any> = typeof authClient> {
6
+ type NuxtApp = {
7
+ runWithContext<T>(run: () => T): T;
8
+ };
9
+ /** Internal bridge installed by the Nuxt module, without making `#app` a dependency of this entry. */
10
+ export declare function setNuxtAppResolver(resolver: (() => NuxtApp | undefined) | undefined): void;
11
+ /**
12
+ * Better Auth's Vue client with the same options, types, and calls, which loads `better-auth/vue` the first time it is
13
+ * used. Creating one costs nothing, so an app can create it up front and only pages that sign in pay for Better Auth.
14
+ * Calls such as `signIn.social()` wait for the load. Hooks such as `useSession()` return a ref at once that is
15
+ * pending until then, and stays pending during server rendering. Use `loadAuthClient()` for anything else, such as `$store`.
16
+ */
17
+ export declare const createAuthClient: typeof createAuthClient$1;
18
+ /** Better Auth's own Vue client behind one that `createAuthClient()` returned, once it has loaded. */
19
+ export declare function loadAuthClient<Client extends VueAuthClient$1<any>>(client: Client): Promise<Client>;
20
+ export declare const authClient: VueAuthClient$1<{}>;
21
+ export declare function useAuthClient(): typeof authClient;
22
+ export interface AuthSessionState<Client extends VueAuthClient$1<any> = typeof authClient> {
10
23
  data: Client["$Infer"]["Session"] | null;
11
24
  error: BetterFetchError | null;
12
25
  isPending: boolean;
@@ -16,11 +29,13 @@ interface AuthSessionState<Client extends VueAuthClient$1<any> = typeof authClie
16
29
  }) => Promise<void>;
17
30
  }
18
31
  type AuthSessionRef<Client extends VueAuthClient$1<any> = typeof authClient> = DeepReadonly<Ref<AuthSessionState<Client>>>;
19
- declare function useSession<Client extends VueAuthClient$1<any> = typeof authClient>(client?: Client): AuthSessionRef<Client>;
32
+ export declare function useSession<Client extends VueAuthClient$1<any> = typeof authClient>(client?: Client): AuthSessionRef<Client>;
20
33
  type ClientSession<Client extends VueAuthClient$1<any>> = Client["$Infer"]["Session"];
21
- interface UserSession<Client extends VueAuthClient$1<any> = typeof authClient> {
34
+ export interface UserSession<Client extends VueAuthClient$1<any> = typeof authClient> {
22
35
  data: ComputedRef<ClientSession<Client> | null>;
23
36
  error: ComputedRef<BetterFetchError | null>;
37
+ /** The id of the administrator who opened this session as `user`, or `null`. Better Auth's admin plugin sets it. */
38
+ impersonatedBy: ComputedRef<string | null>;
24
39
  loggedIn: ComputedRef<boolean>;
25
40
  pending: ComputedRef<boolean>;
26
41
  ready: ComputedRef<boolean>;
@@ -29,10 +44,12 @@ interface UserSession<Client extends VueAuthClient$1<any> = typeof authClient> {
29
44
  signIn: Client["signIn"];
30
45
  signOut: Client["signOut"];
31
46
  signUp: Client["signUp"];
47
+ /** End the impersonation session and restore the administrator's own session. */
48
+ stopImpersonating: () => Promise<void>;
32
49
  user: ComputedRef<ClientSession<Client>["user"] | null>;
33
50
  }
34
- declare function useUserSession<Client extends VueAuthClient$1<any> = typeof authClient>(client?: Client): UserSession<Client>;
35
- declare function useSignIn(): typeof authClient.signIn;
36
- declare function useSignUp(): typeof authClient.signUp;
51
+ export declare function useUserSession<Client extends VueAuthClient$1<any> = typeof authClient>(client?: Client): UserSession<Client>;
52
+ export declare function useSignIn(): typeof authClient.signIn;
53
+ export declare function useSignUp(): typeof authClient.signUp;
37
54
  //#endregion
38
- export { AuthSessionState, UserSession, type VueAuthClient, authClient, createAuthClient, useAuthClient, useSession, useSignIn, useSignUp, useUserSession };
55
+ export type { VueAuthClient };
package/dist/vue.js CHANGED
@@ -1,7 +1,73 @@
1
- import { createAuthClient } from "better-auth/vue";
2
- import { computed } from "vue";
1
+ import { t as resolveAuthMountPath } from "./application-path-C290OAIs.js";
2
+ import { computed, getCurrentInstance, getCurrentScope, shallowRef, watch } from "vue";
3
3
  //#region src/vue.ts
4
- const authClient = createAuthClient();
4
+ const LOAD = Symbol.for("vitehub.auth.client.load");
5
+ let nuxtAppResolver;
6
+ /** Internal bridge installed by the Nuxt module, without making `#app` a dependency of this entry. */
7
+ function setNuxtAppResolver(resolver) {
8
+ nuxtAppResolver = resolver;
9
+ }
10
+ /** The state of a client hook, such as `useSession()`, before Better Auth's client has loaded. */
11
+ const pendingState = (refetch) => ({
12
+ data: null,
13
+ error: null,
14
+ isPending: true,
15
+ isRefetching: false,
16
+ refetch
17
+ });
18
+ /**
19
+ * Better Auth's Vue client with the same options, types, and calls, which loads `better-auth/vue` the first time it is
20
+ * used. Creating one costs nothing, so an app can create it up front and only pages that sign in pay for Better Auth.
21
+ * Calls such as `signIn.social()` wait for the load. Hooks such as `useSession()` return a ref at once that is
22
+ * pending until then, and stays pending during server rendering. Use `loadAuthClient()` for anything else, such as `$store`.
23
+ */
24
+ const createAuthClient = (options) => {
25
+ let loaded;
26
+ const load = () => loaded ??= import("better-auth/vue").then((module) => module.createAuthClient(options));
27
+ function hook(name, args) {
28
+ const scope = getCurrentScope();
29
+ const nuxtApp = nuxtAppResolver?.() || getCurrentInstance()?.appContext.config.globalProperties.$nuxt;
30
+ const real = (client) => Reflect.get(client, name)(...args);
31
+ if (typeof args[0] === "function") return load().then((client) => runIn(scope, () => nuxtApp ? nuxtApp.runWithContext(() => real(client)) : real(client)));
32
+ const pending = pendingState(async (...query) => {
33
+ await load();
34
+ const current = state.value;
35
+ return current === pending ? void 0 : current.refetch?.(...query);
36
+ });
37
+ const state = shallowRef(pending);
38
+ if (!("window" in globalThis)) return state;
39
+ load().then((client) => {
40
+ if (scope && !scope.active) return;
41
+ runIn(scope, () => watch(real(client), (value) => state.value = value, { immediate: true }));
42
+ });
43
+ return state;
44
+ }
45
+ function call(path) {
46
+ return new Proxy(function() {}, {
47
+ get(_, key) {
48
+ if (key === LOAD && !path.length) return load;
49
+ if (typeof key !== "string" || key === "then" || key === "catch" || key === "finally") return void 0;
50
+ if (!path.length && /^use[A-Z]/.test(key)) return (...args) => hook(key, args);
51
+ return call([...path, key]);
52
+ },
53
+ async apply(_, __, args) {
54
+ const client = await load();
55
+ return path.reduce((node, key) => Reflect.get(Object(node), key), client)(...args);
56
+ }
57
+ });
58
+ }
59
+ return call([]);
60
+ };
61
+ /** Run `run` in the scope the hook was called in, so its watchers stop with the component that called it. */
62
+ function runIn(scope, run) {
63
+ return scope ? scope.run(run) : run();
64
+ }
65
+ /** Better Auth's own Vue client behind one that `createAuthClient()` returned, once it has loaded. */
66
+ async function loadAuthClient(client) {
67
+ const load = Reflect.get(client, LOAD);
68
+ return load ? await load() : client;
69
+ }
70
+ const authClient = createAuthClient({ basePath: resolveAuthMountPath("/api/auth") });
5
71
  function useAuthClient() {
6
72
  return authClient;
7
73
  }
@@ -13,6 +79,10 @@ function useUserSession(client = authClient) {
13
79
  return {
14
80
  data: computed(() => state.value.data),
15
81
  error: computed(() => state.value.error),
82
+ impersonatedBy: computed(() => {
83
+ const value = state.value.data?.session ? Reflect.get(state.value.data.session, "impersonatedBy") : void 0;
84
+ return typeof value === "string" && value ? value : null;
85
+ }),
16
86
  loggedIn: computed(() => Boolean(state.value.data?.session && state.value.data?.user)),
17
87
  pending: computed(() => state.value.isPending || state.value.isRefetching),
18
88
  ready: computed(() => !state.value.isPending),
@@ -21,6 +91,14 @@ function useUserSession(client = authClient) {
21
91
  signIn: client.signIn,
22
92
  signOut: client.signOut,
23
93
  signUp: client.signUp,
94
+ async stopImpersonating() {
95
+ await client.$fetch("/admin/stop-impersonating", {
96
+ method: "POST",
97
+ body: {},
98
+ throw: true
99
+ });
100
+ await state.value.refetch();
101
+ },
24
102
  user: computed(() => state.value.data?.user ?? null)
25
103
  };
26
104
  }
@@ -31,4 +109,4 @@ function useSignUp() {
31
109
  return authClient.signUp;
32
110
  }
33
111
  //#endregion
34
- export { authClient, createAuthClient, useAuthClient, useSession, useSignIn, useSignUp, useUserSession };
112
+ export { authClient, createAuthClient, loadAuthClient, setNuxtAppResolver, useAuthClient, useSession, useSignIn, useSignUp, useUserSession };
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "@vite-hub/auth",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
4
  "description": "Better Auth-powered authentication primitives and Vite integration for ViteHub.",
5
5
  "keywords": [
6
6
  "auth",
7
7
  "authentication",
8
8
  "better-auth",
9
+ "nuxt",
10
+ "nuxt-module",
11
+ "session",
12
+ "typescript",
9
13
  "vite",
10
14
  "vitehub"
11
15
  ],
12
- "homepage": "https://github.com/vite-hub/vitehub#readme",
16
+ "homepage": "https://vitehub.dev",
13
17
  "bugs": "https://github.com/vite-hub/vitehub/issues",
14
18
  "license": "Apache-2.0",
15
19
  "author": "onmax <maximogarciamtnez@gmail.com>",
@@ -32,41 +36,97 @@
32
36
  }
33
37
  },
34
38
  "exports": {
35
- ".": "./dist/index.js",
36
- "./agent": "./dist/agent.js",
37
- "./nuxt": "./dist/nuxt.js",
38
- "./server": "./dist/server.js",
39
- "./vite": "./dist/vite.js",
40
- "./vue": "./dist/vue.js",
39
+ ".": {
40
+ "types": "./dist/index.d.ts",
41
+ "import": "./dist/index.js",
42
+ "default": "./dist/index.js"
43
+ },
44
+ "./agent": {
45
+ "types": "./dist/agent.d.ts",
46
+ "import": "./dist/agent.js",
47
+ "default": "./dist/agent.js"
48
+ },
49
+ "./cli": {
50
+ "types": "./dist/cli.d.ts",
51
+ "import": "./dist/cli.js",
52
+ "default": "./dist/cli.js"
53
+ },
54
+ "./console": {
55
+ "types": "./dist/console.d.ts",
56
+ "import": "./dist/console.js",
57
+ "default": "./dist/console.js"
58
+ },
59
+ "./console-runtime": {
60
+ "types": "./dist/console-runtime.d.ts",
61
+ "import": "./dist/console-runtime.js",
62
+ "default": "./dist/console-runtime.js"
63
+ },
64
+ "./nuxt": {
65
+ "types": "./dist/nuxt.d.ts",
66
+ "import": "./dist/nuxt.js",
67
+ "default": "./dist/nuxt.js"
68
+ },
69
+ "./presets": {
70
+ "types": "./dist/presets.d.ts",
71
+ "import": "./dist/presets.js",
72
+ "default": "./dist/presets.js"
73
+ },
74
+ "./runtime/console": {
75
+ "types": "./dist/runtime/console.d.ts",
76
+ "import": "./dist/runtime/console.js",
77
+ "default": "./dist/runtime/console.js"
78
+ },
79
+ "./server": {
80
+ "types": "./dist/server.d.ts",
81
+ "import": "./dist/server.js",
82
+ "default": "./dist/server.js"
83
+ },
84
+ "./vite": {
85
+ "types": "./dist/vite.d.ts",
86
+ "import": "./dist/vite.js",
87
+ "default": "./dist/vite.js"
88
+ },
89
+ "./vue": {
90
+ "types": "./dist/vue.d.ts",
91
+ "import": "./dist/vue.js",
92
+ "default": "./dist/vue.js"
93
+ },
41
94
  "./package.json": "./package.json"
42
95
  },
43
96
  "dependencies": {
44
- "@cloudflare/workers-types": "^4.20260509.1",
45
- "@types/node": "^24.13.3",
46
- "@vite-hub/env": "0.0.4",
47
- "@vite-hub/runtime": "0.0.4",
48
- "better-auth": "^1.6.23",
49
- "bun-types": "^1.3.10"
97
+ "@cloudflare/workers-types": "^5.20261016.1",
98
+ "@types/node": "^24.19.1",
99
+ "@vite-hub/env": "0.1.0",
100
+ "@vite-hub/runtime": "0.1.0",
101
+ "better-auth": "1.7.7",
102
+ "bun-types": "^1.4.3",
103
+ "drizzle-orm": "^0.45.3",
104
+ "nostics": "1.3.0",
105
+ "valibot": "^1.5.0"
50
106
  },
51
107
  "devDependencies": {
52
108
  "@types/json-schema": "^7.0.15",
53
109
  "@types/mdast": "^4.0.4",
54
- "@vite-hub/agent": "0.0.4",
55
- "@types/node": "^24.13.3",
56
- "publint": "^0.3.21",
110
+ "@types/node": "^24.19.1",
111
+ "@vite-hub/agent": "0.1.0",
112
+ "happy-dom": "20.14.5",
113
+ "miniflare": "4.20260730.0",
114
+ "publint": "^0.3.25",
57
115
  "typescript": "^6.0.3",
58
- "vite": "^8.0.8",
59
- "vite-plus": "^0.1.24",
60
- "vitest": "^4.1.4",
61
- "vue": "^3.5.0",
116
+ "undici": "8.12.2",
117
+ "vite": "^8.2.2",
118
+ "vite-plus": "^0.3.3",
119
+ "vitest": "^4.1.11",
120
+ "vue": "3.5.44",
121
+ "@better-auth/oauth-provider": "1.7.7",
62
122
  "@vite-hub/internal": "0.0.1"
63
123
  },
64
124
  "peerDependencies": {
65
125
  "@types/json-schema": "^7.0.15",
66
126
  "@types/mdast": "^4.0.4",
67
- "@vite-hub/agent": "0.0.4",
127
+ "@vite-hub/agent": "0.1.0",
68
128
  "vite": ">=8.0.0",
69
- "vue": "^3.5.0"
129
+ "vue": "3.5.44"
70
130
  },
71
131
  "peerDependenciesMeta": {
72
132
  "@vite-hub/agent": {
@@ -85,7 +145,7 @@
85
145
  "scripts": {
86
146
  "build": "vp pack",
87
147
  "dev": "vp pack --watch",
88
- "typecheck": "tsc --noEmit -p ./tsconfig.json",
148
+ "typecheck": "vp run --cache -t @vite-hub/auth#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
89
149
  "test": "vp run -t @vite-hub/auth#build && vp test"
90
150
  }
91
151
  }