@onmax/nuxt-better-auth 0.0.2-alpha.3 → 0.0.2-alpha.31
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/module.d.mts +28 -1
- package/dist/module.json +2 -2
- package/dist/module.mjs +965 -313
- package/dist/runtime/app/components/BetterAuthState.vue +1 -0
- package/dist/runtime/app/composables/useAction.d.ts +2 -0
- package/dist/runtime/app/composables/useAction.js +6 -0
- package/dist/runtime/app/composables/useAuthAsyncData.d.ts +6 -0
- package/dist/runtime/app/composables/useAuthAsyncData.js +16 -0
- package/dist/runtime/app/composables/useAuthClientAction.d.ts +5 -0
- package/dist/runtime/app/composables/useAuthClientAction.js +15 -0
- package/dist/runtime/app/composables/useAuthRequestFetch.d.ts +11 -0
- package/dist/runtime/app/composables/useAuthRequestFetch.js +4 -0
- package/dist/runtime/app/composables/useSignIn.d.ts +16 -0
- package/dist/runtime/app/composables/useSignIn.js +8 -0
- package/dist/runtime/app/composables/useSignUp.d.ts +5 -0
- package/dist/runtime/app/composables/useSignUp.js +8 -0
- package/dist/runtime/app/composables/useUserSession.d.ts +14 -12
- package/dist/runtime/app/composables/useUserSession.js +162 -67
- package/dist/runtime/app/internal/auth-action-error.d.ts +3 -0
- package/dist/runtime/app/internal/auth-action-error.js +33 -0
- package/dist/runtime/app/internal/auth-action-handles.d.ts +18 -0
- package/dist/runtime/app/internal/auth-action-handles.js +105 -0
- package/dist/runtime/app/internal/redirect-helpers.d.ts +4 -0
- package/dist/runtime/app/internal/redirect-helpers.js +37 -0
- package/dist/runtime/app/internal/session-fetch.d.ts +12 -0
- package/dist/runtime/app/internal/session-fetch.js +56 -0
- package/dist/runtime/app/internal/utils.d.ts +1 -0
- package/dist/runtime/app/internal/utils.js +3 -0
- package/dist/runtime/app/internal/wrap-auth-method.d.ts +15 -0
- package/dist/runtime/app/internal/wrap-auth-method.js +66 -0
- package/dist/runtime/app/middleware/auth.global.js +73 -12
- package/dist/runtime/app/pages/__better-auth-devtools.vue +4 -10
- package/dist/runtime/app/plugins/session.client.js +1 -2
- package/dist/runtime/config.d.ts +66 -11
- package/dist/runtime/config.js +9 -2
- package/dist/runtime/server/api/_better-auth/_schema.js +2 -1
- package/dist/runtime/server/api/_better-auth/accounts.get.js +3 -2
- package/dist/runtime/server/api/_better-auth/config.get.d.ts +17 -11
- package/dist/runtime/server/api/_better-auth/config.get.js +17 -5
- package/dist/runtime/server/api/_better-auth/sessions.delete.js +3 -2
- package/dist/runtime/server/api/_better-auth/sessions.get.d.ts +3 -1
- package/dist/runtime/server/api/_better-auth/sessions.get.js +3 -2
- package/dist/runtime/server/api/_better-auth/users.get.js +3 -2
- package/dist/runtime/server/api/auth/[...all].js +1 -1
- package/dist/runtime/server/middleware/route-access.js +1 -0
- package/dist/runtime/server/tsconfig.json +9 -1
- package/dist/runtime/server/utils/auth.d.ts +5 -7
- package/dist/runtime/server/utils/auth.js +197 -17
- package/dist/runtime/server/utils/custom-secondary-storage.d.ts +6 -0
- package/dist/runtime/server/utils/custom-secondary-storage.js +8 -0
- package/dist/runtime/server/utils/session.d.ts +4 -8
- package/dist/runtime/server/utils/session.js +43 -4
- package/dist/runtime/server/virtual-modules.d.ts +22 -0
- package/dist/runtime/types/augment.d.ts +18 -2
- package/dist/runtime/types.d.ts +12 -13
- package/dist/types.d.mts +1 -1
- package/package.json +32 -42
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { H3Event } from 'h3';
|
|
2
|
+
import createServerAuth from '#auth/server';
|
|
2
3
|
import { betterAuth } from 'better-auth';
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export declare function serverAuth(event: H3Event): Promise<AuthInstance>;
|
|
4
|
+
type AuthOptions = ReturnType<typeof createServerAuth>;
|
|
5
|
+
type AuthInstance = ReturnType<typeof betterAuth<AuthOptions>>;
|
|
6
|
+
/** Returns Better Auth instance. Caches per resolved host (or single instance when siteUrl is explicit). */
|
|
7
|
+
export declare function serverAuth(event?: H3Event): AuthInstance;
|
|
10
8
|
export {};
|
|
@@ -2,31 +2,211 @@ import { createDatabase, db } from "#auth/database";
|
|
|
2
2
|
import { createSecondaryStorage } from "#auth/secondary-storage";
|
|
3
3
|
import createServerAuth from "#auth/server";
|
|
4
4
|
import { betterAuth } from "better-auth";
|
|
5
|
-
import {
|
|
6
|
-
import { getRequestURL } from "h3";
|
|
5
|
+
import { getRequestHost, getRequestProtocol } from "h3";
|
|
7
6
|
import { useRuntimeConfig } from "nitropack/runtime";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
import { withoutProtocol } from "ufo";
|
|
8
|
+
import { resolveCustomSecondaryStorageRequirement } from "./custom-secondary-storage.js";
|
|
9
|
+
const _authCache = /* @__PURE__ */ new Map();
|
|
10
|
+
let _baseURLInferenceLogged = false;
|
|
11
|
+
let _customSecondaryStorageMisconfigWarned = false;
|
|
12
|
+
function normalizeLoopbackOrigin(origin) {
|
|
13
|
+
if (!import.meta.dev)
|
|
14
|
+
return origin;
|
|
15
|
+
try {
|
|
16
|
+
const url = new URL(origin);
|
|
17
|
+
if (url.hostname === "127.0.0.1" || url.hostname === "::1" || url.hostname === "[::1]") {
|
|
18
|
+
url.hostname = "localhost";
|
|
19
|
+
return url.origin;
|
|
20
|
+
}
|
|
21
|
+
} catch {
|
|
22
|
+
}
|
|
16
23
|
return origin;
|
|
17
24
|
}
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
25
|
+
function logInferredBaseURL(baseURL, source) {
|
|
26
|
+
if (!import.meta.dev || _baseURLInferenceLogged)
|
|
27
|
+
return;
|
|
28
|
+
_baseURLInferenceLogged = true;
|
|
29
|
+
console.warn(`[nuxt-better-auth] Using inferred baseURL "${baseURL}" from ${source}. Set runtimeConfig.public.siteUrl for deterministic OAuth callbacks.`);
|
|
30
|
+
}
|
|
31
|
+
function validateURL(url) {
|
|
32
|
+
try {
|
|
33
|
+
return normalizeLoopbackOrigin(new URL(url).origin);
|
|
34
|
+
} catch {
|
|
35
|
+
throw new Error(`Invalid siteUrl: "${url}". Must be a valid URL.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function resolveConfiguredSiteUrl(config) {
|
|
39
|
+
if (typeof config.public.siteUrl !== "string" || !config.public.siteUrl)
|
|
40
|
+
return void 0;
|
|
41
|
+
return validateURL(config.public.siteUrl);
|
|
42
|
+
}
|
|
43
|
+
function resolveEventOrigin(event) {
|
|
44
|
+
if (!event)
|
|
45
|
+
return void 0;
|
|
46
|
+
const host = getRequestHost(event, { xForwardedHost: true });
|
|
47
|
+
const protocol = getRequestProtocol(event, { xForwardedProto: true });
|
|
48
|
+
if (!host || !protocol)
|
|
49
|
+
return void 0;
|
|
50
|
+
try {
|
|
51
|
+
return validateURL(`${protocol}://${host}`);
|
|
52
|
+
} catch {
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function getNitroOrigin() {
|
|
57
|
+
const cert = process.env.NITRO_SSL_CERT;
|
|
58
|
+
const key = process.env.NITRO_SSL_KEY;
|
|
59
|
+
let host = process.env.NITRO_HOST || process.env.HOST;
|
|
60
|
+
let port;
|
|
61
|
+
if (import.meta.dev)
|
|
62
|
+
port = process.env.NITRO_PORT || process.env.PORT || "3000";
|
|
63
|
+
let protocol = cert && key || !import.meta.dev ? "https" : "http";
|
|
64
|
+
try {
|
|
65
|
+
if ((import.meta.dev || import.meta.prerender) && process.env.__NUXT_DEV__) {
|
|
66
|
+
const origin = JSON.parse(process.env.__NUXT_DEV__).proxy.url;
|
|
67
|
+
host = withoutProtocol(origin);
|
|
68
|
+
protocol = origin.includes("https") ? "https" : "http";
|
|
69
|
+
} else if ((import.meta.dev || import.meta.prerender) && process.env.NUXT_VITE_NODE_OPTIONS) {
|
|
70
|
+
const origin = JSON.parse(process.env.NUXT_VITE_NODE_OPTIONS).baseURL.replace("/__nuxt_vite_node__", "");
|
|
71
|
+
host = withoutProtocol(origin);
|
|
72
|
+
protocol = origin.includes("https") ? "https" : "http";
|
|
73
|
+
}
|
|
74
|
+
} catch {
|
|
75
|
+
}
|
|
76
|
+
if (!host)
|
|
77
|
+
return void 0;
|
|
78
|
+
if (host.startsWith("[") && host.includes("]:")) {
|
|
79
|
+
const lastBracketColon = host.lastIndexOf("]:");
|
|
80
|
+
const extractedPort = host.slice(lastBracketColon + 2);
|
|
81
|
+
host = host.slice(0, lastBracketColon + 1);
|
|
82
|
+
if (extractedPort)
|
|
83
|
+
port = extractedPort;
|
|
84
|
+
} else if (host.includes(":") && !host.startsWith("[")) {
|
|
85
|
+
const hostParts = host.split(":");
|
|
86
|
+
port = hostParts.pop();
|
|
87
|
+
host = hostParts.join(":");
|
|
88
|
+
}
|
|
89
|
+
const portSuffix = port ? `:${port}` : "";
|
|
90
|
+
return `${protocol}://${host}${portSuffix}`;
|
|
91
|
+
}
|
|
92
|
+
function resolveEnvironmentOrigin() {
|
|
93
|
+
const nitroOrigin = getNitroOrigin();
|
|
94
|
+
if (nitroOrigin)
|
|
95
|
+
return { origin: validateURL(nitroOrigin), source: "Nitro environment detection" };
|
|
96
|
+
if (process.env.VERCEL_URL)
|
|
97
|
+
return { origin: validateURL(`https://${process.env.VERCEL_URL}`), source: "VERCEL_URL" };
|
|
98
|
+
if (process.env.CF_PAGES_URL)
|
|
99
|
+
return { origin: validateURL(`https://${process.env.CF_PAGES_URL}`), source: "CF_PAGES_URL" };
|
|
100
|
+
if (process.env.URL)
|
|
101
|
+
return { origin: validateURL(process.env.URL.startsWith("http") ? process.env.URL : `https://${process.env.URL}`), source: "URL" };
|
|
102
|
+
return void 0;
|
|
103
|
+
}
|
|
104
|
+
function resolveDevFallback() {
|
|
105
|
+
if (!import.meta.dev)
|
|
106
|
+
return void 0;
|
|
107
|
+
return { origin: "http://localhost:3000", source: "development fallback" };
|
|
108
|
+
}
|
|
109
|
+
function getBaseURL(event) {
|
|
110
|
+
const config = useRuntimeConfig();
|
|
111
|
+
const configuredSiteUrl = resolveConfiguredSiteUrl(config);
|
|
112
|
+
if (configuredSiteUrl)
|
|
113
|
+
return configuredSiteUrl;
|
|
114
|
+
const eventOrigin = resolveEventOrigin(event);
|
|
115
|
+
if (eventOrigin) {
|
|
116
|
+
logInferredBaseURL(eventOrigin, "request origin");
|
|
117
|
+
return eventOrigin;
|
|
118
|
+
}
|
|
119
|
+
const environmentOrigin = resolveEnvironmentOrigin();
|
|
120
|
+
if (environmentOrigin) {
|
|
121
|
+
logInferredBaseURL(environmentOrigin.origin, environmentOrigin.source);
|
|
122
|
+
return environmentOrigin.origin;
|
|
123
|
+
}
|
|
124
|
+
const devFallback = resolveDevFallback();
|
|
125
|
+
if (devFallback) {
|
|
126
|
+
logInferredBaseURL(devFallback.origin, devFallback.source);
|
|
127
|
+
return devFallback.origin;
|
|
128
|
+
}
|
|
129
|
+
throw new Error("siteUrl required. Set NUXT_PUBLIC_SITE_URL.");
|
|
130
|
+
}
|
|
131
|
+
function dedupeOrigins(origins) {
|
|
132
|
+
return [...new Set(origins)];
|
|
133
|
+
}
|
|
134
|
+
function getDevTrustedOrigins() {
|
|
135
|
+
const fallbackOrigin = "http://localhost:3000";
|
|
136
|
+
const nitroOrigin = getNitroOrigin();
|
|
137
|
+
if (!nitroOrigin)
|
|
138
|
+
return [fallbackOrigin];
|
|
139
|
+
try {
|
|
140
|
+
const url = new URL(nitroOrigin);
|
|
141
|
+
const protocol = url.protocol === "https:" ? "https" : "http";
|
|
142
|
+
const port = url.port || "3000";
|
|
143
|
+
const localhostOrigin = `${protocol}://localhost:${port}`;
|
|
144
|
+
return dedupeOrigins([localhostOrigin, url.origin]);
|
|
145
|
+
} catch {
|
|
146
|
+
return [fallbackOrigin];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function getRequestOrigin(request) {
|
|
150
|
+
if (!request)
|
|
151
|
+
return void 0;
|
|
152
|
+
try {
|
|
153
|
+
return new URL(request.url).origin;
|
|
154
|
+
} catch {
|
|
155
|
+
return void 0;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function withDevTrustedOrigins(trustedOrigins, hasExplicitSiteUrl) {
|
|
159
|
+
if (!import.meta.dev || !hasExplicitSiteUrl)
|
|
160
|
+
return trustedOrigins;
|
|
161
|
+
const devOrigins = getDevTrustedOrigins();
|
|
162
|
+
const mergeOrigins = (origins, request) => {
|
|
163
|
+
const validOrigins = origins.filter((origin) => typeof origin === "string");
|
|
164
|
+
const requestOrigin = getRequestOrigin(request);
|
|
165
|
+
return dedupeOrigins(requestOrigin ? [...validOrigins, ...devOrigins, requestOrigin] : [...validOrigins, ...devOrigins]);
|
|
166
|
+
};
|
|
167
|
+
if (typeof trustedOrigins === "function") {
|
|
168
|
+
return async (request) => {
|
|
169
|
+
const resolvedOrigins = await trustedOrigins(request);
|
|
170
|
+
return mergeOrigins(resolvedOrigins, request);
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
if (Array.isArray(trustedOrigins)) {
|
|
174
|
+
const baseOrigins = mergeOrigins(trustedOrigins);
|
|
175
|
+
return async (request) => {
|
|
176
|
+
return mergeOrigins(baseOrigins, request);
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
return async (request) => {
|
|
180
|
+
return mergeOrigins([], request);
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
export function serverAuth(event) {
|
|
21
184
|
const runtimeConfig = useRuntimeConfig();
|
|
185
|
+
const siteUrl = getBaseURL(event);
|
|
186
|
+
const hasExplicitSiteUrl = runtimeConfig.public.siteUrl && typeof runtimeConfig.public.siteUrl === "string";
|
|
187
|
+
const cacheKey = hasExplicitSiteUrl ? "__explicit__" : siteUrl;
|
|
188
|
+
const cached = _authCache.get(cacheKey);
|
|
189
|
+
if (cached)
|
|
190
|
+
return cached;
|
|
22
191
|
const database = createDatabase();
|
|
23
192
|
const userConfig = createServerAuth({ runtimeConfig, db });
|
|
24
|
-
|
|
193
|
+
const trustedOrigins = withDevTrustedOrigins(userConfig.trustedOrigins, Boolean(hasExplicitSiteUrl));
|
|
194
|
+
const hubSecondaryStorage = runtimeConfig.auth?.hubSecondaryStorage;
|
|
195
|
+
const customSecondaryStorage = resolveCustomSecondaryStorageRequirement(hubSecondaryStorage, userConfig.secondaryStorage != null, Boolean(import.meta.dev));
|
|
196
|
+
if (customSecondaryStorage?.shouldThrow)
|
|
197
|
+
throw new Error(customSecondaryStorage.message);
|
|
198
|
+
if (customSecondaryStorage?.shouldWarn && !_customSecondaryStorageMisconfigWarned) {
|
|
199
|
+
_customSecondaryStorageMisconfigWarned = true;
|
|
200
|
+
console.warn(customSecondaryStorage.message);
|
|
201
|
+
}
|
|
202
|
+
const auth = betterAuth({
|
|
25
203
|
...userConfig,
|
|
26
204
|
...database && { database },
|
|
27
|
-
secondaryStorage: createSecondaryStorage(),
|
|
205
|
+
...hubSecondaryStorage === true && { secondaryStorage: createSecondaryStorage() },
|
|
28
206
|
secret: runtimeConfig.betterAuthSecret,
|
|
29
|
-
baseURL:
|
|
207
|
+
baseURL: siteUrl,
|
|
208
|
+
trustedOrigins
|
|
30
209
|
});
|
|
31
|
-
|
|
210
|
+
_authCache.set(cacheKey, auth);
|
|
211
|
+
return auth;
|
|
32
212
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type HubSecondaryStorageMode = boolean | 'custom' | undefined;
|
|
2
|
+
export declare function resolveCustomSecondaryStorageRequirement(hubSecondaryStorage: HubSecondaryStorageMode, userHasSecondaryStorage: boolean, isDev: boolean): {
|
|
3
|
+
shouldThrow: boolean;
|
|
4
|
+
shouldWarn: boolean;
|
|
5
|
+
message: string;
|
|
6
|
+
} | null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function resolveCustomSecondaryStorageRequirement(hubSecondaryStorage, userHasSecondaryStorage, isDev) {
|
|
2
|
+
if (hubSecondaryStorage !== "custom")
|
|
3
|
+
return null;
|
|
4
|
+
if (userHasSecondaryStorage)
|
|
5
|
+
return null;
|
|
6
|
+
const message = '[nuxt-better-auth] hubSecondaryStorage: "custom" requires secondaryStorage in defineServerAuth().';
|
|
7
|
+
return { shouldThrow: !isDev, shouldWarn: isDev, message };
|
|
8
|
+
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
+
import type { AppSession, RequireSessionOptions } from '#nuxt-better-auth';
|
|
1
2
|
import type { H3Event } from 'h3';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
session: AuthSession;
|
|
6
|
-
}
|
|
7
|
-
export declare function getUserSession(event: H3Event): Promise<FullSession | null>;
|
|
8
|
-
export declare function requireUserSession(event: H3Event, options?: RequireSessionOptions): Promise<FullSession>;
|
|
9
|
-
export {};
|
|
3
|
+
export declare function getRequestSession(event: H3Event): Promise<AppSession | null>;
|
|
4
|
+
export declare function getUserSession(event: H3Event): Promise<AppSession | null>;
|
|
5
|
+
export declare function requireUserSession(event: H3Event, options?: RequireSessionOptions): Promise<AppSession>;
|
|
@@ -1,12 +1,51 @@
|
|
|
1
1
|
import { createError } from "h3";
|
|
2
2
|
import { matchesUser } from "../../utils/match-user.js";
|
|
3
|
+
import { serverAuth } from "./auth.js";
|
|
4
|
+
const requestSessionLoadKey = Symbol.for("nuxt-better-auth.requestSessionLoad");
|
|
5
|
+
const fallbackRequestSessionContext = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
function getRequestSessionContext(event) {
|
|
7
|
+
const eventWithContext = event;
|
|
8
|
+
if (eventWithContext.context && typeof eventWithContext.context === "object")
|
|
9
|
+
return eventWithContext.context;
|
|
10
|
+
let context = fallbackRequestSessionContext.get(event);
|
|
11
|
+
if (!context) {
|
|
12
|
+
context = {};
|
|
13
|
+
fallbackRequestSessionContext.set(event, context);
|
|
14
|
+
}
|
|
15
|
+
return context;
|
|
16
|
+
}
|
|
17
|
+
function loadSession(event) {
|
|
18
|
+
const auth = serverAuth(event);
|
|
19
|
+
return auth.api.getSession({ headers: event.headers });
|
|
20
|
+
}
|
|
21
|
+
export async function getRequestSession(event) {
|
|
22
|
+
const context = getRequestSessionContext(event);
|
|
23
|
+
if (context.requestSession !== void 0)
|
|
24
|
+
return context.requestSession;
|
|
25
|
+
const inFlight = context[requestSessionLoadKey];
|
|
26
|
+
if (inFlight)
|
|
27
|
+
return inFlight;
|
|
28
|
+
const load = loadSession(event);
|
|
29
|
+
context[requestSessionLoadKey] = load;
|
|
30
|
+
try {
|
|
31
|
+
const session = await load;
|
|
32
|
+
context.requestSession = session;
|
|
33
|
+
return session;
|
|
34
|
+
} finally {
|
|
35
|
+
delete context[requestSessionLoadKey];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
3
38
|
export async function getUserSession(event) {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
39
|
+
const context = getRequestSessionContext(event);
|
|
40
|
+
if (context.requestSession !== void 0)
|
|
41
|
+
return context.requestSession;
|
|
42
|
+
const inFlight = context[requestSessionLoadKey];
|
|
43
|
+
if (inFlight)
|
|
44
|
+
return inFlight;
|
|
45
|
+
return loadSession(event);
|
|
7
46
|
}
|
|
8
47
|
export async function requireUserSession(event, options) {
|
|
9
|
-
const session = await
|
|
48
|
+
const session = await getRequestSession(event);
|
|
10
49
|
if (!session)
|
|
11
50
|
throw createError({ statusCode: 401, statusMessage: "Authentication required" });
|
|
12
51
|
if (options?.user) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare module '#auth/database' {
|
|
2
|
+
export const db: any
|
|
3
|
+
export function createDatabase(...args: any[]): any
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare module '#auth/secondary-storage' {
|
|
7
|
+
export function createSecondaryStorage(...args: any[]): any
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare module '#auth/schema' {
|
|
11
|
+
export const schema: any
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '#auth/server' {
|
|
15
|
+
const createServerAuth: any
|
|
16
|
+
export default createServerAuth
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '@nuxthub/db' {
|
|
20
|
+
export const db: any
|
|
21
|
+
export const schema: any
|
|
22
|
+
}
|
|
@@ -22,6 +22,8 @@ export interface ServerAuthContext {
|
|
|
22
22
|
runtimeConfig: Record<string, unknown>;
|
|
23
23
|
db: unknown;
|
|
24
24
|
}
|
|
25
|
+
export interface AuthSocialProviderRegistry {
|
|
26
|
+
}
|
|
25
27
|
export interface UserSessionComposable {
|
|
26
28
|
client: unknown;
|
|
27
29
|
user: Ref<AuthUser | null>;
|
|
@@ -37,6 +39,20 @@ export interface UserSessionComposable {
|
|
|
37
39
|
waitForSession: () => Promise<void>;
|
|
38
40
|
signOut: (options?: {
|
|
39
41
|
onSuccess?: () => void | Promise<void>;
|
|
40
|
-
}) => Promise<
|
|
41
|
-
updateUser: (updates: Partial<AuthUser>) => void
|
|
42
|
+
}) => Promise<void>;
|
|
43
|
+
updateUser: (updates: Partial<AuthUser>) => Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
export type UserMatch<T> = {
|
|
46
|
+
[K in keyof T]?: T[K] | T[K][];
|
|
47
|
+
};
|
|
48
|
+
export interface AppSession {
|
|
49
|
+
user: AuthUser;
|
|
50
|
+
session: AuthSession;
|
|
51
|
+
}
|
|
52
|
+
export interface RequireSessionOptions {
|
|
53
|
+
user?: UserMatch<AuthUser>;
|
|
54
|
+
rule?: (ctx: {
|
|
55
|
+
user: AuthUser;
|
|
56
|
+
session: AuthSession;
|
|
57
|
+
}) => boolean | Promise<boolean>;
|
|
42
58
|
}
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import type { AuthSocialProviderRegistry, AuthUser, UserMatch } from '#nuxt-better-auth';
|
|
1
2
|
import type { NitroRouteRules } from 'nitropack/types';
|
|
2
|
-
|
|
3
|
-
export type
|
|
4
|
-
|
|
3
|
+
export type { AppSession, AuthSession, AuthSocialProviderRegistry, AuthUser, RequireSessionOptions, ServerAuthContext, UserMatch, UserSessionComposable } from './types/augment.js';
|
|
4
|
+
export type AuthSocialProviderId = AuthSocialProviderRegistry extends {
|
|
5
|
+
ids: infer T;
|
|
6
|
+
} ? Extract<T, string> : never;
|
|
7
|
+
export type { Auth, InferPluginTypes, InferSessionFromClient as InferSession, InferUserFromClient as InferUser } from 'better-auth';
|
|
8
|
+
export interface AuthActionError {
|
|
9
|
+
message: string;
|
|
10
|
+
code?: string;
|
|
11
|
+
status?: number;
|
|
12
|
+
raw: unknown;
|
|
13
|
+
}
|
|
5
14
|
export type AuthMode = 'guest' | 'user';
|
|
6
|
-
export type UserMatch<T> = {
|
|
7
|
-
[K in keyof T]?: T[K] | T[K][];
|
|
8
|
-
};
|
|
9
15
|
export type AuthMeta = false | AuthMode | {
|
|
10
16
|
only?: AuthMode;
|
|
11
17
|
redirectTo?: string;
|
|
@@ -14,10 +20,3 @@ export type AuthMeta = false | AuthMode | {
|
|
|
14
20
|
export type AuthRouteRules = NitroRouteRules & {
|
|
15
21
|
auth?: AuthMeta;
|
|
16
22
|
};
|
|
17
|
-
export interface RequireSessionOptions {
|
|
18
|
-
user?: UserMatch<AuthUser>;
|
|
19
|
-
rule?: (ctx: {
|
|
20
|
-
user: AuthUser;
|
|
21
|
-
session: AuthSession;
|
|
22
|
-
}) => boolean | Promise<boolean>;
|
|
23
|
-
}
|
package/dist/types.d.mts
CHANGED
|
@@ -6,6 +6,6 @@ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<
|
|
|
6
6
|
|
|
7
7
|
export { type BetterAuthModuleOptions, type defineClientAuth, type defineServerAuth } from '../dist/runtime/config.js'
|
|
8
8
|
|
|
9
|
-
export { type Auth, type AuthMeta, type AuthMode, type AuthRouteRules, type AuthSession, type AuthUser, type InferSession, type InferUser, type RequireSessionOptions, type ServerAuthContext, type UserMatch } from '../dist/runtime/types.js'
|
|
9
|
+
export { type AppSession, type Auth, type AuthActionError, type AuthMeta, type AuthMode, type AuthRouteRules, type AuthSession, type AuthSocialProviderId, type AuthUser, type InferSession, type InferUser, type RequireSessionOptions, type ServerAuthContext, type UserMatch } from '../dist/runtime/types.js'
|
|
10
10
|
|
|
11
11
|
export { default } from './module.mjs'
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onmax/nuxt-better-auth",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.2-alpha.
|
|
4
|
+
"version": "0.0.2-alpha.31",
|
|
5
5
|
"packageManager": "pnpm@10.15.1",
|
|
6
6
|
"description": "Nuxt module for Better Auth integration with NuxtHub, route protection, session management, and role-based access",
|
|
7
7
|
"author": "onmax",
|
|
8
8
|
"license": "MIT",
|
|
9
|
+
"homepage": "https://better-auth.nuxt.dev",
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/
|
|
12
|
+
"url": "https://github.com/nuxt-modules/better-auth"
|
|
12
13
|
},
|
|
13
14
|
"exports": {
|
|
14
15
|
".": {
|
|
@@ -41,16 +42,17 @@
|
|
|
41
42
|
"dev:prepare": "nuxt-module-build build --stub && nuxi prepare playground",
|
|
42
43
|
"dev:docs": "nuxi dev docs",
|
|
43
44
|
"build:docs": "nuxi build docs",
|
|
44
|
-
"release": "bumpp
|
|
45
|
+
"release": "bumpp --push --no-push-all",
|
|
45
46
|
"lint": "eslint .",
|
|
46
47
|
"lint:fix": "eslint . --fix",
|
|
47
48
|
"typecheck": "vue-tsc --noEmit",
|
|
48
|
-
"typecheck:
|
|
49
|
+
"typecheck:runtime-server": "tsc --noEmit --pretty false -p src/runtime/server/tsconfig.json",
|
|
50
|
+
"typecheck:playground": "pnpm -C playground exec nuxi prepare && pnpm -C playground exec vue-tsc --noEmit -p .nuxt/tsconfig.app.json",
|
|
49
51
|
"test": "vitest run",
|
|
50
52
|
"test:watch": "vitest watch"
|
|
51
53
|
},
|
|
52
54
|
"peerDependencies": {
|
|
53
|
-
"@nuxthub/core": ">=0.10.
|
|
55
|
+
"@nuxthub/core": ">=0.10.5",
|
|
54
56
|
"better-auth": ">=1.0.0"
|
|
55
57
|
},
|
|
56
58
|
"peerDependenciesMeta": {
|
|
@@ -59,54 +61,42 @@
|
|
|
59
61
|
}
|
|
60
62
|
},
|
|
61
63
|
"dependencies": {
|
|
62
|
-
"@
|
|
64
|
+
"@better-auth/cli": "1.5.0-beta.13",
|
|
65
|
+
"@nuxt/kit": "^4.3.1",
|
|
66
|
+
"@nuxt/ui": "^4.5.0",
|
|
63
67
|
"defu": "^6.1.4",
|
|
64
|
-
"jiti": "^2.
|
|
68
|
+
"jiti": "^2.6.1",
|
|
65
69
|
"pathe": "^2.0.3",
|
|
66
|
-
"radix3": "^1.1.2"
|
|
70
|
+
"radix3": "^1.1.2",
|
|
71
|
+
"std-env": "^4.0.0"
|
|
67
72
|
},
|
|
68
73
|
"devDependencies": {
|
|
69
|
-
"@antfu/eslint-config": "^
|
|
70
|
-
"@
|
|
71
|
-
"@libsql/
|
|
72
|
-
"@nuxt/devtools": "^3.
|
|
73
|
-
"@nuxt/devtools-kit": "^3.
|
|
74
|
+
"@antfu/eslint-config": "^7.6.1",
|
|
75
|
+
"@libsql/client": "^0.17.0",
|
|
76
|
+
"@libsql/linux-x64-gnu": "0.5.22",
|
|
77
|
+
"@nuxt/devtools": "^3.2.3",
|
|
78
|
+
"@nuxt/devtools-kit": "^3.2.2",
|
|
74
79
|
"@nuxt/module-builder": "^1.0.2",
|
|
75
|
-
"@nuxt/schema": "^4.
|
|
76
|
-
"@nuxt/test-utils": "^
|
|
77
|
-
"@nuxthub/core": "^0.10.
|
|
80
|
+
"@nuxt/schema": "^4.3.1",
|
|
81
|
+
"@nuxt/test-utils": "^4.0.0",
|
|
82
|
+
"@nuxthub/core": "^0.10.6",
|
|
78
83
|
"@types/better-sqlite3": "^7.6.13",
|
|
79
84
|
"@types/node": "latest",
|
|
80
|
-
"better-auth": "
|
|
81
|
-
"better-sqlite3": "^
|
|
82
|
-
"bumpp": "^
|
|
85
|
+
"better-auth": "1.5.5",
|
|
86
|
+
"better-sqlite3": "^12.6.2",
|
|
87
|
+
"bumpp": "^11.0.0",
|
|
83
88
|
"changelogen": "^0.6.2",
|
|
84
89
|
"consola": "^3.4.2",
|
|
85
|
-
"drizzle-kit": "^0.31.
|
|
86
|
-
"drizzle-orm": "^0.
|
|
87
|
-
"eslint": "^
|
|
88
|
-
"
|
|
90
|
+
"drizzle-kit": "^0.31.9",
|
|
91
|
+
"drizzle-orm": "^0.45.1",
|
|
92
|
+
"eslint": "^10.0.3",
|
|
93
|
+
"npm-agentskills": "https://pkg.pr.new/onmax/npm-agentskills@394499e",
|
|
94
|
+
"nuxt": "^4.3.1",
|
|
89
95
|
"tinyexec": "^1.0.2",
|
|
90
96
|
"typescript": "~5.9.3",
|
|
91
|
-
"vitest": "^4.0.
|
|
92
|
-
"vitest-package-exports": "^
|
|
93
|
-
"vue-tsc": "^3.
|
|
97
|
+
"vitest": "^4.0.18",
|
|
98
|
+
"vitest-package-exports": "^1.2.0",
|
|
99
|
+
"vue-tsc": "^3.2.5",
|
|
94
100
|
"yaml": "^2.8.2"
|
|
95
|
-
},
|
|
96
|
-
"pnpm": {
|
|
97
|
-
"onlyBuiltDependencies": [
|
|
98
|
-
"@parcel/watcher",
|
|
99
|
-
"better-sqlite3",
|
|
100
|
-
"esbuild",
|
|
101
|
-
"sharp",
|
|
102
|
-
"workerd"
|
|
103
|
-
],
|
|
104
|
-
"patchedDependencies": {
|
|
105
|
-
"@peculiar/x509@1.14.2": "patches/@peculiar__x509@1.14.2.patch",
|
|
106
|
-
"unenv@2.0.0-rc.24": "patches/unenv@2.0.0-rc.24.patch"
|
|
107
|
-
},
|
|
108
|
-
"overrides": {
|
|
109
|
-
"reka-ui": "^2.6.1"
|
|
110
|
-
}
|
|
111
101
|
}
|
|
112
102
|
}
|