@onmax/nuxt-better-auth 0.0.2-alpha.9 → 0.0.3
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 +57 -17
- package/dist/module.d.mts +28 -1
- package/dist/module.json +3 -3
- package/dist/module.mjs +1258 -351
- package/dist/runtime/app/components/BetterAuthState.d.vue.ts +4 -4
- package/dist/runtime/app/components/BetterAuthState.vue +1 -0
- package/dist/runtime/app/components/BetterAuthState.vue.d.ts +4 -4
- package/dist/runtime/app/composables/runWithSessionRefresh.d.ts +1 -0
- package/dist/runtime/app/composables/runWithSessionRefresh.js +12 -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/useAuthClient.d.ts +9 -0
- package/dist/runtime/app/composables/useAuthClient.js +34 -0
- package/dist/runtime/app/composables/useAuthClientAction.d.ts +3 -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 +6 -5
- package/dist/runtime/app/composables/useUserSession.js +189 -100
- package/dist/runtime/app/composables/useUserSessionState.d.ts +3 -0
- package/dist/runtime/app/composables/useUserSessionState.js +4 -0
- 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 +21 -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/vue-safe-auth-proxy.d.ts +3 -0
- package/dist/runtime/app/internal/vue-safe-auth-proxy.js +68 -0
- package/dist/runtime/app/internal/wrap-auth-method.d.ts +18 -0
- package/dist/runtime/app/internal/wrap-auth-method.js +69 -0
- package/dist/runtime/app/middleware/auth.global.js +80 -15
- package/dist/runtime/app/pages/__better-auth-devtools.vue +293 -339
- package/dist/runtime/composables.d.ts +12 -0
- package/dist/runtime/composables.js +10 -0
- package/dist/runtime/config.d.ts +69 -15
- package/dist/runtime/config.js +9 -2
- package/dist/runtime/internal/auth-route-rules.d.ts +1 -0
- package/dist/runtime/internal/auth-route-rules.js +24 -0
- package/dist/runtime/server/api/_better-auth/_schema.d.ts +1 -5
- package/dist/runtime/server/api/_better-auth/_schema.js +2 -1
- package/dist/runtime/server/api/_better-auth/accounts.get.d.ts +2 -2
- package/dist/runtime/server/api/_better-auth/accounts.get.js +3 -2
- package/dist/runtime/server/api/_better-auth/config.get.d.ts +9 -3
- package/dist/runtime/server/api/_better-auth/config.get.js +18 -6
- package/dist/runtime/server/api/_better-auth/sessions.delete.js +3 -2
- package/dist/runtime/server/api/_better-auth/sessions.get.d.ts +5 -3
- package/dist/runtime/server/api/_better-auth/sessions.get.js +3 -2
- package/dist/runtime/server/api/_better-auth/users.get.d.ts +2 -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 +4 -2
- package/dist/runtime/server/tsconfig.json +9 -1
- package/dist/runtime/server/utils/auth.d.ts +16 -8
- package/dist/runtime/server/utils/auth.js +229 -23
- 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 +7 -8
- package/dist/runtime/server/utils/session.js +256 -5
- package/dist/runtime/server/virtual-modules.d.ts +27 -0
- package/dist/runtime/types/augment.d.ts +18 -4
- package/dist/runtime/types.d.ts +12 -13
- package/dist/types.d.mts +1 -1
- package/package.json +53 -47
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { runWithSessionRefresh } from './app/composables/runWithSessionRefresh.js';
|
|
2
|
+
export { useAction } from './app/composables/useAction.js';
|
|
3
|
+
export { useAuthAsyncData } from './app/composables/useAuthAsyncData.js';
|
|
4
|
+
export { useAuthClient } from './app/composables/useAuthClient.js';
|
|
5
|
+
export { useAuthClientAction } from './app/composables/useAuthClientAction.js';
|
|
6
|
+
export { useAuthRequestFetch } from './app/composables/useAuthRequestFetch.js';
|
|
7
|
+
export { useSignIn } from './app/composables/useSignIn.js';
|
|
8
|
+
export { useSignUp } from './app/composables/useSignUp.js';
|
|
9
|
+
export { useUserSession } from './app/composables/useUserSession.js';
|
|
10
|
+
export type { SignOutOptions, UseUserSessionReturn } from './app/composables/useUserSession.js';
|
|
11
|
+
export { useUserSessionState } from './app/composables/useUserSessionState.js';
|
|
12
|
+
export type { UseUserSessionStateReturn } from './app/composables/useUserSessionState.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { runWithSessionRefresh } from "./app/composables/runWithSessionRefresh.js";
|
|
2
|
+
export { useAction } from "./app/composables/useAction.js";
|
|
3
|
+
export { useAuthAsyncData } from "./app/composables/useAuthAsyncData.js";
|
|
4
|
+
export { useAuthClient } from "./app/composables/useAuthClient.js";
|
|
5
|
+
export { useAuthClientAction } from "./app/composables/useAuthClientAction.js";
|
|
6
|
+
export { useAuthRequestFetch } from "./app/composables/useAuthRequestFetch.js";
|
|
7
|
+
export { useSignIn } from "./app/composables/useSignIn.js";
|
|
8
|
+
export { useSignUp } from "./app/composables/useSignUp.js";
|
|
9
|
+
export { useUserSession } from "./app/composables/useUserSession.js";
|
|
10
|
+
export { useUserSessionState } from "./app/composables/useUserSessionState.js";
|
package/dist/runtime/config.d.ts
CHANGED
|
@@ -1,44 +1,98 @@
|
|
|
1
|
-
import type { BetterAuthOptions } from 'better-auth';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type { ServerAuthContext } from './types/augment.js';
|
|
5
|
-
|
|
1
|
+
import type { BetterAuthOptions, BetterAuthPlugin } from 'better-auth';
|
|
2
|
+
import type { BetterAuthClientOptions } from 'better-auth/client';
|
|
3
|
+
import type { Casing } from 'drizzle-orm/utils';
|
|
4
|
+
import type { ServerAuthContext as BaseServerAuthContext } from './types/augment.js';
|
|
5
|
+
import { createAuthClient } from 'better-auth/vue';
|
|
6
|
+
export interface ServerAuthContextExtension {
|
|
7
|
+
}
|
|
8
|
+
export type ServerAuthContext = BaseServerAuthContext & ServerAuthContextExtension;
|
|
6
9
|
export interface ClientAuthContext {
|
|
7
10
|
siteUrl: string;
|
|
8
11
|
}
|
|
9
|
-
type ServerAuthConfig = Omit<BetterAuthOptions, '
|
|
10
|
-
|
|
12
|
+
export type ServerAuthConfig = Omit<BetterAuthOptions, 'secret' | 'baseURL'> & {
|
|
13
|
+
plugins?: readonly BetterAuthPlugin[];
|
|
14
|
+
};
|
|
15
|
+
export type ClientAuthConfig = Omit<BetterAuthClientOptions, 'baseURL'> & {
|
|
11
16
|
baseURL?: string;
|
|
12
17
|
};
|
|
13
18
|
export type ServerAuthConfigFn = (ctx: ServerAuthContext) => ServerAuthConfig;
|
|
14
19
|
export type ClientAuthConfigFn = (ctx: ClientAuthContext) => ClientAuthConfig;
|
|
20
|
+
export type ModuleDatabaseProviderId = 'none' | 'nuxthub' | (string & {});
|
|
21
|
+
export type EffectiveDatabaseProviderId = 'user' | ModuleDatabaseProviderId;
|
|
15
22
|
export interface BetterAuthModuleOptions {
|
|
16
|
-
/**
|
|
23
|
+
/** Client-only mode - skip server setup for external auth backends */
|
|
24
|
+
clientOnly?: boolean;
|
|
25
|
+
/** Server config path. Relative paths resolve from the layer that declares them. Default: 'server/auth.config' */
|
|
17
26
|
serverConfig?: string;
|
|
18
|
-
/** Client config path
|
|
27
|
+
/** Client config path. Relative paths resolve from the layer that declares them. Default: 'app/auth.config' */
|
|
19
28
|
clientConfig?: string;
|
|
20
29
|
redirects?: {
|
|
30
|
+
/** Where to redirect unauthenticated users. Default: '/login' */
|
|
21
31
|
login?: string;
|
|
32
|
+
/** Where to redirect authenticated users on guest-only routes. Default: '/' */
|
|
22
33
|
guest?: string;
|
|
34
|
+
/** Where to navigate after successful signIn/signUp when no onSuccess is provided. Default: no automatic navigation */
|
|
35
|
+
authenticated?: string;
|
|
36
|
+
/** Where to navigate after logout. Default: no automatic navigation */
|
|
37
|
+
logout?: string;
|
|
23
38
|
};
|
|
24
|
-
/**
|
|
25
|
-
|
|
39
|
+
/**
|
|
40
|
+
* When redirecting unauthenticated users to the login route, append a query param
|
|
41
|
+
* containing the originally requested path (for safe "return-to" redirects).
|
|
42
|
+
*
|
|
43
|
+
* Default: true
|
|
44
|
+
*/
|
|
45
|
+
preserveRedirect?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Query param key used by preserveRedirect.
|
|
48
|
+
*
|
|
49
|
+
* Default: 'redirect'
|
|
50
|
+
*/
|
|
51
|
+
redirectQueryKey?: string;
|
|
52
|
+
session?: {
|
|
53
|
+
/**
|
|
54
|
+
* When enabled, and session/user are already hydrated from SSR, skip the initial
|
|
55
|
+
* client `/api/auth/get-session` bootstrap request. This also skips Better Auth's
|
|
56
|
+
* session refresh manager on those pages.
|
|
57
|
+
*
|
|
58
|
+
* Default: false
|
|
59
|
+
*/
|
|
60
|
+
skipHydratedSsrGetSession?: boolean;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Enable secondary storage for sessions.
|
|
64
|
+
* - `true`: Use NuxtHub KV (requires hub.kv: true)
|
|
65
|
+
* - `'custom'`: User provides own secondaryStorage in defineServerAuth()
|
|
66
|
+
* - `false` (default): No secondary storage from module
|
|
67
|
+
*/
|
|
68
|
+
hubSecondaryStorage?: boolean | 'custom';
|
|
26
69
|
/** Schema generation options. Must match drizzleAdapter config. */
|
|
27
70
|
schema?: {
|
|
28
71
|
/** Plural table names: user → users. Default: false */
|
|
29
72
|
usePlural?: boolean;
|
|
30
73
|
/** Column/table name casing. Explicit value takes precedence over hub.db.casing. */
|
|
31
|
-
casing?:
|
|
74
|
+
casing?: Casing;
|
|
32
75
|
};
|
|
33
76
|
}
|
|
34
77
|
export interface AuthRuntimeConfig {
|
|
35
78
|
redirects: {
|
|
36
79
|
login: string;
|
|
37
80
|
guest: string;
|
|
81
|
+
authenticated?: string;
|
|
82
|
+
logout?: string;
|
|
83
|
+
};
|
|
84
|
+
preserveRedirect: boolean;
|
|
85
|
+
redirectQueryKey: string;
|
|
86
|
+
useDatabase: boolean;
|
|
87
|
+
databaseProvider: EffectiveDatabaseProviderId;
|
|
88
|
+
clientOnly: boolean;
|
|
89
|
+
session: {
|
|
90
|
+
skipHydratedSsrGetSession: boolean;
|
|
38
91
|
};
|
|
39
92
|
}
|
|
40
93
|
export interface AuthPrivateRuntimeConfig {
|
|
41
|
-
|
|
94
|
+
hubSecondaryStorage: boolean | 'custom';
|
|
42
95
|
}
|
|
43
|
-
export declare function defineServerAuth<
|
|
44
|
-
export declare function
|
|
96
|
+
export declare function defineServerAuth<const R>(config: (ctx: ServerAuthContext) => R & ServerAuthConfig): (ctx: ServerAuthContext) => R;
|
|
97
|
+
export declare function defineServerAuth<const R>(config: R & ServerAuthConfig): (ctx: ServerAuthContext) => R;
|
|
98
|
+
export declare function defineClientAuth<T extends ClientAuthConfig>(config: T | ((ctx: ClientAuthContext) => T)): (baseURL: string) => ReturnType<typeof createAuthClient<T>>;
|
package/dist/runtime/config.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import { createAuthClient } from "better-auth/vue";
|
|
1
2
|
export function defineServerAuth(config) {
|
|
2
|
-
return config;
|
|
3
|
+
return typeof config === "function" ? config : () => config;
|
|
3
4
|
}
|
|
4
5
|
export function defineClientAuth(config) {
|
|
5
|
-
return
|
|
6
|
+
return (baseURL) => {
|
|
7
|
+
const ctx = { siteUrl: baseURL };
|
|
8
|
+
const resolved = typeof config === "function" ? config(ctx) : config;
|
|
9
|
+
const { baseURL: configuredBaseURL, ...resolvedOptions } = resolved;
|
|
10
|
+
const clientOptions = { ...resolvedOptions, baseURL: configuredBaseURL ?? baseURL };
|
|
11
|
+
return createAuthClient(clientOptions);
|
|
12
|
+
};
|
|
6
13
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function shouldSkipAuthRouteRules(path: string): boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const internalRouteRuleAuthPaths = /* @__PURE__ */ new Set([
|
|
2
|
+
"/_ipx",
|
|
3
|
+
"/_nuxt",
|
|
4
|
+
"/__better-auth-devtools",
|
|
5
|
+
"/__nuxt_devtools__",
|
|
6
|
+
"/__nuxt_error",
|
|
7
|
+
"/__nuxt_vite_node__",
|
|
8
|
+
"/api/_better-auth",
|
|
9
|
+
"/api/_nuxt_icon",
|
|
10
|
+
"/api/auth"
|
|
11
|
+
]);
|
|
12
|
+
const internalRouteRuleAuthPrefixes = [
|
|
13
|
+
"/_ipx/",
|
|
14
|
+
"/_nuxt/",
|
|
15
|
+
"/__nuxt_devtools__/",
|
|
16
|
+
"/__nuxt_vite_node__/",
|
|
17
|
+
"/api/_better-auth/",
|
|
18
|
+
"/api/_nuxt_icon/",
|
|
19
|
+
"/api/auth/"
|
|
20
|
+
];
|
|
21
|
+
export function shouldSkipAuthRouteRules(path) {
|
|
22
|
+
const pathname = path.split(/[?#]/, 1)[0] || "/";
|
|
23
|
+
return internalRouteRuleAuthPaths.has(pathname) || internalRouteRuleAuthPrefixes.some((prefix) => pathname.startsWith(prefix));
|
|
24
|
+
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const paginationQuerySchema:
|
|
3
|
-
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
4
|
-
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
5
|
-
search: z.ZodDefault<z.ZodString>;
|
|
6
|
-
}, z.core.$strip>;
|
|
2
|
+
export declare const paginationQuerySchema: any;
|
|
7
3
|
export type PaginationQuery = z.infer<typeof paginationQuerySchema>;
|
|
8
4
|
export declare function sanitizeSearchPattern(search: string): string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
const SQL_LIKE_ESCAPE_RE = /[%_\\]/g;
|
|
2
3
|
export const paginationQuerySchema = z.object({
|
|
3
4
|
page: z.coerce.number().int().min(1).default(1),
|
|
4
5
|
limit: z.coerce.number().int().min(1).max(100).default(20),
|
|
@@ -7,5 +8,5 @@ export const paginationQuerySchema = z.object({
|
|
|
7
8
|
export function sanitizeSearchPattern(search) {
|
|
8
9
|
if (!search)
|
|
9
10
|
return "";
|
|
10
|
-
return `%${search.replace(
|
|
11
|
+
return `%${search.replace(SQL_LIKE_ESCAPE_RE, "\\$&")}%`;
|
|
11
12
|
}
|
|
@@ -2,8 +2,9 @@ import { defineEventHandler, getQuery } from "h3";
|
|
|
2
2
|
import { paginationQuerySchema, sanitizeSearchPattern } from "./_schema.js";
|
|
3
3
|
export default defineEventHandler(async (event) => {
|
|
4
4
|
try {
|
|
5
|
-
const { db
|
|
6
|
-
|
|
5
|
+
const { db } = await import("@nuxthub/db");
|
|
6
|
+
const { schema } = await import("#auth/schema");
|
|
7
|
+
if (!schema?.account)
|
|
7
8
|
return { accounts: [], total: 0, error: "Account table not found" };
|
|
8
9
|
const query = paginationQuerySchema.parse(getQuery(event));
|
|
9
10
|
const { page, limit, search } = query;
|
|
@@ -2,11 +2,16 @@ declare const _default: import("h3").EventHandler<import("h3").EventHandlerReque
|
|
|
2
2
|
config: {
|
|
3
3
|
module: {
|
|
4
4
|
redirects: {
|
|
5
|
-
login
|
|
6
|
-
guest
|
|
5
|
+
login: string;
|
|
6
|
+
guest: string;
|
|
7
|
+
authenticated: string | undefined;
|
|
8
|
+
logout: string | undefined;
|
|
7
9
|
};
|
|
8
|
-
|
|
10
|
+
preserveRedirect: boolean;
|
|
11
|
+
redirectQueryKey: string;
|
|
12
|
+
hubSecondaryStorage: boolean | "custom";
|
|
9
13
|
useDatabase: boolean;
|
|
14
|
+
databaseProvider: "none" | "nuxthub";
|
|
10
15
|
};
|
|
11
16
|
server: {
|
|
12
17
|
baseURL: any;
|
|
@@ -14,6 +19,7 @@ declare const _default: import("h3").EventHandler<import("h3").EventHandlerReque
|
|
|
14
19
|
socialProviders: string[];
|
|
15
20
|
plugins: any;
|
|
16
21
|
trustedOrigins: any;
|
|
22
|
+
configuredTrustedOrigins: any;
|
|
17
23
|
session: {
|
|
18
24
|
expiresIn: string;
|
|
19
25
|
updateAge: string;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { defineEventHandler } from "h3";
|
|
2
|
-
import { useRuntimeConfig } from "
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
3
|
import { serverAuth } from "../../utils/auth.js";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
try {
|
|
6
|
-
const auth =
|
|
6
|
+
const auth = serverAuth(event);
|
|
7
7
|
const options = auth.options;
|
|
8
|
+
const authContext = await auth.$context;
|
|
8
9
|
const runtimeConfig = useRuntimeConfig();
|
|
9
10
|
const publicAuth = runtimeConfig.public?.auth;
|
|
10
11
|
const privateAuth = runtimeConfig.auth;
|
|
12
|
+
const configuredTrustedOrigins = Array.isArray(options.trustedOrigins) ? options.trustedOrigins : [];
|
|
13
|
+
const effectiveTrustedOrigins = authContext?.trustedOrigins || configuredTrustedOrigins;
|
|
11
14
|
const sessionConfig = options.session || {};
|
|
12
15
|
const expiresInDays = sessionConfig.expiresIn ? Math.round(sessionConfig.expiresIn / 86400) : 7;
|
|
13
16
|
const updateAgeDays = sessionConfig.updateAge ? Math.round(sessionConfig.updateAge / 86400) : 1;
|
|
@@ -15,9 +18,17 @@ export default defineEventHandler(async (event) => {
|
|
|
15
18
|
config: {
|
|
16
19
|
// Module config (nuxt.config.ts)
|
|
17
20
|
module: {
|
|
18
|
-
redirects:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
redirects: {
|
|
22
|
+
login: publicAuth?.redirects?.login ?? "/login",
|
|
23
|
+
guest: publicAuth?.redirects?.guest ?? "/",
|
|
24
|
+
authenticated: publicAuth?.redirects?.authenticated,
|
|
25
|
+
logout: publicAuth?.redirects?.logout
|
|
26
|
+
},
|
|
27
|
+
preserveRedirect: publicAuth?.preserveRedirect ?? true,
|
|
28
|
+
redirectQueryKey: publicAuth?.redirectQueryKey ?? "redirect",
|
|
29
|
+
hubSecondaryStorage: privateAuth?.hubSecondaryStorage ?? false,
|
|
30
|
+
useDatabase: publicAuth?.useDatabase ?? false,
|
|
31
|
+
databaseProvider: publicAuth?.databaseProvider ?? "none"
|
|
21
32
|
},
|
|
22
33
|
// Server config (server/auth.config.ts)
|
|
23
34
|
server: {
|
|
@@ -25,7 +36,8 @@ export default defineEventHandler(async (event) => {
|
|
|
25
36
|
basePath: options.basePath || "/api/auth",
|
|
26
37
|
socialProviders: Object.keys(options.socialProviders || {}),
|
|
27
38
|
plugins: (options.plugins || []).map((p) => p.id || "unknown"),
|
|
28
|
-
trustedOrigins:
|
|
39
|
+
trustedOrigins: effectiveTrustedOrigins,
|
|
40
|
+
configuredTrustedOrigins,
|
|
29
41
|
session: {
|
|
30
42
|
expiresIn: `${expiresInDays} days`,
|
|
31
43
|
updateAge: `${updateAgeDays} days`,
|
|
@@ -6,8 +6,9 @@ const deleteSessionSchema = z.object({
|
|
|
6
6
|
export default defineEventHandler(async (event) => {
|
|
7
7
|
try {
|
|
8
8
|
const body = deleteSessionSchema.parse(await readBody(event));
|
|
9
|
-
const { db
|
|
10
|
-
|
|
9
|
+
const { db } = await import("@nuxthub/db");
|
|
10
|
+
const { schema } = await import("#auth/schema");
|
|
11
|
+
if (!schema?.session)
|
|
11
12
|
throw createError({ statusCode: 500, message: "Session table not found" });
|
|
12
13
|
const { eq } = await import("drizzle-orm");
|
|
13
14
|
await db.delete(schema.session).where(eq(schema.session.id, body.id));
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Session } from 'better-auth/types';
|
|
2
|
+
type SafeSession = Pick<Session, 'id' | 'userId' | 'createdAt' | 'updatedAt' | 'expiresAt' | 'ipAddress' | 'userAgent'>;
|
|
1
3
|
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
|
|
2
4
|
sessions: never[];
|
|
3
5
|
total: number;
|
|
@@ -5,10 +7,10 @@ declare const _default: import("h3").EventHandler<import("h3").EventHandlerReque
|
|
|
5
7
|
page?: undefined;
|
|
6
8
|
limit?: undefined;
|
|
7
9
|
} | {
|
|
8
|
-
sessions:
|
|
10
|
+
sessions: SafeSession[];
|
|
9
11
|
total: any;
|
|
10
|
-
page:
|
|
11
|
-
limit:
|
|
12
|
+
page: any;
|
|
13
|
+
limit: any;
|
|
12
14
|
error?: undefined;
|
|
13
15
|
}>>;
|
|
14
16
|
export default _default;
|
|
@@ -2,8 +2,9 @@ import { defineEventHandler, getQuery } from "h3";
|
|
|
2
2
|
import { paginationQuerySchema, sanitizeSearchPattern } from "./_schema.js";
|
|
3
3
|
export default defineEventHandler(async (event) => {
|
|
4
4
|
try {
|
|
5
|
-
const { db
|
|
6
|
-
|
|
5
|
+
const { db } = await import("@nuxthub/db");
|
|
6
|
+
const { schema } = await import("#auth/schema");
|
|
7
|
+
if (!schema?.session)
|
|
7
8
|
return { sessions: [], total: 0, error: "Session table not found" };
|
|
8
9
|
const query = paginationQuerySchema.parse(getQuery(event));
|
|
9
10
|
const { page, limit, search } = query;
|
|
@@ -2,8 +2,9 @@ import { defineEventHandler, getQuery } from "h3";
|
|
|
2
2
|
import { paginationQuerySchema, sanitizeSearchPattern } from "./_schema.js";
|
|
3
3
|
export default defineEventHandler(async (event) => {
|
|
4
4
|
try {
|
|
5
|
-
const { db
|
|
6
|
-
|
|
5
|
+
const { db } = await import("@nuxthub/db");
|
|
6
|
+
const { schema } = await import("#auth/schema");
|
|
7
|
+
if (!schema?.user)
|
|
7
8
|
return { users: [], total: 0, error: "User table not found" };
|
|
8
9
|
const query = paginationQuerySchema.parse(getQuery(event));
|
|
9
10
|
const { page, limit, search } = query;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, toWebRequest } from "h3";
|
|
2
2
|
import { serverAuth } from "../../utils/auth.js";
|
|
3
3
|
export default defineEventHandler(async (event) => {
|
|
4
|
-
const auth =
|
|
4
|
+
const auth = serverAuth(event);
|
|
5
5
|
return auth.handler(toWebRequest(event));
|
|
6
6
|
});
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { createError, defineEventHandler, getRequestURL } from "h3";
|
|
2
|
-
import { getRouteRules } from "
|
|
2
|
+
import { getRouteRules } from "#imports";
|
|
3
|
+
import { shouldSkipAuthRouteRules } from "../../internal/auth-route-rules.js";
|
|
3
4
|
import { matchesUser } from "../../utils/match-user.js";
|
|
5
|
+
import { getUserSession, requireUserSession } from "../utils/session.js";
|
|
4
6
|
export default defineEventHandler(async (event) => {
|
|
5
7
|
const path = getRequestURL(event).pathname;
|
|
6
8
|
if (!path.startsWith("/api/"))
|
|
7
9
|
return;
|
|
8
|
-
if (path
|
|
10
|
+
if (shouldSkipAuthRouteRules(path))
|
|
9
11
|
return;
|
|
10
12
|
const rules = getRouteRules(event);
|
|
11
13
|
if (!rules.auth)
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "
|
|
2
|
+
"extends": "../../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"paths": {
|
|
6
|
+
"#nuxt-better-auth": ["../types/augment"]
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"include": ["./**/*.ts", "./**/*.d.ts"],
|
|
10
|
+
"exclude": ["node_modules"]
|
|
3
11
|
}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BetterAuthOptions } from 'better-auth';
|
|
2
2
|
import type { H3Event } from 'h3';
|
|
3
|
+
import { betterAuth } from 'better-auth';
|
|
3
4
|
import createServerAuth from '#auth/server';
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
type AuthOptions = ReturnType<typeof createServerAuth>;
|
|
6
|
+
type UserAuthConfig = AuthOptions & {
|
|
7
|
+
trustedOrigins?: BetterAuthOptions['trustedOrigins'];
|
|
8
|
+
secondaryStorage?: BetterAuthOptions['secondaryStorage'];
|
|
9
|
+
};
|
|
10
|
+
type ResolvedAuthOptions = UserAuthConfig & {
|
|
11
|
+
secret: string;
|
|
12
|
+
baseURL: string;
|
|
13
|
+
trustedOrigins?: BetterAuthOptions['trustedOrigins'];
|
|
14
|
+
database?: BetterAuthOptions['database'];
|
|
15
|
+
};
|
|
16
|
+
type AuthInstance = ReturnType<typeof betterAuth<ResolvedAuthOptions>>;
|
|
17
|
+
/** Returns Better Auth instance. Caches per resolved host (or single instance when siteUrl is explicit). */
|
|
18
|
+
export declare function serverAuth(event?: H3Event): AuthInstance;
|
|
11
19
|
export {};
|