@vite-hub/auth 0.8.0 → 0.9.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 +1 -1
- package/dist/{abilities-IOwpkcz4.d.ts → abilities-6LE7VSdN.d.ts} +1 -1
- package/dist/abilities.d.ts +1 -1
- package/dist/{ability-error-DgR91Jwc.js → ability-error-Ccm5Iy4F.js} +1 -1
- package/dist/{access-pages-C69nwa99.js → access-pages-lQGfRvfL.js} +1 -4
- package/dist/{admin-claim-code-C3X_U43x.js → admin-claim-code-CMa0eRRm.js} +0 -1
- package/dist/agent.js +3 -3
- package/dist/{application-path-zKi7NrvK.js → application-path-LMc_ptL9.js} +0 -2
- package/dist/{auth-instance-WeEK1zDd.js → auth-instance-0PTsOttV.js} +10 -48
- package/dist/bun-sqlite.d.ts +0 -2
- package/dist/cli.js +2 -2
- package/dist/{client-extension-BgUlm6hy.d.ts → client-extension-BVBVUqa1.d.ts} +1 -1
- package/dist/{console-runtime-Dk3j4Jmz.js → console-runtime-BlOx9hWC.js} +3 -19
- package/dist/{console-runtime-C71weVrt.d.ts → console-runtime-D2FUATXQ.d.ts} +1 -1
- 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-Cms7BI3c.js → database-options-CPhnGap9.js} +1 -1
- package/dist/{database-schema-options-IlHEeUBK.js → database-schema-options-BQyynyhw.js} +1 -1
- package/dist/database.d.ts +1 -1
- package/dist/database.js +15 -9
- package/dist/{definition-EpeI5LUG.js → definition-CvmvHaQT.js} +4 -12
- package/dist/{error-diagnostics-DZHuHXPP.js → error-diagnostics-BpQy1iIO.js} +2 -3
- package/dist/{events-Cm7Iwq47.js → events-aP_Rz_gx.js} +1 -1
- package/dist/{extension-mCx4TrsO.js → extension-B35v_o1u.js} +1 -1
- package/dist/{extension-BWmjJhoN.d.ts → extension-C2giF7w2.d.ts} +1 -1
- package/dist/forward.d.ts +0 -5
- package/dist/forward.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/internal/server.d.ts +2 -2
- package/dist/internal/server.js +4 -4
- package/dist/{mcp-config-Bbr8kQxm.js → mcp-config-DYlTXmr6.js} +1 -1
- package/dist/{mcp-token-BleQZK6H.js → mcp-token-i-8NMulH.js} +3 -4
- package/dist/mcp.d.ts +0 -5
- package/dist/mcp.js +2 -4
- package/dist/{members-7OMdqha_.js → members-USm08YwK.js} +4 -6
- package/dist/nuxt.d.ts +1 -1
- package/dist/nuxt.js +3 -55
- package/dist/{own-access-CGiai2L3.d.ts → own-access-B7VRd92K.d.ts} +1 -1
- package/dist/presets.js +1 -1
- package/dist/{request-Dpq7GO8B.js → request-CdlcvqVc.js} +0 -1
- 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 +1 -1
- package/dist/runtime/empty-definition.d.ts +1 -1
- package/dist/runtime/server.d.ts +3 -3
- package/dist/runtime/server.js +4 -4
- package/dist/runtime/vue-nuxt.js +2 -18
- package/dist/schema.d.ts +1 -4
- package/dist/schema.js +19 -3
- package/dist/{server-DyP1v-sZ.d.ts → server-4_EXgXFn.d.ts} +4 -6
- package/dist/{server-5t-HA7I1.js → server-CZR2dVVp.js} +13 -47
- package/dist/{server-mmp8EfcE.d.ts → server-DAIBBKbR.d.ts} +3 -3
- package/dist/server.d.ts +1 -1
- package/dist/server.js +3 -3
- package/dist/{session-cookies-BNtY3hMp.js → session-cookies-CfXdF1yd.js} +3 -19
- package/dist/{set-cookie-Bva-P-_C.js → set-cookie-BYZslovs.js} +1 -1
- package/dist/{table-specs-Bm7QJCbu.js → table-specs-Cvjc_Ccs.js} +28 -2
- package/dist/{table-specs-BxKeFD_y.d.ts → table-specs-VYAy_jJ7.d.ts} +0 -2
- package/dist/test.d.ts +1 -1
- package/dist/test.js +2 -2
- package/dist/{types-CnO5bHEF.d.ts → types-DakualFJ.d.ts} +1 -3
- package/dist/{vite-7I1bJvqA.js → vite-DVvWaN3D.js} +21 -71
- package/dist/vite.d.ts +3 -5
- package/dist/vite.js +1 -1
- package/dist/vue.d.ts +3 -34
- package/dist/vue.js +4 -65
- package/package.json +9 -8
package/dist/vite.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference path="./host-declarations.d.ts" />
|
|
2
2
|
import { r as resolveNuxtAuthDiscovery } from "./vite-CZ_Z6IR3.js";
|
|
3
|
-
import { V as DiscoveredAuthDefinition, W as ResolvedAuthViteConfig, w as AuthOptions } from "./types-
|
|
3
|
+
import { V as DiscoveredAuthDefinition, W as ResolvedAuthViteConfig, w as AuthOptions } from "./types-DakualFJ.js";
|
|
4
4
|
import { n as ViteHubCliPluginMetadata } from "./cli-DL7uCAvz.js";
|
|
5
5
|
import { Plugin } from "vite";
|
|
6
6
|
interface ViteHubDefinitionField {
|
|
@@ -65,10 +65,6 @@ interface ViteHubInspectionPluginMetadata {
|
|
|
65
65
|
inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
|
|
66
66
|
}
|
|
67
67
|
type LayerRootsByAlias = Readonly<Record<string, string>>;
|
|
68
|
-
/**
|
|
69
|
-
* Whether the Auth Definition of the project keeps users in the app Database with `authDatabase()`. ViteHub turns the
|
|
70
|
-
* Database on for it, as it does for Connections.
|
|
71
|
-
*/
|
|
72
68
|
interface AuthDiscovery {
|
|
73
69
|
projectRoot?: string;
|
|
74
70
|
serverDirs?: readonly string[];
|
|
@@ -163,6 +159,8 @@ export interface AuthDatabaseContribution {
|
|
|
163
159
|
module: string;
|
|
164
160
|
export: "authPostgresSchema" | "authSqliteSchema";
|
|
165
161
|
};
|
|
162
|
+
/** The export of `definition.module` with the Drizzle relations of the Auth tables. */
|
|
163
|
+
relations: "authPostgresRelations" | "authSqliteRelations";
|
|
166
164
|
/** The schema keys and SQL names of the tables, so the Database lists them without loading the schema module. */
|
|
167
165
|
tables: Readonly<Record<string, string>>;
|
|
168
166
|
reason: string;
|
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 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-
|
|
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-DVvWaN3D.js";
|
package/dist/vue.d.ts
CHANGED
|
@@ -1,7 +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-
|
|
4
|
-
import { a as extendAuthClient, i as ExtendedAuthClientOptions, n as AuthClientExtensionOptions, t as AuthClientExtension } from "./client-extension-
|
|
2
|
+
import { a as AbilityRefusal, i as AbilityName, t as AbilityArgs } from "./abilities-6LE7VSdN.js";
|
|
3
|
+
import { S as AuthFor, _ as AuthDefinition } from "./types-DakualFJ.js";
|
|
4
|
+
import { a as extendAuthClient, i as ExtendedAuthClientOptions, n as AuthClientExtensionOptions, t as AuthClientExtension } from "./client-extension-BVBVUqa1.js";
|
|
5
5
|
import { n as AbilityErrorData } from "./ability-error-C1c30O6E.js";
|
|
6
6
|
import { BetterAuthClientOptions } from "better-auth";
|
|
7
7
|
import { ComputedRef, VNode } from "vue";
|
|
@@ -57,10 +57,6 @@ export declare function setSessionSeedResolver(resolver: ((read: boolean) => unk
|
|
|
57
57
|
* `undefined` outside a request.
|
|
58
58
|
*/
|
|
59
59
|
export declare function setRequestFetchResolver(resolver: (() => RequestFetch | undefined) | undefined): void;
|
|
60
|
-
/**
|
|
61
|
-
* The members of a client that the composables read. Every Better Auth Vue client has them. `VueAuthClient<any>`
|
|
62
|
-
* rejects a client with a required additional field, because its `signUp.email()` needs that field.
|
|
63
|
-
*/
|
|
64
60
|
type AuthClientLike = Pick<VueAuthClient$1<{}>, "$fetch" | "getSession"> & {
|
|
65
61
|
$Infer: {
|
|
66
62
|
Session: {
|
|
@@ -99,22 +95,15 @@ export declare function loadAuthClient<Client extends AuthClientLike>(client: Cl
|
|
|
99
95
|
export declare function defineAuthClient<Option extends BetterAuthClientOptions>(options: Option): Option;
|
|
100
96
|
declare global {
|
|
101
97
|
namespace ViteHub {
|
|
102
|
-
/** Generated declarations set `client` to the type of the options in the app's `auth.client.ts`. */
|
|
103
98
|
interface AuthRegistry {}
|
|
104
99
|
}
|
|
105
100
|
}
|
|
106
|
-
/** The client options that generated declarations register from the app's `auth.client.ts`. Without one, none. */
|
|
107
101
|
type RegisteredClientOptions<TRegistry> = TRegistry extends {
|
|
108
102
|
client: infer TOptions;
|
|
109
103
|
} ? 0 extends 1 & TOptions ? {} : TOptions extends BetterAuthClientOptions ? TOptions : {} : {};
|
|
110
|
-
/** The fields that a server plugin's `schema` adds to one table. A plugin without a `schema`, such as `bearer()`, adds none. */
|
|
111
104
|
type ServerPluginTableFields<TSchema, TTable extends "session" | "user"> = TSchema extends { [Key in TTable]: {
|
|
112
105
|
fields: infer TFields extends Record<string, unknown>;
|
|
113
106
|
}; } ? TFields : {};
|
|
114
|
-
/**
|
|
115
|
-
* The endpoints of a server plugin that change the session response, such as the `getSession` of `customSession()`.
|
|
116
|
-
* Better Auth marks them with `CUSTOM_SESSION`. The client keeps no other plugin endpoint.
|
|
117
|
-
*/
|
|
118
107
|
type ServerPluginSessionEndpoints<TEndpoints> = { [Key in keyof TEndpoints as TEndpoints[Key] extends {
|
|
119
108
|
options: {
|
|
120
109
|
metadata: {
|
|
@@ -122,10 +111,6 @@ type ServerPluginSessionEndpoints<TEndpoints> = { [Key in keyof TEndpoints as TE
|
|
|
122
111
|
};
|
|
123
112
|
};
|
|
124
113
|
} ? Key : never]: TEndpoints[Key]; };
|
|
125
|
-
/**
|
|
126
|
-
* A type-only client plugin with the user and session fields of one server plugin, such as the `role` of `admin()`,
|
|
127
|
-
* and the session response of `customSession()`. It keeps only these, so every server plugin gives a valid client plugin.
|
|
128
|
-
*/
|
|
129
114
|
type ServerPluginFields<TPlugin> = TPlugin extends {
|
|
130
115
|
id: infer Id extends string;
|
|
131
116
|
schema?: infer Schema;
|
|
@@ -144,10 +129,6 @@ type ServerPluginFields<TPlugin> = TPlugin extends {
|
|
|
144
129
|
};
|
|
145
130
|
};
|
|
146
131
|
} : never;
|
|
147
|
-
/**
|
|
148
|
-
* Client options with type-only plugins: Better Auth's `inferAdditionalFields()` for `user.additionalFields` and
|
|
149
|
-
* `session.additionalFields`, and the fields of each server plugin.
|
|
150
|
-
*/
|
|
151
132
|
type ServerFieldsClientOptions<TAuth extends {
|
|
152
133
|
options: {
|
|
153
134
|
plugins?: readonly unknown[];
|
|
@@ -155,11 +136,9 @@ type ServerFieldsClientOptions<TAuth extends {
|
|
|
155
136
|
}> = {
|
|
156
137
|
plugins: Array<ReturnType<typeof inferAdditionalFields<TAuth>> | ServerPluginFields<NonNullable<TAuth["options"]["plugins"]>[number]>>;
|
|
157
138
|
};
|
|
158
|
-
/** The plugins of client options, such as the `adminClient()` of `auth.client.ts`. */
|
|
159
139
|
type ClientOptionsPlugins<TOptions> = TOptions extends {
|
|
160
140
|
plugins?: infer TPlugins;
|
|
161
141
|
} ? TPlugins extends readonly (infer TPlugin)[] ? TPlugin : never : never;
|
|
162
|
-
/** The type-only plugins with the fields of the registered Auth Definition and its server plugins. Without one, none. */
|
|
163
142
|
type RegisteredServerFieldsPlugins<TRegistry> = TRegistry extends {
|
|
164
143
|
definition: infer TDefinition extends AuthDefinition;
|
|
165
144
|
} ? 0 extends 1 & TDefinition ? never : ServerFieldsClientOptions<AuthFor<TDefinition>>["plugins"][number] : never;
|
|
@@ -171,23 +150,14 @@ type RegisteredServerFieldsPlugins<TRegistry> = TRegistry extends {
|
|
|
171
150
|
export type RegisteredAuthClient<TRegistry = ViteHub.AuthRegistry> = ServerFieldsClient<Omit<RegisteredClientOptions<TRegistry>, "plugins"> & {
|
|
172
151
|
plugins: Array<ClientOptionsPlugins<RegisteredClientOptions<TRegistry>> | RegisteredServerFieldsPlugins<TRegistry>>;
|
|
173
152
|
}>;
|
|
174
|
-
/** A client that Better Auth cannot type with these options keeps the plain fields, so `user` never becomes `never`. */
|
|
175
153
|
type ServerFieldsClient<TOptions> = TOptions extends BetterAuthClientOptions ? VueAuthClient$1<TOptions> : VueAuthClient$1<{}>;
|
|
176
|
-
/**
|
|
177
|
-
* The client that the composables and the Nuxt page guard share. On first use, it loads `better-auth/vue` and the app's
|
|
178
|
-
* `auth.client.ts` together, and the options of that file replace the defaults. In Nuxt, the default `basePath` is the
|
|
179
|
-
* Auth Definition's `basePath` below the `app.baseURL` of the page, also when `NUXT_APP_BASE_URL` sets it at runtime.
|
|
180
|
-
*/
|
|
181
154
|
export declare const authClient: RegisteredAuthClient;
|
|
182
155
|
/** Provide the app's configured client to Auth composables and `<AuthPermission>` in descendant components. */
|
|
183
156
|
export declare function provideAuthClient(client: AuthClientLike): void;
|
|
184
157
|
export declare function useAuthClient(): typeof authClient;
|
|
185
158
|
type ClientSession<Client extends AuthClientLike> = Client["$Infer"]["Session"];
|
|
186
|
-
/** Better Auth's `signOut()` of `Client`. */
|
|
187
159
|
type ClientSignOut<Client extends AuthClientLike> = Extract<Client["signOut"], (...args: never) => unknown>;
|
|
188
|
-
/** The parameters of Better Auth's `signOut()` of `Client`. */
|
|
189
160
|
type SignOutParameters<Client extends AuthClientLike> = Parameters<ClientSignOut<Client>>;
|
|
190
|
-
/** The result of Better Auth's `signOut()` of `Client`. */
|
|
191
161
|
type SignOutResult<Client extends AuthClientLike> = ReturnType<ClientSignOut<Client>>;
|
|
192
162
|
/** The options of `signOut()` from `useUserSession()`: the options of Better Auth's `signOut()`, and `redirectTo`. */
|
|
193
163
|
export type SignOutOptions<Client extends AuthClientLike = typeof authClient> = NonNullable<SignOutParameters<Client>[0]> & {
|
|
@@ -269,7 +239,6 @@ export interface Ability {
|
|
|
269
239
|
* await authorize("posts.edit", loadedPost)
|
|
270
240
|
*/
|
|
271
241
|
export declare function useAbility(client?: AuthClientLike): Ability;
|
|
272
|
-
/** The rule arguments use the same tuple as the server check. */
|
|
273
242
|
type PermissionArguments<Args extends unknown[]> = [] extends Args ? {
|
|
274
243
|
args?: Args;
|
|
275
244
|
} : {
|
package/dist/vue.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as checkAbility, t as AbilityError } from "./ability-error-
|
|
2
|
-
import { t as authErrorDiagnostics } from "./error-diagnostics-
|
|
3
|
-
import { n as assertUniquePluginIds } from "./extension-
|
|
4
|
-
import { i as resolveAuthMountPath } from "./application-path-
|
|
1
|
+
import { n as checkAbility, t as AbilityError } from "./ability-error-Ccm5Iy4F.js";
|
|
2
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-BpQy1iIO.js";
|
|
3
|
+
import { n as assertUniquePluginIds } from "./extension-B35v_o1u.js";
|
|
4
|
+
import { i as resolveAuthMountPath } from "./application-path-LMc_ptL9.js";
|
|
5
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";
|
|
6
6
|
import abilities from "#vitehub/auth/abilities";
|
|
7
7
|
import { computed, defineComponent, effectScope, getCurrentInstance, getCurrentScope, inject, onScopeDispose, onServerPrefetch, provide, shallowRef, watch } from "vue";
|
|
@@ -44,7 +44,6 @@ const ON_LOAD = Symbol.for("vitehub.auth.client.on-load");
|
|
|
44
44
|
const OPTIONS = Symbol.for("vitehub.auth.client.options");
|
|
45
45
|
const authClientKey = Symbol("vitehub.auth.client");
|
|
46
46
|
const signOutListeners = /* @__PURE__ */ new Set();
|
|
47
|
-
/** The state of a client hook, such as `useSession()`, before Better Auth's client has loaded. */
|
|
48
47
|
const pendingState = (refetch) => ({
|
|
49
48
|
data: null,
|
|
50
49
|
error: null,
|
|
@@ -65,20 +64,12 @@ const pendingState = (refetch) => ({
|
|
|
65
64
|
* During Nuxt server rendering, a call such as `listSessions()` reaches the app in-process with the visitor's cookie.
|
|
66
65
|
*/
|
|
67
66
|
const createAuthClient = (options) => createLazyAuthClient(() => withDefaultBasePath(options), () => options);
|
|
68
|
-
/**
|
|
69
|
-
* The options with ViteHub's default `basePath` when they set none: in Nuxt, the Auth Definition's `basePath` below
|
|
70
|
-
* `app.baseURL`. Read when Better Auth loads, after the Nuxt module set it.
|
|
71
|
-
*/
|
|
72
67
|
function withDefaultBasePath(options) {
|
|
73
68
|
return {
|
|
74
69
|
basePath: authNuxtBridge.defaultBasePath ?? resolveAuthMountPath("/api/auth"),
|
|
75
70
|
...options
|
|
76
71
|
};
|
|
77
72
|
}
|
|
78
|
-
/**
|
|
79
|
-
* The client of `createAuthClient()`. It runs `resolveOptions` when it loads Better Auth. `knownOptions` returns the
|
|
80
|
-
* options known before the load, such as `sessionOptions`, without loading anything.
|
|
81
|
-
*/
|
|
82
73
|
function createLazyAuthClient(resolveOptions, knownOptions = () => void 0) {
|
|
83
74
|
let loaded;
|
|
84
75
|
let betterAuth;
|
|
@@ -97,11 +88,6 @@ function createLazyAuthClient(resolveOptions, knownOptions = () => void 0) {
|
|
|
97
88
|
else onLoad.add(run);
|
|
98
89
|
};
|
|
99
90
|
const requestClients = /* @__PURE__ */ new WeakMap();
|
|
100
|
-
/**
|
|
101
|
-
* Better Auth's client for a call. On the server, during a request, it calls the app in-process with the visitor's
|
|
102
|
-
* cookie. A client with its own `baseURL` or `customFetchImpl` keeps them. Call it before the caller's first `await`,
|
|
103
|
-
* because only the caller's frame knows the request.
|
|
104
|
-
*/
|
|
105
91
|
function loadForCall() {
|
|
106
92
|
const request = "window" in globalThis ? void 0 : authNuxtBridge.requestFetchResolver?.();
|
|
107
93
|
if (!request) return load();
|
|
@@ -170,18 +156,11 @@ function createLazyAuthClient(resolveOptions, knownOptions = () => void 0) {
|
|
|
170
156
|
function isPendingWithoutData(value) {
|
|
171
157
|
return typeof value === "object" && value !== null && Reflect.get(value, "isPending") === true && !Reflect.get(value, "data");
|
|
172
158
|
}
|
|
173
|
-
/** Run `run` in the scope the hook was called in, so its watchers stop with the component that called it. */
|
|
174
159
|
function runIn(scope, run) {
|
|
175
160
|
return scope ? scope.run(run) : run();
|
|
176
161
|
}
|
|
177
|
-
/** The owner of the stores in the browser: one page has one session per client. */
|
|
178
162
|
const browserOwner = {};
|
|
179
163
|
const stores = /* @__PURE__ */ new WeakMap();
|
|
180
|
-
/**
|
|
181
|
-
* The session store of `client` for the current app. The browser has one store per client. The server has one per
|
|
182
|
-
* request, through the request's Nuxt app or Vue app, so two requests never share a session. On the server, a call
|
|
183
|
-
* outside an app, such as at module scope, gets a store of its own.
|
|
184
|
-
*/
|
|
185
164
|
function sessionStore(client) {
|
|
186
165
|
const browser = "window" in globalThis;
|
|
187
166
|
const app = browser ? void 0 : authNuxtBridge.nuxtAppResolver?.();
|
|
@@ -222,7 +201,6 @@ function createSessionStore(client, app, initialRead) {
|
|
|
222
201
|
async function refetch(query) {
|
|
223
202
|
await read(query);
|
|
224
203
|
}
|
|
225
|
-
/** Settles the state with the server's session. A promise of it, such as a read still in flight, is the read. */
|
|
226
204
|
function seed(read) {
|
|
227
205
|
if (seeded) return;
|
|
228
206
|
const value = authNuxtBridge.sessionSeedResolver?.(read);
|
|
@@ -240,17 +218,12 @@ function createSessionStore(client, app, initialRead) {
|
|
|
240
218
|
function serverRead() {
|
|
241
219
|
return !browser && state.value.isPending ? serverReading : void 0;
|
|
242
220
|
}
|
|
243
|
-
/** Makes `read` the read that callers share, until it ends or `clear()` runs. */
|
|
244
221
|
function share(read) {
|
|
245
222
|
const shared = read.finally(() => {
|
|
246
223
|
if (reading === shared) reading = void 0;
|
|
247
224
|
});
|
|
248
225
|
return shared;
|
|
249
226
|
}
|
|
250
|
-
/**
|
|
251
|
-
* Follows Better Auth's session atom with one watcher. It runs when Better Auth loads, before the first call of the
|
|
252
|
-
* client runs, so the session signal of that call, such as after `signOut()`, reaches the state.
|
|
253
|
-
*/
|
|
254
227
|
function connect(loaded) {
|
|
255
228
|
if (atom) return atom;
|
|
256
229
|
stopWaking?.();
|
|
@@ -277,11 +250,6 @@ function createSessionStore(client, app, initialRead) {
|
|
|
277
250
|
});
|
|
278
251
|
return atom;
|
|
279
252
|
}
|
|
280
|
-
/**
|
|
281
|
-
* Waits for the session signal of a client that loaded before the store, such as one from `loadAuthClient()`, and then
|
|
282
|
-
* follows its session atom. Better Auth sends the signal after a call that changes the session, such as a sign-in.
|
|
283
|
-
* Waiting costs no read.
|
|
284
|
-
*/
|
|
285
253
|
function followSignal(loaded) {
|
|
286
254
|
const signal = storeAtom(loaded, "$sessionSignal");
|
|
287
255
|
if (!signal) {
|
|
@@ -290,7 +258,6 @@ function createSessionStore(client, app, initialRead) {
|
|
|
290
258
|
}
|
|
291
259
|
stopSignal = signal.listen(() => void connect(loaded));
|
|
292
260
|
}
|
|
293
|
-
/** Loads Better Auth in the browser and follows its session atom. */
|
|
294
261
|
async function follow() {
|
|
295
262
|
return atom ?? connect(await loadAuthClient(client));
|
|
296
263
|
}
|
|
@@ -355,15 +322,10 @@ function createSessionStore(client, app, initialRead) {
|
|
|
355
322
|
scope
|
|
356
323
|
};
|
|
357
324
|
}
|
|
358
|
-
/**
|
|
359
|
-
* An atom of Better Auth's `$store` of a loaded client, such as `session` or `$sessionSignal`. Better Auth answers
|
|
360
|
-
* `$store` and `atoms` with path proxies, and a missing atom with a function.
|
|
361
|
-
*/
|
|
362
325
|
function storeAtom(loaded, name) {
|
|
363
326
|
const value = Reflect.get(Object(Reflect.get(Object(Reflect.get(loaded, "$store")), "atoms")), name);
|
|
364
327
|
return typeof value === "object" && value !== null ? value : void 0;
|
|
365
328
|
}
|
|
366
|
-
/** Sets Better Auth's session atom of `loaded` to no session, settled. */
|
|
367
329
|
function clearAtom(loaded) {
|
|
368
330
|
const session = storeAtom(loaded, "session");
|
|
369
331
|
session?.set({
|
|
@@ -374,17 +336,8 @@ function clearAtom(loaded) {
|
|
|
374
336
|
isRefetching: false
|
|
375
337
|
});
|
|
376
338
|
}
|
|
377
|
-
/** The longest delay that `setTimeout()` keeps. It runs a longer delay at once. */
|
|
378
339
|
const maxTimerDelay = 2 ** 31 - 1;
|
|
379
|
-
/** Better Auth's channel to other tabs: a tab writes this `localStorage` key when it signs out or updates the user or session. */
|
|
380
340
|
const sessionChannelKey = "better-auth.message";
|
|
381
|
-
/**
|
|
382
|
-
* Calls `wake` at the moments when Better Auth reads the session again: the tab shows again (unless
|
|
383
|
-
* `refetchOnWindowFocus` is `false`), the network comes back, another tab changes the session, `refetchInterval`
|
|
384
|
-
* passes, or the session expires. Like Better Auth, it waits while the browser is offline, unless `refetchWhenOffline`
|
|
385
|
-
* is `true`: Better Auth could not load then, and the `online` event wakes it later. Returns a function that removes
|
|
386
|
-
* the listeners.
|
|
387
|
-
*/
|
|
388
341
|
function wakeWhenSessionCanChange(options, seed, wake) {
|
|
389
342
|
const stops = [];
|
|
390
343
|
const { document: page, navigator, window } = globalThis;
|
|
@@ -431,11 +384,6 @@ async function loadAuthClient(client) {
|
|
|
431
384
|
function defineAuthClient(options) {
|
|
432
385
|
return options;
|
|
433
386
|
}
|
|
434
|
-
/**
|
|
435
|
-
* The client that the composables and the Nuxt page guard share. On first use, it loads `better-auth/vue` and the app's
|
|
436
|
-
* `auth.client.ts` together, and the options of that file replace the defaults. In Nuxt, the default `basePath` is the
|
|
437
|
-
* Auth Definition's `basePath` below the `app.baseURL` of the page, also when `NUXT_APP_BASE_URL` sets it at runtime.
|
|
438
|
-
*/
|
|
439
387
|
const authClient = createLazyAuthClient(async () => {
|
|
440
388
|
const { default: options, extensions } = await import("#vitehub/auth/client");
|
|
441
389
|
return withDefaultBasePath(applyAuthClientExtensions(options, extensions));
|
|
@@ -450,7 +398,6 @@ function useAuthClient() {
|
|
|
450
398
|
const nuxtApp = authNuxtBridge.nuxtAppResolver?.() || instance?.appContext.config.globalProperties.$nuxt;
|
|
451
399
|
return client ?? nuxtApp?.$vitehubAuthClient ?? authClient;
|
|
452
400
|
}
|
|
453
|
-
/** The session state of `client`, which `useUserSession()`, `useAbility()`, and the page guard share. */
|
|
454
401
|
function sessionState(client = useAuthClient()) {
|
|
455
402
|
return sessionStore(client).state;
|
|
456
403
|
}
|
|
@@ -503,7 +450,6 @@ function onSignOut(listener) {
|
|
|
503
450
|
signOutListeners.delete(listener);
|
|
504
451
|
};
|
|
505
452
|
}
|
|
506
|
-
/** `value` when it is an object, else an empty one, to spread fetch options that a caller may leave out. */
|
|
507
453
|
function record(value) {
|
|
508
454
|
return typeof value === "object" && value !== null ? { ...value } : {};
|
|
509
455
|
}
|
|
@@ -557,17 +503,10 @@ async function signOut(client, store, options = {}, fetchOptions = []) {
|
|
|
557
503
|
else if (redirectTo) location?.assign(redirectTo);
|
|
558
504
|
return result;
|
|
559
505
|
}
|
|
560
|
-
/** The refusal of a rule for the visitor: `undefined` while the session is unknown, `null` when the rule allows. */
|
|
561
506
|
function abilityRefusal(state, name, args) {
|
|
562
507
|
if (state.isPending) return void 0;
|
|
563
508
|
return checkAbility(abilities, state.data?.user ?? null, name, args);
|
|
564
509
|
}
|
|
565
|
-
/**
|
|
566
|
-
* The user that `authorize()` checks. The server uses the session it read for the request. While Nuxt hydrates, the
|
|
567
|
-
* browser uses the same session, so it decides as the server did. Otherwise the browser asks the client of
|
|
568
|
-
* `useAbility()`, because a sign-in or sign-out in the tab makes the server's session old. In Nuxt, that is the client of
|
|
569
|
-
* the page guard, at the configured Auth `basePath` below `app.baseURL`.
|
|
570
|
-
*/
|
|
571
510
|
async function authorizedUser(client, state) {
|
|
572
511
|
const known = !state.value.isPending;
|
|
573
512
|
if (!("window" in globalThis) || known && authNuxtBridge.nuxtAppResolver?.()?.isHydrating) return state.value.data?.user ?? null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Better Auth-powered authentication primitives and Vite integration for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"auth",
|
|
@@ -142,11 +142,12 @@
|
|
|
142
142
|
"./package.json": "./package.json"
|
|
143
143
|
},
|
|
144
144
|
"dependencies": {
|
|
145
|
+
"@better-auth/drizzle-adapter": "1.7.27",
|
|
145
146
|
"@noble/hashes": "^2.4.0",
|
|
146
147
|
"@types/node": "^24.19.2",
|
|
147
|
-
"@vite-hub/env": "0.
|
|
148
|
-
"@vite-hub/runtime": "0.
|
|
149
|
-
"@vite-hub/web-container": "0.
|
|
148
|
+
"@vite-hub/env": "0.9.0",
|
|
149
|
+
"@vite-hub/runtime": "0.9.0",
|
|
150
|
+
"@vite-hub/web-container": "0.9.0",
|
|
150
151
|
"better-auth": "^1.7.27",
|
|
151
152
|
"better-auth-rou3": "npm:rou3@0.9.2",
|
|
152
153
|
"h3": "^2.0.8",
|
|
@@ -166,8 +167,8 @@
|
|
|
166
167
|
"@types/json-schema": "^7.0.15",
|
|
167
168
|
"@types/mdast": "^4.0.4",
|
|
168
169
|
"@types/node": "^24.19.2",
|
|
169
|
-
"@vite-hub/agent": "0.
|
|
170
|
-
"@vite-hub/database": "0.
|
|
170
|
+
"@vite-hub/agent": "0.9.0",
|
|
171
|
+
"@vite-hub/database": "0.9.0",
|
|
171
172
|
"@vite-hub/internal": "0.0.1",
|
|
172
173
|
"bun-types": "^1.4.5",
|
|
173
174
|
"evlog": "2.37.1",
|
|
@@ -190,8 +191,8 @@
|
|
|
190
191
|
"@better-auth/oauth-provider": "^1.7.27",
|
|
191
192
|
"@types/json-schema": "^7.0.15",
|
|
192
193
|
"@types/mdast": "^4.0.4",
|
|
193
|
-
"@vite-hub/agent": "0.
|
|
194
|
-
"@vite-hub/database": "0.
|
|
194
|
+
"@vite-hub/agent": "0.9.0",
|
|
195
|
+
"@vite-hub/database": "0.9.0",
|
|
195
196
|
"nitro": "3.0.261102-rc || ^3.0.261103-rc",
|
|
196
197
|
"vite": ">=8.0.0",
|
|
197
198
|
"vue": "^3.5.0",
|