@better-auth/core 1.5.0-beta.9 → 1.5.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 +17 -0
- package/dist/api/index.d.mts +144 -41
- package/dist/api/index.mjs +2 -1
- package/dist/api/index.mjs.map +1 -0
- package/dist/async_hooks/index.d.mts +2 -1
- package/dist/async_hooks/index.mjs +2 -1
- package/dist/async_hooks/index.mjs.map +1 -0
- package/dist/async_hooks/pure.index.d.mts +2 -1
- package/dist/async_hooks/pure.index.mjs +2 -1
- package/dist/async_hooks/pure.index.mjs.map +1 -0
- package/dist/context/endpoint-context.d.mts +2 -1
- package/dist/context/endpoint-context.mjs +4 -3
- package/dist/context/endpoint-context.mjs.map +1 -0
- package/dist/context/global.d.mts +2 -2
- package/dist/context/global.mjs +3 -2
- package/dist/context/global.mjs.map +1 -0
- package/dist/context/request-state.d.mts +2 -1
- package/dist/context/request-state.mjs +4 -3
- package/dist/context/request-state.mjs.map +1 -0
- package/dist/context/transaction.d.mts +2 -1
- package/dist/context/transaction.mjs +4 -3
- package/dist/context/transaction.mjs.map +1 -0
- package/dist/db/adapter/factory.d.mts +6 -13
- package/dist/db/adapter/factory.mjs +44 -57
- package/dist/db/adapter/factory.mjs.map +1 -0
- package/dist/db/adapter/get-default-field-name.d.mts +2 -1
- package/dist/db/adapter/get-default-field-name.mjs +3 -2
- package/dist/db/adapter/get-default-field-name.mjs.map +1 -0
- package/dist/db/adapter/get-default-model-name.d.mts +2 -1
- package/dist/db/adapter/get-default-model-name.mjs +5 -4
- package/dist/db/adapter/get-default-model-name.mjs.map +1 -0
- package/dist/db/adapter/get-field-attributes.d.mts +3 -2
- package/dist/db/adapter/get-field-attributes.mjs +2 -1
- package/dist/db/adapter/get-field-attributes.mjs.map +1 -0
- package/dist/db/adapter/get-field-name.d.mts +2 -1
- package/dist/db/adapter/get-field-name.mjs +2 -1
- package/dist/db/adapter/get-field-name.mjs.map +1 -0
- package/dist/db/adapter/get-id-field.d.mts +3 -2
- package/dist/db/adapter/get-id-field.mjs +3 -2
- package/dist/db/adapter/get-id-field.mjs.map +1 -0
- package/dist/db/adapter/get-model-name.d.mts +2 -1
- package/dist/db/adapter/get-model-name.mjs +2 -1
- package/dist/db/adapter/get-model-name.mjs.map +1 -0
- package/dist/db/adapter/index.d.mts +10 -4
- package/dist/db/adapter/index.mjs +19 -2
- package/dist/db/adapter/index.mjs.map +1 -0
- package/dist/db/adapter/types.d.mts +3 -34
- package/dist/db/adapter/utils.d.mts +2 -1
- package/dist/db/adapter/utils.mjs +2 -1
- package/dist/db/adapter/utils.mjs.map +1 -0
- package/dist/db/get-tables.d.mts +2 -1
- package/dist/db/get-tables.mjs +46 -39
- package/dist/db/get-tables.mjs.map +1 -0
- package/dist/db/index.d.mts +7 -7
- package/dist/db/plugin.d.mts +2 -1
- package/dist/db/schema/account.d.mts +8 -4
- package/dist/db/schema/account.mjs +2 -1
- package/dist/db/schema/account.mjs.map +1 -0
- package/dist/db/schema/rate-limit.d.mts +8 -2
- package/dist/db/schema/rate-limit.mjs +2 -1
- package/dist/db/schema/rate-limit.mjs.map +1 -0
- package/dist/db/schema/session.d.mts +8 -4
- package/dist/db/schema/session.mjs +2 -1
- package/dist/db/schema/session.mjs.map +1 -0
- package/dist/db/schema/shared.d.mts +2 -1
- package/dist/db/schema/shared.mjs +2 -1
- package/dist/db/schema/shared.mjs.map +1 -0
- package/dist/db/schema/user.d.mts +8 -4
- package/dist/db/schema/user.mjs +2 -1
- package/dist/db/schema/user.mjs.map +1 -0
- package/dist/db/schema/verification.d.mts +8 -4
- package/dist/db/schema/verification.mjs +2 -1
- package/dist/db/schema/verification.mjs.map +1 -0
- package/dist/db/type.d.mts +28 -2
- package/dist/env/color-depth.d.mts +2 -1
- package/dist/env/color-depth.mjs +2 -1
- package/dist/env/color-depth.mjs.map +1 -0
- package/dist/env/env-impl.d.mts +3 -2
- package/dist/env/env-impl.mjs +9 -8
- package/dist/env/env-impl.mjs.map +1 -0
- package/dist/env/logger.d.mts +2 -1
- package/dist/env/logger.mjs +3 -2
- package/dist/env/logger.mjs.map +1 -0
- package/dist/error/codes.d.mts +64 -181
- package/dist/error/codes.mjs +6 -2
- package/dist/error/codes.mjs.map +1 -0
- package/dist/error/index.d.mts +2 -1
- package/dist/error/index.mjs +2 -1
- package/dist/error/index.mjs.map +1 -0
- package/dist/index.d.mts +5 -4
- package/dist/oauth2/client-credentials-token.d.mts +25 -3
- package/dist/oauth2/client-credentials-token.mjs +15 -2
- package/dist/oauth2/client-credentials-token.mjs.map +1 -0
- package/dist/oauth2/create-authorization-url.d.mts +5 -2
- package/dist/oauth2/create-authorization-url.mjs +3 -1
- package/dist/oauth2/create-authorization-url.mjs.map +1 -0
- package/dist/oauth2/index.d.mts +4 -4
- package/dist/oauth2/index.mjs +4 -4
- package/dist/oauth2/oauth-provider.d.mts +3 -2
- package/dist/oauth2/refresh-access-token.d.mts +24 -4
- package/dist/oauth2/refresh-access-token.mjs +20 -2
- package/dist/oauth2/refresh-access-token.mjs.map +1 -0
- package/dist/oauth2/utils.d.mts +2 -1
- package/dist/oauth2/utils.mjs +2 -1
- package/dist/oauth2/utils.mjs.map +1 -0
- package/dist/oauth2/validate-authorization-code.d.mts +37 -4
- package/dist/oauth2/validate-authorization-code.mjs +25 -13
- package/dist/oauth2/validate-authorization-code.mjs.map +1 -0
- package/dist/oauth2/verify.d.mts +7 -13
- package/dist/oauth2/verify.mjs +2 -1
- package/dist/oauth2/verify.mjs.map +1 -0
- package/dist/social-providers/apple.d.mts +2 -1
- package/dist/social-providers/apple.mjs +22 -21
- package/dist/social-providers/apple.mjs.map +1 -0
- package/dist/social-providers/atlassian.d.mts +2 -1
- package/dist/social-providers/atlassian.mjs +2 -1
- package/dist/social-providers/atlassian.mjs.map +1 -0
- package/dist/social-providers/cognito.d.mts +2 -1
- package/dist/social-providers/cognito.mjs +4 -3
- package/dist/social-providers/cognito.mjs.map +1 -0
- package/dist/social-providers/discord.d.mts +2 -1
- package/dist/social-providers/discord.mjs +2 -1
- package/dist/social-providers/discord.mjs.map +1 -0
- package/dist/social-providers/dropbox.d.mts +2 -1
- package/dist/social-providers/dropbox.mjs +2 -1
- package/dist/social-providers/dropbox.mjs.map +1 -0
- package/dist/social-providers/facebook.d.mts +2 -1
- package/dist/social-providers/facebook.mjs +13 -12
- package/dist/social-providers/facebook.mjs.map +1 -0
- package/dist/social-providers/figma.d.mts +2 -1
- package/dist/social-providers/figma.mjs +2 -1
- package/dist/social-providers/figma.mjs.map +1 -0
- package/dist/social-providers/github.d.mts +3 -2
- package/dist/social-providers/github.mjs +23 -6
- package/dist/social-providers/github.mjs.map +1 -0
- package/dist/social-providers/gitlab.d.mts +2 -1
- package/dist/social-providers/gitlab.mjs +3 -2
- package/dist/social-providers/gitlab.mjs.map +1 -0
- package/dist/social-providers/google.d.mts +2 -1
- package/dist/social-providers/google.mjs +18 -13
- package/dist/social-providers/google.mjs.map +1 -0
- package/dist/social-providers/huggingface.d.mts +2 -1
- package/dist/social-providers/huggingface.mjs +3 -2
- package/dist/social-providers/huggingface.mjs.map +1 -0
- package/dist/social-providers/index.d.mts +61 -8
- package/dist/social-providers/index.mjs +5 -2
- package/dist/social-providers/index.mjs.map +1 -0
- package/dist/social-providers/kakao.d.mts +3 -2
- package/dist/social-providers/kakao.mjs +3 -2
- package/dist/social-providers/kakao.mjs.map +1 -0
- package/dist/social-providers/kick.d.mts +2 -1
- package/dist/social-providers/kick.mjs +2 -1
- package/dist/social-providers/kick.mjs.map +1 -0
- package/dist/social-providers/line.d.mts +2 -1
- package/dist/social-providers/line.mjs +3 -2
- package/dist/social-providers/line.mjs.map +1 -0
- package/dist/social-providers/linear.d.mts +2 -1
- package/dist/social-providers/linear.mjs +2 -1
- package/dist/social-providers/linear.mjs.map +1 -0
- package/dist/social-providers/linkedin.d.mts +2 -1
- package/dist/social-providers/linkedin.mjs +2 -1
- package/dist/social-providers/linkedin.mjs.map +1 -0
- package/dist/social-providers/microsoft-entra-id.d.mts +4 -1
- package/dist/social-providers/microsoft-entra-id.mjs +36 -2
- package/dist/social-providers/microsoft-entra-id.mjs.map +1 -0
- package/dist/social-providers/naver.d.mts +11 -20
- package/dist/social-providers/naver.mjs +3 -2
- package/dist/social-providers/naver.mjs.map +1 -0
- package/dist/social-providers/notion.d.mts +2 -1
- package/dist/social-providers/notion.mjs +3 -2
- package/dist/social-providers/notion.mjs.map +1 -0
- package/dist/social-providers/paybin.d.mts +2 -1
- package/dist/social-providers/paybin.mjs +3 -2
- package/dist/social-providers/paybin.mjs.map +1 -0
- package/dist/social-providers/paypal.d.mts +2 -1
- package/dist/social-providers/paypal.mjs +2 -1
- package/dist/social-providers/paypal.mjs.map +1 -0
- package/dist/social-providers/polar.d.mts +2 -1
- package/dist/social-providers/polar.mjs +3 -2
- package/dist/social-providers/polar.mjs.map +1 -0
- package/dist/social-providers/railway.d.mts +68 -0
- package/dist/social-providers/railway.mjs +78 -0
- package/dist/social-providers/railway.mjs.map +1 -0
- package/dist/social-providers/reddit.d.mts +2 -1
- package/dist/social-providers/reddit.mjs +2 -1
- package/dist/social-providers/reddit.mjs.map +1 -0
- package/dist/social-providers/roblox.d.mts +2 -1
- package/dist/social-providers/roblox.mjs +2 -1
- package/dist/social-providers/roblox.mjs.map +1 -0
- package/dist/social-providers/salesforce.d.mts +2 -1
- package/dist/social-providers/salesforce.mjs +2 -1
- package/dist/social-providers/salesforce.mjs.map +1 -0
- package/dist/social-providers/slack.d.mts +2 -1
- package/dist/social-providers/slack.mjs +2 -1
- package/dist/social-providers/slack.mjs.map +1 -0
- package/dist/social-providers/spotify.d.mts +2 -1
- package/dist/social-providers/spotify.mjs +2 -1
- package/dist/social-providers/spotify.mjs.map +1 -0
- package/dist/social-providers/tiktok.d.mts +3 -3
- package/dist/social-providers/tiktok.mjs +3 -2
- package/dist/social-providers/tiktok.mjs.map +1 -0
- package/dist/social-providers/twitch.d.mts +2 -1
- package/dist/social-providers/twitch.mjs +2 -1
- package/dist/social-providers/twitch.mjs.map +1 -0
- package/dist/social-providers/twitter.d.mts +14 -25
- package/dist/social-providers/twitter.mjs +2 -1
- package/dist/social-providers/twitter.mjs.map +1 -0
- package/dist/social-providers/vercel.d.mts +2 -1
- package/dist/social-providers/vercel.mjs +3 -2
- package/dist/social-providers/vercel.mjs.map +1 -0
- package/dist/social-providers/vk.d.mts +2 -1
- package/dist/social-providers/vk.mjs +2 -1
- package/dist/social-providers/vk.mjs.map +1 -0
- package/dist/social-providers/zoom.d.mts +3 -10
- package/dist/social-providers/zoom.mjs +2 -1
- package/dist/social-providers/zoom.mjs.map +1 -0
- package/dist/types/context.d.mts +53 -21
- package/dist/types/cookie.d.mts +2 -1
- package/dist/types/helper.d.mts +4 -1
- package/dist/types/index.d.mts +4 -3
- package/dist/types/init-options.d.mts +231 -159
- package/dist/types/plugin-client.d.mts +4 -1
- package/dist/types/plugin.d.mts +12 -11
- package/dist/types/secret.d.mts +12 -0
- package/dist/utils/db.d.mts +12 -0
- package/dist/utils/db.mjs +17 -0
- package/dist/utils/db.mjs.map +1 -0
- package/dist/utils/deprecate.d.mts +2 -2
- package/dist/utils/deprecate.mjs +2 -1
- package/dist/utils/deprecate.mjs.map +1 -0
- package/dist/utils/error-codes.d.mts +8 -6
- package/dist/utils/error-codes.mjs +3 -2
- package/dist/utils/error-codes.mjs.map +1 -0
- package/dist/utils/id.d.mts +2 -1
- package/dist/utils/id.mjs +2 -1
- package/dist/utils/id.mjs.map +1 -0
- package/dist/utils/ip.d.mts +2 -1
- package/dist/utils/ip.mjs +2 -1
- package/dist/utils/ip.mjs.map +1 -0
- package/dist/utils/json.d.mts +2 -1
- package/dist/utils/json.mjs +2 -1
- package/dist/utils/json.mjs.map +1 -0
- package/dist/utils/string.d.mts +2 -1
- package/dist/utils/string.mjs +2 -1
- package/dist/utils/string.mjs.map +1 -0
- package/dist/utils/url.d.mts +2 -1
- package/dist/utils/url.mjs +2 -1
- package/dist/utils/url.mjs.map +1 -0
- package/package.json +35 -13
- package/src/db/adapter/factory.ts +41 -73
- package/src/db/adapter/get-id-field.ts +1 -3
- package/src/db/adapter/index.ts +20 -15
- package/src/db/adapter/types.ts +2 -41
- package/src/db/get-tables.ts +48 -37
- package/src/db/index.ts +30 -5
- package/src/db/schema/account.ts +16 -3
- package/src/db/schema/rate-limit.ts +16 -1
- package/src/db/schema/session.ts +15 -3
- package/src/db/schema/user.ts +15 -3
- package/src/db/schema/verification.ts +16 -3
- package/src/db/test/get-tables.test.ts +33 -0
- package/src/db/type.ts +154 -1
- package/src/env/env-impl.ts +2 -2
- package/src/env/logger.ts +1 -1
- package/src/error/codes.ts +17 -0
- package/src/oauth2/client-credentials-token.ts +26 -2
- package/src/oauth2/create-authorization-url.ts +3 -1
- package/src/oauth2/index.ts +3 -0
- package/src/oauth2/oauth-provider.ts +1 -1
- package/src/oauth2/refresh-access-token.test.ts +90 -0
- package/src/oauth2/refresh-access-token.ts +37 -4
- package/src/oauth2/validate-authorization-code.ts +55 -24
- package/src/oauth2/validate-token.test.ts +107 -52
- package/src/social-providers/apple.ts +29 -29
- package/src/social-providers/cognito.ts +6 -5
- package/src/social-providers/facebook.ts +3 -3
- package/src/social-providers/github.ts +26 -4
- package/src/social-providers/gitlab.ts +1 -1
- package/src/social-providers/google.ts +18 -14
- package/src/social-providers/huggingface.ts +1 -1
- package/src/social-providers/index.ts +9 -5
- package/src/social-providers/kakao.ts +1 -1
- package/src/social-providers/line.ts +1 -1
- package/src/social-providers/microsoft-entra-id.ts +84 -1
- package/src/social-providers/naver.ts +1 -1
- package/src/social-providers/notion.ts +1 -1
- package/src/social-providers/paybin.ts +1 -5
- package/src/social-providers/polar.ts +1 -1
- package/src/social-providers/railway.ts +100 -0
- package/src/social-providers/tiktok.ts +2 -1
- package/src/social-providers/vercel.ts +1 -1
- package/src/social-providers/zoom.ts +0 -8
- package/src/types/context.ts +74 -14
- package/src/types/helper.ts +9 -0
- package/src/types/index.ts +14 -2
- package/src/types/init-options.ts +294 -186
- package/src/types/plugin-client.ts +1 -0
- package/src/types/plugin.ts +11 -6
- package/src/types/secret.ts +8 -0
- package/src/utils/db.ts +20 -0
- package/src/utils/deprecate.test.ts +0 -1
- package/src/utils/error-codes.ts +12 -9
- package/.turbo/turbo-build.log +0 -182
- package/tsconfig.json +0 -7
- package/tsdown.config.ts +0 -32
- package/vitest.config.ts +0 -3
|
@@ -1,32 +1,76 @@
|
|
|
1
1
|
import { DBFieldAttribute, ModelNames, SecondaryStorage } from "../db/type.mjs";
|
|
2
|
-
import { Account } from "../db/schema/account.mjs";
|
|
3
|
-
import { RateLimit } from "../db/schema/rate-limit.mjs";
|
|
4
|
-
import { Session } from "../db/schema/session.mjs";
|
|
5
|
-
import { User } from "../db/schema/user.mjs";
|
|
6
|
-
import { Verification } from "../db/schema/verification.mjs";
|
|
7
|
-
import "../db/index.mjs";
|
|
8
|
-
import { Awaitable, LiteralUnion } from "./helper.mjs";
|
|
9
2
|
import { DBAdapterDebugLogOption, DBAdapterInstance } from "../db/adapter/index.mjs";
|
|
3
|
+
import { BaseRateLimit, RateLimit } from "../db/schema/rate-limit.mjs";
|
|
4
|
+
import { BaseSession, Session } from "../db/schema/session.mjs";
|
|
5
|
+
import { BaseUser, User } from "../db/schema/user.mjs";
|
|
6
|
+
import { BaseVerification, Verification } from "../db/schema/verification.mjs";
|
|
10
7
|
import { Logger } from "../env/logger.mjs";
|
|
11
8
|
import { SocialProviderList, SocialProviders } from "../social-providers/index.mjs";
|
|
9
|
+
import { Awaitable, LiteralString, LiteralUnion } from "./helper.mjs";
|
|
12
10
|
import { BetterAuthPlugin } from "./plugin.mjs";
|
|
11
|
+
import { Account, BaseAccount } from "../db/schema/account.mjs";
|
|
12
|
+
import "../db/index.mjs";
|
|
13
13
|
import { AuthContext, GenericEndpointContext } from "./context.mjs";
|
|
14
14
|
import { AuthMiddleware } from "../api/index.mjs";
|
|
15
15
|
import { CookieOptions } from "better-call";
|
|
16
16
|
import { Database } from "bun:sqlite";
|
|
17
17
|
import { DatabaseSync } from "node:sqlite";
|
|
18
|
+
import { D1Database } from "@cloudflare/workers-types";
|
|
18
19
|
import { Dialect, Kysely, MysqlPool, PostgresPool, SqliteDatabase } from "kysely";
|
|
19
20
|
|
|
20
21
|
//#region src/types/init-options.d.ts
|
|
21
22
|
type KyselyDatabaseType = "postgres" | "mysql" | "sqlite" | "mssql";
|
|
22
|
-
type OmitId<T extends {
|
|
23
|
-
id: unknown;
|
|
24
|
-
}> = Omit<T, "id">;
|
|
25
23
|
type Optional<T> = { [P in keyof T]?: T[P] | undefined };
|
|
24
|
+
type StoreIdentifierOption = "plain" | "hashed" | {
|
|
25
|
+
hash: (identifier: string) => Promise<string>;
|
|
26
|
+
};
|
|
26
27
|
type GenerateIdFn = (options: {
|
|
27
28
|
model: ModelNames;
|
|
28
29
|
size?: number | undefined;
|
|
29
30
|
}) => string | false;
|
|
31
|
+
/**
|
|
32
|
+
* Configuration for dynamic base URL resolution.
|
|
33
|
+
* Allows Better Auth to work with multiple domains (e.g., Vercel preview deployments).
|
|
34
|
+
*/
|
|
35
|
+
type DynamicBaseURLConfig = {
|
|
36
|
+
/**
|
|
37
|
+
* List of allowed hostnames. Supports wildcard patterns.
|
|
38
|
+
*
|
|
39
|
+
* The derived host from the request will be validated against this list.
|
|
40
|
+
* Uses the same wildcard matching as `trustedOrigins`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* allowedHosts: [
|
|
45
|
+
* "myapp.com", // Exact match
|
|
46
|
+
* "*.vercel.app", // Any Vercel preview
|
|
47
|
+
* "preview-*.myapp.com" // Pattern match
|
|
48
|
+
* ]
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
allowedHosts: string[];
|
|
52
|
+
/**
|
|
53
|
+
* Fallback URL to use if the derived host doesn't match any allowed host.
|
|
54
|
+
* If not set, Better Auth will throw an error when the host doesn't match.
|
|
55
|
+
*
|
|
56
|
+
* @example "https://myapp.com"
|
|
57
|
+
*/
|
|
58
|
+
fallback?: string | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Protocol to use when constructing the URL.
|
|
61
|
+
* - `"https"`: Always use HTTPS (recommended for production)
|
|
62
|
+
* - `"http"`: Always use HTTP (for local development)
|
|
63
|
+
* - `"auto"`: Derive from `x-forwarded-proto` header or default to HTTPS
|
|
64
|
+
*
|
|
65
|
+
* @default "auto"
|
|
66
|
+
*/
|
|
67
|
+
protocol?: "http" | "https" | "auto" | undefined;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Base URL configuration.
|
|
71
|
+
* Can be a static string or a dynamic config for multi-domain deployments.
|
|
72
|
+
*/
|
|
73
|
+
type BaseURLConfig = string | DynamicBaseURLConfig;
|
|
30
74
|
interface BetterAuthRateLimitStorage {
|
|
31
75
|
get: (key: string) => Promise<RateLimit | null | undefined>;
|
|
32
76
|
set: (key: string, value: RateLimit, update?: boolean | undefined) => Promise<void>;
|
|
@@ -46,7 +90,21 @@ type BetterAuthRateLimitRule = {
|
|
|
46
90
|
*/
|
|
47
91
|
max: number;
|
|
48
92
|
};
|
|
49
|
-
type
|
|
93
|
+
type BetterAuthDBOptions<ModelName extends string, Keys extends string = string> = {
|
|
94
|
+
/**
|
|
95
|
+
* The name of the model. Defaults to the model name.
|
|
96
|
+
*/
|
|
97
|
+
modelName?: ModelName | LiteralString;
|
|
98
|
+
/**
|
|
99
|
+
* Map fields to database columns
|
|
100
|
+
*/
|
|
101
|
+
fields?: Partial<Record<Exclude<Keys, "id">, string>>;
|
|
102
|
+
/**
|
|
103
|
+
* Additional fields for the model
|
|
104
|
+
*/
|
|
105
|
+
additionalFields?: { [Key in Exclude<string, Keys | "id">]: DBFieldAttribute };
|
|
106
|
+
};
|
|
107
|
+
type BetterAuthRateLimitOptions = Optional<BetterAuthRateLimitRule> & Omit<BetterAuthDBOptions<"rateLimit", keyof BaseRateLimit>, "additionalFields"> & {
|
|
50
108
|
/**
|
|
51
109
|
* By default, rate limiting is only
|
|
52
110
|
* enabled on production.
|
|
@@ -69,17 +127,6 @@ type BetterAuthRateLimitOptions = Optional<BetterAuthRateLimitRule> & {
|
|
|
69
127
|
* @default "memory"
|
|
70
128
|
*/
|
|
71
129
|
storage?: ("memory" | "database" | "secondary-storage") | undefined;
|
|
72
|
-
/**
|
|
73
|
-
* If database is used as storage, the name of the table to
|
|
74
|
-
* use for rate limiting.
|
|
75
|
-
*
|
|
76
|
-
* @default "rateLimit"
|
|
77
|
-
*/
|
|
78
|
-
modelName?: string | undefined;
|
|
79
|
-
/**
|
|
80
|
-
* Custom field names for the rate limit table
|
|
81
|
-
*/
|
|
82
|
-
fields?: Partial<Record<keyof RateLimit, string>> | undefined;
|
|
83
130
|
/**
|
|
84
131
|
* custom storage configuration.
|
|
85
132
|
*
|
|
@@ -112,23 +159,11 @@ type BetterAuthAdvancedOptions = {
|
|
|
112
159
|
disableIpTracking?: boolean;
|
|
113
160
|
/**
|
|
114
161
|
* IPv6 subnet prefix length for rate limiting.
|
|
162
|
+
* IPv6 addresses will be normalized to this subnet.
|
|
115
163
|
*
|
|
116
|
-
*
|
|
117
|
-
* bypassing rate limits by rotating through multiple addresses in
|
|
118
|
-
* their allocation.
|
|
119
|
-
*
|
|
120
|
-
* Common values:
|
|
121
|
-
* - 128 (default): Individual IPv6 address
|
|
122
|
-
* - 64: /64 subnet (typical home/business allocation)
|
|
123
|
-
* - 48: /48 subnet (larger network allocation)
|
|
124
|
-
* - 32: /32 subnet (ISP allocation)
|
|
125
|
-
*
|
|
126
|
-
* Note: This only affects IPv6 addresses. IPv4 addresses are always
|
|
127
|
-
* rate limited individually.
|
|
128
|
-
*
|
|
129
|
-
* @default 64 (/64 subnet)
|
|
164
|
+
* @default 64
|
|
130
165
|
*/
|
|
131
|
-
ipv6Subnet?: 128 | 64 | 48 | 32
|
|
166
|
+
ipv6Subnet?: 128 | 64 | 48 | 32;
|
|
132
167
|
} | undefined;
|
|
133
168
|
/**
|
|
134
169
|
* Use secure cookies
|
|
@@ -213,17 +248,6 @@ type BetterAuthAdvancedOptions = {
|
|
|
213
248
|
* @default 100
|
|
214
249
|
*/
|
|
215
250
|
defaultFindManyLimit?: number;
|
|
216
|
-
/**
|
|
217
|
-
* If your database auto increments number ids, set this to `true`.
|
|
218
|
-
*
|
|
219
|
-
* Note: If enabled, we will not handle ID generation (including if you use `generateId`), and it would be expected that your database will provide the ID automatically.
|
|
220
|
-
*
|
|
221
|
-
* @default false
|
|
222
|
-
*
|
|
223
|
-
* @deprecated Please use `generateId` instead. This will be removed in future
|
|
224
|
-
* releases.
|
|
225
|
-
*/
|
|
226
|
-
useNumberId?: boolean;
|
|
227
251
|
/**
|
|
228
252
|
* Custom generateId function.
|
|
229
253
|
*
|
|
@@ -277,14 +301,17 @@ type BetterAuthAdvancedOptions = {
|
|
|
277
301
|
* }
|
|
278
302
|
*/
|
|
279
303
|
backgroundTasks?: {
|
|
280
|
-
handler: (promise: Promise<
|
|
304
|
+
handler: (promise: Promise<unknown>) => void;
|
|
281
305
|
};
|
|
282
306
|
/**
|
|
283
|
-
* Skip trailing
|
|
307
|
+
* Skip trailing slashes in API routes.
|
|
308
|
+
*
|
|
309
|
+
* When enabled, requests with trailing slashes (e.g., `/api/auth/session/`)
|
|
310
|
+
* will be handled the same as requests without (e.g., `/api/auth/session`).
|
|
284
311
|
*
|
|
285
312
|
* @default false
|
|
286
313
|
*/
|
|
287
|
-
skipTrailingSlashes?: boolean
|
|
314
|
+
skipTrailingSlashes?: boolean;
|
|
288
315
|
};
|
|
289
316
|
type BetterAuthOptions = {
|
|
290
317
|
/**
|
|
@@ -298,12 +325,27 @@ type BetterAuthOptions = {
|
|
|
298
325
|
/**
|
|
299
326
|
* Base URL for the Better Auth. This is typically the
|
|
300
327
|
* root URL where your application server is hosted.
|
|
301
|
-
* If not explicitly set,
|
|
302
|
-
* the system will check the following environment variable:
|
|
303
328
|
*
|
|
304
|
-
*
|
|
329
|
+
* Can be configured as:
|
|
330
|
+
* - A static string: `"https://myapp.com"`
|
|
331
|
+
* - A dynamic config with allowed hosts for multi-domain deployments
|
|
332
|
+
*
|
|
333
|
+
* If not explicitly set, the system will check environment variables:
|
|
334
|
+
* `BETTER_AUTH_URL`, `NEXT_PUBLIC_BETTER_AUTH_URL`, etc.
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```ts
|
|
338
|
+
* // Static URL
|
|
339
|
+
* baseURL: "https://myapp.com"
|
|
340
|
+
*
|
|
341
|
+
* // Dynamic with allowed hosts (for Vercel, multi-domain, etc.)
|
|
342
|
+
* baseURL: {
|
|
343
|
+
* allowedHosts: ["myapp.com", "*.vercel.app", "preview-*.myapp.com"],
|
|
344
|
+
* fallback: "https://myapp.com"
|
|
345
|
+
* }
|
|
346
|
+
* ```
|
|
305
347
|
*/
|
|
306
|
-
baseURL?:
|
|
348
|
+
baseURL?: BaseURLConfig | undefined;
|
|
307
349
|
/**
|
|
308
350
|
* Base path for the Better Auth. This is typically
|
|
309
351
|
* the path where the
|
|
@@ -336,10 +378,26 @@ type BetterAuthOptions = {
|
|
|
336
378
|
* ```
|
|
337
379
|
*/
|
|
338
380
|
secret?: string | undefined;
|
|
381
|
+
/**
|
|
382
|
+
* Versioned secrets for non-destructive secret rotation.
|
|
383
|
+
* When set, encryption uses an envelope format with key IDs.
|
|
384
|
+
* First entry is the current key used for new encryption.
|
|
385
|
+
* Remaining entries are decryption-only (previous rotations).
|
|
386
|
+
*
|
|
387
|
+
* Can also be set via BETTER_AUTH_SECRETS env var:
|
|
388
|
+
* `BETTER_AUTH_SECRETS=2:base64secret,1:base64secret`
|
|
389
|
+
*
|
|
390
|
+
* When set, `secret` is only used as legacy fallback
|
|
391
|
+
* for decrypting bare-hex payloads that predate the envelope format.
|
|
392
|
+
*/
|
|
393
|
+
secrets?: Array<{
|
|
394
|
+
version: number;
|
|
395
|
+
value: string;
|
|
396
|
+
}> | undefined;
|
|
339
397
|
/**
|
|
340
398
|
* Database configuration
|
|
341
399
|
*/
|
|
342
|
-
database?: (PostgresPool | MysqlPool | SqliteDatabase | Dialect | DBAdapterInstance | Database | DatabaseSync | {
|
|
400
|
+
database?: (PostgresPool | MysqlPool | SqliteDatabase | Dialect | DBAdapterInstance | Database | DatabaseSync | D1Database | {
|
|
343
401
|
dialect: Dialect;
|
|
344
402
|
type: KyselyDatabaseType;
|
|
345
403
|
/**
|
|
@@ -425,10 +483,13 @@ type BetterAuthOptions = {
|
|
|
425
483
|
*/
|
|
426
484
|
request?: Request) => Promise<void>;
|
|
427
485
|
/**
|
|
428
|
-
* Send a verification email automatically
|
|
429
|
-
* after sign up
|
|
486
|
+
* Send a verification email automatically after sign up.
|
|
430
487
|
*
|
|
431
|
-
*
|
|
488
|
+
* - `true`: Always send verification email on sign up
|
|
489
|
+
* - `false`: Never send verification email on sign up
|
|
490
|
+
* - `undefined`: Follows `requireEmailVerification` behavior
|
|
491
|
+
*
|
|
492
|
+
* @default undefined
|
|
432
493
|
*/
|
|
433
494
|
sendOnSignUp?: boolean;
|
|
434
495
|
/**
|
|
@@ -448,13 +509,6 @@ type BetterAuthOptions = {
|
|
|
448
509
|
* @default 3600 seconds (1 hour)
|
|
449
510
|
*/
|
|
450
511
|
expiresIn?: number;
|
|
451
|
-
/**
|
|
452
|
-
* A function that is called when a user verifies their email
|
|
453
|
-
* @param user the user that verified their email
|
|
454
|
-
* @param request the request object
|
|
455
|
-
* @deprecated Use `beforeEmailVerification` or `afterEmailVerification` instead. This will be removed in 1.5
|
|
456
|
-
*/
|
|
457
|
-
onEmailVerification?: (user: User, request?: Request) => Promise<void>;
|
|
458
512
|
/**
|
|
459
513
|
* A function that is called before a user verifies their email
|
|
460
514
|
* @param user the user that verified their email
|
|
@@ -563,6 +617,56 @@ type BetterAuthOptions = {
|
|
|
563
617
|
* @default false
|
|
564
618
|
*/
|
|
565
619
|
revokeSessionsOnPasswordReset?: boolean;
|
|
620
|
+
/**
|
|
621
|
+
* A callback function that is triggered when a user tries to sign up
|
|
622
|
+
* with an email that already exists. Useful for notifying the existing user
|
|
623
|
+
* that someone attempted to register with their email.
|
|
624
|
+
*
|
|
625
|
+
* This is only called when `requireEmailVerification: true` or `autoSignIn: false`.
|
|
626
|
+
*/
|
|
627
|
+
onExistingUserSignUp?: (
|
|
628
|
+
/**
|
|
629
|
+
* @param user the existing user from the database
|
|
630
|
+
*/
|
|
631
|
+
data: {
|
|
632
|
+
user: User;
|
|
633
|
+
}, request?: Request) => Promise<void>;
|
|
634
|
+
/**
|
|
635
|
+
* Build a custom synthetic user for email enumeration
|
|
636
|
+
* protection. When a sign-up attempt is made with an
|
|
637
|
+
* email that already exists, this function is called
|
|
638
|
+
* to build the fake user response.
|
|
639
|
+
*
|
|
640
|
+
* Use this when plugins add fields to the user table
|
|
641
|
+
* (e.g. admin plugin adds `role`, `banned`, etc.)
|
|
642
|
+
* to ensure the fake response is indistinguishable
|
|
643
|
+
* from a real sign-up.
|
|
644
|
+
*
|
|
645
|
+
* @example
|
|
646
|
+
* ```ts
|
|
647
|
+
* customSyntheticUser: ({ coreFields, additionalFields, id }) => ({
|
|
648
|
+
* ...coreFields,
|
|
649
|
+
* role: "user",
|
|
650
|
+
* banned: false,
|
|
651
|
+
* banReason: null,
|
|
652
|
+
* banExpires: null,
|
|
653
|
+
* ...additionalFields,
|
|
654
|
+
* id,
|
|
655
|
+
* })
|
|
656
|
+
* ```
|
|
657
|
+
*/
|
|
658
|
+
customSyntheticUser?: (params: {
|
|
659
|
+
/** Core user fields: name, email, emailVerified, image, createdAt, updatedAt */coreFields: {
|
|
660
|
+
name: string;
|
|
661
|
+
email: string;
|
|
662
|
+
emailVerified: boolean;
|
|
663
|
+
image: string | null;
|
|
664
|
+
createdAt: Date;
|
|
665
|
+
updatedAt: Date;
|
|
666
|
+
}; /** Processed additional fields from options.user.additionalFields (with defaults applied) */
|
|
667
|
+
additionalFields: Record<string, unknown>; /** Generated user ID */
|
|
668
|
+
id: string;
|
|
669
|
+
}) => Record<string, unknown>;
|
|
566
670
|
} | undefined;
|
|
567
671
|
/**
|
|
568
672
|
* list of social providers
|
|
@@ -575,28 +679,7 @@ type BetterAuthOptions = {
|
|
|
575
679
|
/**
|
|
576
680
|
* User configuration
|
|
577
681
|
*/
|
|
578
|
-
user?: {
|
|
579
|
-
/**
|
|
580
|
-
* The model name for the user. Defaults to "user".
|
|
581
|
-
*/
|
|
582
|
-
modelName?: string;
|
|
583
|
-
/**
|
|
584
|
-
* Map fields
|
|
585
|
-
*
|
|
586
|
-
* @example
|
|
587
|
-
* ```ts
|
|
588
|
-
* {
|
|
589
|
-
* userId: "user_id"
|
|
590
|
-
* }
|
|
591
|
-
* ```
|
|
592
|
-
*/
|
|
593
|
-
fields?: Partial<Record<keyof OmitId<User>, string>>;
|
|
594
|
-
/**
|
|
595
|
-
* Additional fields for the user
|
|
596
|
-
*/
|
|
597
|
-
additionalFields?: {
|
|
598
|
-
[key: string]: DBFieldAttribute;
|
|
599
|
-
};
|
|
682
|
+
user?: (BetterAuthDBOptions<"user", keyof BaseUser> & {
|
|
600
683
|
/**
|
|
601
684
|
* Changing email configuration
|
|
602
685
|
*/
|
|
@@ -606,18 +689,6 @@ type BetterAuthOptions = {
|
|
|
606
689
|
* @default false
|
|
607
690
|
*/
|
|
608
691
|
enabled: boolean;
|
|
609
|
-
/**
|
|
610
|
-
* Send a verification email when the user changes their email.
|
|
611
|
-
* @param data the data object
|
|
612
|
-
* @param request the request object
|
|
613
|
-
* @deprecated Use `sendChangeEmailConfirmation` instead
|
|
614
|
-
*/
|
|
615
|
-
sendChangeEmailVerification?: (data: {
|
|
616
|
-
user: User;
|
|
617
|
-
newEmail: string;
|
|
618
|
-
url: string;
|
|
619
|
-
token: string;
|
|
620
|
-
}, request?: Request) => Promise<void>;
|
|
621
692
|
/**
|
|
622
693
|
* Send a confirmation email to the old email address when the user changes their email.
|
|
623
694
|
* @param data the data object
|
|
@@ -674,24 +745,8 @@ type BetterAuthOptions = {
|
|
|
674
745
|
*/
|
|
675
746
|
deleteTokenExpiresIn?: number;
|
|
676
747
|
};
|
|
677
|
-
} | undefined;
|
|
678
|
-
session?: {
|
|
679
|
-
/**
|
|
680
|
-
* The model name for the session.
|
|
681
|
-
*
|
|
682
|
-
* @default "session"
|
|
683
|
-
*/
|
|
684
|
-
modelName?: string;
|
|
685
|
-
/**
|
|
686
|
-
* Map fields
|
|
687
|
-
*
|
|
688
|
-
* @example
|
|
689
|
-
* ```ts
|
|
690
|
-
* {
|
|
691
|
-
* userId: "user_id"
|
|
692
|
-
* }
|
|
693
|
-
*/
|
|
694
|
-
fields?: Partial<Record<keyof OmitId<Session>, string>>;
|
|
748
|
+
}) | undefined;
|
|
749
|
+
session?: (BetterAuthDBOptions<"session", keyof BaseSession> & {
|
|
695
750
|
/**
|
|
696
751
|
* Expiration time for the session token. The value
|
|
697
752
|
* should be in seconds.
|
|
@@ -713,11 +768,13 @@ type BetterAuthOptions = {
|
|
|
713
768
|
*/
|
|
714
769
|
disableSessionRefresh?: boolean;
|
|
715
770
|
/**
|
|
716
|
-
*
|
|
771
|
+
* Defer session refresh writes to POST requests.
|
|
772
|
+
* When enabled, GET is read-only and POST performs refresh.
|
|
773
|
+
* Useful for read-replica database setups.
|
|
774
|
+
*
|
|
775
|
+
* @default false
|
|
717
776
|
*/
|
|
718
|
-
|
|
719
|
-
[key: string]: DBFieldAttribute;
|
|
720
|
-
};
|
|
777
|
+
deferSessionRefresh?: boolean;
|
|
721
778
|
/**
|
|
722
779
|
* By default if secondary storage is provided
|
|
723
780
|
* the session is stored in the secondary storage.
|
|
@@ -816,22 +873,8 @@ type BetterAuthOptions = {
|
|
|
816
873
|
* @default 1 day (60 * 60 * 24)
|
|
817
874
|
*/
|
|
818
875
|
freshAge?: number;
|
|
819
|
-
} | undefined;
|
|
820
|
-
account?: {
|
|
821
|
-
/**
|
|
822
|
-
* The model name for the account. Defaults to "account".
|
|
823
|
-
*/
|
|
824
|
-
modelName?: string;
|
|
825
|
-
/**
|
|
826
|
-
* Map fields
|
|
827
|
-
*/
|
|
828
|
-
fields?: Partial<Record<keyof OmitId<Account>, string>>;
|
|
829
|
-
/**
|
|
830
|
-
* Additional fields for the account
|
|
831
|
-
*/
|
|
832
|
-
additionalFields?: {
|
|
833
|
-
[key: string]: DBFieldAttribute;
|
|
834
|
-
};
|
|
876
|
+
}) | undefined;
|
|
877
|
+
account?: (BetterAuthDBOptions<"account", keyof BaseAccount> & {
|
|
835
878
|
/**
|
|
836
879
|
* When enabled (true), the user account data (accessToken, idToken, refreshToken, etc.)
|
|
837
880
|
* will be updated on sign in with the latest data from the provider.
|
|
@@ -850,9 +893,38 @@ type BetterAuthOptions = {
|
|
|
850
893
|
*/
|
|
851
894
|
enabled?: boolean;
|
|
852
895
|
/**
|
|
853
|
-
*
|
|
896
|
+
* Disable implicit account linking on sign-in.
|
|
897
|
+
*
|
|
898
|
+
* When enabled, accounts will not be automatically linked
|
|
899
|
+
* during OAuth sign-in, even if the email is verified or
|
|
900
|
+
* the provider is trusted. Users must explicitly link
|
|
901
|
+
* accounts using `linkSocial()` while authenticated.
|
|
902
|
+
*
|
|
903
|
+
* @default false
|
|
904
|
+
*/
|
|
905
|
+
disableImplicitLinking?: boolean;
|
|
906
|
+
/**
|
|
907
|
+
* List of trusted providers. Can be a static array or a function
|
|
908
|
+
* that returns providers dynamically. The function is called
|
|
909
|
+
* during context init (with `request` undefined) and again
|
|
910
|
+
* on each request (with the incoming Request). It must be
|
|
911
|
+
* resilient to `request` being undefined.
|
|
912
|
+
*
|
|
913
|
+
* @example
|
|
914
|
+
* ```ts
|
|
915
|
+
* trustedProviders: ["google", "github"]
|
|
916
|
+
* ```
|
|
917
|
+
*
|
|
918
|
+
* @example
|
|
919
|
+
* ```ts
|
|
920
|
+
* trustedProviders: async (request) => {
|
|
921
|
+
* if (!request) return [];
|
|
922
|
+
* const providers = await getTrustedProvidersForTenant(request);
|
|
923
|
+
* return providers;
|
|
924
|
+
* }
|
|
925
|
+
* ```
|
|
854
926
|
*/
|
|
855
|
-
trustedProviders?: Array<LiteralUnion<SocialProviderList[number] | "email-password", string
|
|
927
|
+
trustedProviders?: Array<LiteralUnion<SocialProviderList[number] | "email-password", string>> | ((request?: Request | undefined) => Awaitable<Array<LiteralUnion<SocialProviderList[number] | "email-password", string>>>);
|
|
856
928
|
/**
|
|
857
929
|
* If enabled (true), this will allow users to manually linking accounts with different email addresses than the main user.
|
|
858
930
|
*
|
|
@@ -914,31 +986,30 @@ type BetterAuthOptions = {
|
|
|
914
986
|
* @note This is automatically set to true if you haven't passed a database
|
|
915
987
|
*/
|
|
916
988
|
storeAccountCookie?: boolean;
|
|
917
|
-
} | undefined;
|
|
918
|
-
|
|
919
|
-
* Verification configuration
|
|
920
|
-
*/
|
|
921
|
-
verification?: {
|
|
922
|
-
/**
|
|
923
|
-
* Change the modelName of the verification table
|
|
924
|
-
*/
|
|
925
|
-
modelName?: string;
|
|
989
|
+
}) | undefined;
|
|
990
|
+
verification?: (BetterAuthDBOptions<"verification", keyof BaseVerification> & {
|
|
926
991
|
/**
|
|
927
|
-
*
|
|
992
|
+
* disable cleaning up expired values when a verification value is
|
|
993
|
+
* fetched
|
|
928
994
|
*/
|
|
929
|
-
|
|
995
|
+
disableCleanup?: boolean;
|
|
930
996
|
/**
|
|
931
|
-
*
|
|
997
|
+
* How to store verification identifiers (tokens, OTPs, etc.)
|
|
998
|
+
*
|
|
999
|
+
* @example "hashed"
|
|
1000
|
+
*
|
|
1001
|
+
* @default "plain"
|
|
932
1002
|
*/
|
|
933
|
-
|
|
934
|
-
|
|
1003
|
+
storeIdentifier?: StoreIdentifierOption | {
|
|
1004
|
+
default: StoreIdentifierOption;
|
|
1005
|
+
overrides?: Record<string, StoreIdentifierOption>;
|
|
935
1006
|
};
|
|
936
1007
|
/**
|
|
937
|
-
*
|
|
938
|
-
*
|
|
1008
|
+
* Store verification data in database even when secondary storage is configured.
|
|
1009
|
+
* @default false
|
|
939
1010
|
*/
|
|
940
|
-
|
|
941
|
-
} | undefined;
|
|
1011
|
+
storeInDatabase?: boolean;
|
|
1012
|
+
}) | undefined;
|
|
942
1013
|
/**
|
|
943
1014
|
* List of trusted origins.
|
|
944
1015
|
*
|
|
@@ -1276,4 +1347,5 @@ type BetterAuthOptions = {
|
|
|
1276
1347
|
};
|
|
1277
1348
|
};
|
|
1278
1349
|
//#endregion
|
|
1279
|
-
export { BetterAuthAdvancedOptions, BetterAuthOptions, BetterAuthRateLimitOptions, BetterAuthRateLimitRule, BetterAuthRateLimitStorage, GenerateIdFn };
|
|
1350
|
+
export { BaseURLConfig, BetterAuthAdvancedOptions, BetterAuthDBOptions, BetterAuthOptions, BetterAuthRateLimitOptions, BetterAuthRateLimitRule, BetterAuthRateLimitStorage, DynamicBaseURLConfig, GenerateIdFn, StoreIdentifierOption };
|
|
1351
|
+
//# sourceMappingURL=init-options.d.mts.map
|
|
@@ -13,6 +13,7 @@ interface ClientStore {
|
|
|
13
13
|
type ClientAtomListener = {
|
|
14
14
|
matcher: (path: string) => boolean;
|
|
15
15
|
signal: "$sessionSignal" | Omit<string, "$sessionSignal">;
|
|
16
|
+
callback?: (path: string) => void;
|
|
16
17
|
};
|
|
17
18
|
/**
|
|
18
19
|
* Better-Fetch options but with additional options for the auth-client.
|
|
@@ -77,6 +78,7 @@ interface BetterAuthClientPlugin {
|
|
|
77
78
|
/**
|
|
78
79
|
* better-auth client options
|
|
79
80
|
*/
|
|
81
|
+
|
|
80
82
|
options: BetterAuthClientOptions | undefined) => Record<string, any>;
|
|
81
83
|
/**
|
|
82
84
|
* State atoms that'll be resolved by each framework
|
|
@@ -107,4 +109,5 @@ interface BetterAuthClientPlugin {
|
|
|
107
109
|
}>;
|
|
108
110
|
}
|
|
109
111
|
//#endregion
|
|
110
|
-
export { BetterAuthClientOptions, BetterAuthClientPlugin, ClientAtomListener, ClientFetchOption, ClientStore };
|
|
112
|
+
export { BetterAuthClientOptions, BetterAuthClientPlugin, ClientAtomListener, ClientFetchOption, ClientStore };
|
|
113
|
+
//# sourceMappingURL=plugin-client.d.mts.map
|
package/dist/types/plugin.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { BetterAuthPluginDBSchema } from "../db/plugin.mjs";
|
|
2
|
-
import "../db/index.mjs";
|
|
3
2
|
import { Awaitable, LiteralString } from "./helper.mjs";
|
|
3
|
+
import { RawError } from "../utils/error-codes.mjs";
|
|
4
4
|
import { BetterAuthOptions } from "./init-options.mjs";
|
|
5
|
+
import "../db/index.mjs";
|
|
5
6
|
import { AuthContext } from "./context.mjs";
|
|
6
7
|
import { AuthMiddleware } from "../api/index.mjs";
|
|
7
8
|
import { Endpoint, EndpointContext, InputContext, Middleware } from "better-call";
|
|
@@ -17,14 +18,20 @@ type HookEndpointContext = Partial<EndpointContext<string, any> & Omit<InputCont
|
|
|
17
18
|
};
|
|
18
19
|
headers?: Headers | undefined;
|
|
19
20
|
};
|
|
20
|
-
type
|
|
21
|
+
type BetterAuthPluginErrorCodePart = {
|
|
22
|
+
/**
|
|
23
|
+
* The error codes returned by the plugin
|
|
24
|
+
*/
|
|
25
|
+
$ERROR_CODES?: Record<string, RawError>;
|
|
26
|
+
};
|
|
27
|
+
type BetterAuthPlugin = BetterAuthPluginErrorCodePart & {
|
|
21
28
|
id: LiteralString;
|
|
22
29
|
/**
|
|
23
30
|
* The init function is called when the plugin is initialized.
|
|
24
31
|
* You can return a new context or modify the existing context.
|
|
25
32
|
*/
|
|
26
33
|
init?: ((ctx: AuthContext) => Awaitable<{
|
|
27
|
-
context?: DeepPartial<Omit<AuthContext, "options"
|
|
34
|
+
context?: DeepPartial<Omit<AuthContext, "options">> & Record<string, unknown>;
|
|
28
35
|
options?: Partial<BetterAuthOptions>;
|
|
29
36
|
}> | void | Promise<void>) | undefined;
|
|
30
37
|
endpoints?: {
|
|
@@ -104,13 +111,6 @@ type BetterAuthPlugin = {
|
|
|
104
111
|
max: number;
|
|
105
112
|
pathMatcher: (path: string) => boolean;
|
|
106
113
|
}[] | undefined;
|
|
107
|
-
/**
|
|
108
|
-
* The error codes returned by the plugin
|
|
109
|
-
*/
|
|
110
|
-
$ERROR_CODES?: Record<string, {
|
|
111
|
-
code: string;
|
|
112
|
-
message: string;
|
|
113
|
-
}> | undefined;
|
|
114
114
|
/**
|
|
115
115
|
* All database operations that are performed by the plugin
|
|
116
116
|
*
|
|
@@ -121,4 +121,5 @@ type BetterAuthPlugin = {
|
|
|
121
121
|
};
|
|
122
122
|
};
|
|
123
123
|
//#endregion
|
|
124
|
-
export { BetterAuthPlugin, HookEndpointContext };
|
|
124
|
+
export { BetterAuthPlugin, BetterAuthPluginErrorCodePart, HookEndpointContext };
|
|
125
|
+
//# sourceMappingURL=plugin.d.mts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/types/secret.d.ts
|
|
2
|
+
interface SecretConfig {
|
|
3
|
+
/** Map of version number → secret value */
|
|
4
|
+
keys: Map<number, string>;
|
|
5
|
+
/** Version to use for new encryption (first entry in secrets array) */
|
|
6
|
+
currentVersion: number;
|
|
7
|
+
/** Legacy secret for bare-hex fallback (from BETTER_AUTH_SECRET) */
|
|
8
|
+
legacySecret?: string;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { SecretConfig };
|
|
12
|
+
//# sourceMappingURL=secret.d.mts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DBFieldAttribute } from "../db/type.mjs";
|
|
2
|
+
import "../db/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/db.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Filters output data by removing fields with the `returned: false` attribute.
|
|
7
|
+
* This ensures sensitive fields are not exposed in API responses.
|
|
8
|
+
*/
|
|
9
|
+
declare function filterOutputFields<T extends Record<string, unknown> | null>(data: T, additionalFields: Record<string, DBFieldAttribute> | undefined): T;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { filterOutputFields };
|
|
12
|
+
//# sourceMappingURL=db.d.mts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/utils/db.ts
|
|
2
|
+
/**
|
|
3
|
+
* Filters output data by removing fields with the `returned: false` attribute.
|
|
4
|
+
* This ensures sensitive fields are not exposed in API responses.
|
|
5
|
+
*/
|
|
6
|
+
function filterOutputFields(data, additionalFields) {
|
|
7
|
+
if (!data || !additionalFields) return data;
|
|
8
|
+
const returnFiltered = Object.entries(additionalFields).filter(([, { returned }]) => returned === false).map(([key]) => key);
|
|
9
|
+
return Object.entries(structuredClone(data)).filter(([key]) => !returnFiltered.includes(key)).reduce((acc, [key, value]) => ({
|
|
10
|
+
...acc,
|
|
11
|
+
[key]: value
|
|
12
|
+
}), {});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { filterOutputFields };
|
|
17
|
+
//# sourceMappingURL=db.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.mjs","names":[],"sources":["../../src/utils/db.ts"],"sourcesContent":["import type { DBFieldAttribute } from \"../db\";\n\n/**\n * Filters output data by removing fields with the `returned: false` attribute.\n * This ensures sensitive fields are not exposed in API responses.\n */\nexport function filterOutputFields<T extends Record<string, unknown> | null>(\n\tdata: T,\n\tadditionalFields: Record<string, DBFieldAttribute> | undefined,\n): T {\n\tif (!data || !additionalFields) {\n\t\treturn data;\n\t}\n\tconst returnFiltered = Object.entries(additionalFields)\n\t\t.filter(([, { returned }]) => returned === false)\n\t\t.map(([key]) => key);\n\treturn Object.entries(structuredClone(data))\n\t\t.filter(([key]) => !returnFiltered.includes(key))\n\t\t.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {} as T);\n}\n"],"mappings":";;;;;AAMA,SAAgB,mBACf,MACA,kBACI;AACJ,KAAI,CAAC,QAAQ,CAAC,iBACb,QAAO;CAER,MAAM,iBAAiB,OAAO,QAAQ,iBAAiB,CACrD,QAAQ,GAAG,EAAE,gBAAgB,aAAa,MAAM,CAChD,KAAK,CAAC,SAAS,IAAI;AACrB,QAAO,OAAO,QAAQ,gBAAgB,KAAK,CAAC,CAC1C,QAAQ,CAAC,SAAS,CAAC,eAAe,SAAS,IAAI,CAAC,CAChD,QAAQ,KAAK,CAAC,KAAK,YAAY;EAAE,GAAG;GAAM,MAAM;EAAO,GAAG,EAAE,CAAM"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { InternalLogger } from "../env/logger.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/deprecate.d.ts
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Wraps a function to log a deprecation warning at once.
|
|
7
6
|
*/
|
|
8
7
|
declare function deprecate<T extends (...args: any[]) => any>(fn: T, message: string, logger?: InternalLogger): T;
|
|
9
8
|
//#endregion
|
|
10
|
-
export { deprecate };
|
|
9
|
+
export { deprecate };
|
|
10
|
+
//# sourceMappingURL=deprecate.d.mts.map
|