@better-auth/core 1.5.0-beta.8 → 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/index.d.mts +2 -2
- package/dist/context/index.mjs +2 -2
- 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 +12 -3
- package/dist/context/transaction.mjs +55 -11
- 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 +3 -2
- 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 +54 -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 +235 -144
- 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 +55 -0
- package/dist/utils/ip.mjs +119 -0
- 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/context/index.ts +1 -0
- package/src/context/transaction.ts +72 -9
- 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 -29
- package/src/oauth2/validate-token.test.ts +229 -0
- package/src/social-providers/apple.ts +29 -29
- package/src/social-providers/cognito.ts +6 -5
- package/src/social-providers/dropbox.ts +1 -1
- 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 +79 -15
- package/src/types/helper.ts +9 -0
- package/src/types/index.ts +14 -2
- package/src/types/init-options.ts +298 -171
- 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/src/utils/ip.test.ts +255 -0
- package/src/utils/ip.ts +211 -0
- package/.turbo/turbo-build.log +0 -180
- 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
|
*
|
|
@@ -110,6 +157,13 @@ type BetterAuthAdvancedOptions = {
|
|
|
110
157
|
* ⚠︎ This is a security risk and it may expose your application to abuse
|
|
111
158
|
*/
|
|
112
159
|
disableIpTracking?: boolean;
|
|
160
|
+
/**
|
|
161
|
+
* IPv6 subnet prefix length for rate limiting.
|
|
162
|
+
* IPv6 addresses will be normalized to this subnet.
|
|
163
|
+
*
|
|
164
|
+
* @default 64
|
|
165
|
+
*/
|
|
166
|
+
ipv6Subnet?: 128 | 64 | 48 | 32;
|
|
113
167
|
} | undefined;
|
|
114
168
|
/**
|
|
115
169
|
* Use secure cookies
|
|
@@ -194,17 +248,6 @@ type BetterAuthAdvancedOptions = {
|
|
|
194
248
|
* @default 100
|
|
195
249
|
*/
|
|
196
250
|
defaultFindManyLimit?: number;
|
|
197
|
-
/**
|
|
198
|
-
* If your database auto increments number ids, set this to `true`.
|
|
199
|
-
*
|
|
200
|
-
* 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.
|
|
201
|
-
*
|
|
202
|
-
* @default false
|
|
203
|
-
*
|
|
204
|
-
* @deprecated Please use `generateId` instead. This will be removed in future
|
|
205
|
-
* releases.
|
|
206
|
-
*/
|
|
207
|
-
useNumberId?: boolean;
|
|
208
251
|
/**
|
|
209
252
|
* Custom generateId function.
|
|
210
253
|
*
|
|
@@ -258,14 +301,17 @@ type BetterAuthAdvancedOptions = {
|
|
|
258
301
|
* }
|
|
259
302
|
*/
|
|
260
303
|
backgroundTasks?: {
|
|
261
|
-
handler: (promise: Promise<
|
|
304
|
+
handler: (promise: Promise<unknown>) => void;
|
|
262
305
|
};
|
|
263
306
|
/**
|
|
264
|
-
* 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`).
|
|
265
311
|
*
|
|
266
312
|
* @default false
|
|
267
313
|
*/
|
|
268
|
-
skipTrailingSlashes?: boolean
|
|
314
|
+
skipTrailingSlashes?: boolean;
|
|
269
315
|
};
|
|
270
316
|
type BetterAuthOptions = {
|
|
271
317
|
/**
|
|
@@ -279,12 +325,27 @@ type BetterAuthOptions = {
|
|
|
279
325
|
/**
|
|
280
326
|
* Base URL for the Better Auth. This is typically the
|
|
281
327
|
* root URL where your application server is hosted.
|
|
282
|
-
* If not explicitly set,
|
|
283
|
-
* the system will check the following environment variable:
|
|
284
328
|
*
|
|
285
|
-
*
|
|
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
|
+
* ```
|
|
286
347
|
*/
|
|
287
|
-
baseURL?:
|
|
348
|
+
baseURL?: BaseURLConfig | undefined;
|
|
288
349
|
/**
|
|
289
350
|
* Base path for the Better Auth. This is typically
|
|
290
351
|
* the path where the
|
|
@@ -317,10 +378,26 @@ type BetterAuthOptions = {
|
|
|
317
378
|
* ```
|
|
318
379
|
*/
|
|
319
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;
|
|
320
397
|
/**
|
|
321
398
|
* Database configuration
|
|
322
399
|
*/
|
|
323
|
-
database?: (PostgresPool | MysqlPool | SqliteDatabase | Dialect | DBAdapterInstance | Database | DatabaseSync | {
|
|
400
|
+
database?: (PostgresPool | MysqlPool | SqliteDatabase | Dialect | DBAdapterInstance | Database | DatabaseSync | D1Database | {
|
|
324
401
|
dialect: Dialect;
|
|
325
402
|
type: KyselyDatabaseType;
|
|
326
403
|
/**
|
|
@@ -406,10 +483,13 @@ type BetterAuthOptions = {
|
|
|
406
483
|
*/
|
|
407
484
|
request?: Request) => Promise<void>;
|
|
408
485
|
/**
|
|
409
|
-
* Send a verification email automatically
|
|
410
|
-
* after sign up
|
|
486
|
+
* Send a verification email automatically after sign up.
|
|
411
487
|
*
|
|
412
|
-
*
|
|
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
|
|
413
493
|
*/
|
|
414
494
|
sendOnSignUp?: boolean;
|
|
415
495
|
/**
|
|
@@ -429,13 +509,6 @@ type BetterAuthOptions = {
|
|
|
429
509
|
* @default 3600 seconds (1 hour)
|
|
430
510
|
*/
|
|
431
511
|
expiresIn?: number;
|
|
432
|
-
/**
|
|
433
|
-
* A function that is called when a user verifies their email
|
|
434
|
-
* @param user the user that verified their email
|
|
435
|
-
* @param request the request object
|
|
436
|
-
* @deprecated Use `beforeEmailVerification` or `afterEmailVerification` instead. This will be removed in 1.5
|
|
437
|
-
*/
|
|
438
|
-
onEmailVerification?: (user: User, request?: Request) => Promise<void>;
|
|
439
512
|
/**
|
|
440
513
|
* A function that is called before a user verifies their email
|
|
441
514
|
* @param user the user that verified their email
|
|
@@ -544,6 +617,56 @@ type BetterAuthOptions = {
|
|
|
544
617
|
* @default false
|
|
545
618
|
*/
|
|
546
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>;
|
|
547
670
|
} | undefined;
|
|
548
671
|
/**
|
|
549
672
|
* list of social providers
|
|
@@ -556,28 +679,7 @@ type BetterAuthOptions = {
|
|
|
556
679
|
/**
|
|
557
680
|
* User configuration
|
|
558
681
|
*/
|
|
559
|
-
user?: {
|
|
560
|
-
/**
|
|
561
|
-
* The model name for the user. Defaults to "user".
|
|
562
|
-
*/
|
|
563
|
-
modelName?: string;
|
|
564
|
-
/**
|
|
565
|
-
* Map fields
|
|
566
|
-
*
|
|
567
|
-
* @example
|
|
568
|
-
* ```ts
|
|
569
|
-
* {
|
|
570
|
-
* userId: "user_id"
|
|
571
|
-
* }
|
|
572
|
-
* ```
|
|
573
|
-
*/
|
|
574
|
-
fields?: Partial<Record<keyof OmitId<User>, string>>;
|
|
575
|
-
/**
|
|
576
|
-
* Additional fields for the user
|
|
577
|
-
*/
|
|
578
|
-
additionalFields?: {
|
|
579
|
-
[key: string]: DBFieldAttribute;
|
|
580
|
-
};
|
|
682
|
+
user?: (BetterAuthDBOptions<"user", keyof BaseUser> & {
|
|
581
683
|
/**
|
|
582
684
|
* Changing email configuration
|
|
583
685
|
*/
|
|
@@ -587,18 +689,6 @@ type BetterAuthOptions = {
|
|
|
587
689
|
* @default false
|
|
588
690
|
*/
|
|
589
691
|
enabled: boolean;
|
|
590
|
-
/**
|
|
591
|
-
* Send a verification email when the user changes their email.
|
|
592
|
-
* @param data the data object
|
|
593
|
-
* @param request the request object
|
|
594
|
-
* @deprecated Use `sendChangeEmailConfirmation` instead
|
|
595
|
-
*/
|
|
596
|
-
sendChangeEmailVerification?: (data: {
|
|
597
|
-
user: User;
|
|
598
|
-
newEmail: string;
|
|
599
|
-
url: string;
|
|
600
|
-
token: string;
|
|
601
|
-
}, request?: Request) => Promise<void>;
|
|
602
692
|
/**
|
|
603
693
|
* Send a confirmation email to the old email address when the user changes their email.
|
|
604
694
|
* @param data the data object
|
|
@@ -655,24 +745,8 @@ type BetterAuthOptions = {
|
|
|
655
745
|
*/
|
|
656
746
|
deleteTokenExpiresIn?: number;
|
|
657
747
|
};
|
|
658
|
-
} | undefined;
|
|
659
|
-
session?: {
|
|
660
|
-
/**
|
|
661
|
-
* The model name for the session.
|
|
662
|
-
*
|
|
663
|
-
* @default "session"
|
|
664
|
-
*/
|
|
665
|
-
modelName?: string;
|
|
666
|
-
/**
|
|
667
|
-
* Map fields
|
|
668
|
-
*
|
|
669
|
-
* @example
|
|
670
|
-
* ```ts
|
|
671
|
-
* {
|
|
672
|
-
* userId: "user_id"
|
|
673
|
-
* }
|
|
674
|
-
*/
|
|
675
|
-
fields?: Partial<Record<keyof OmitId<Session>, string>>;
|
|
748
|
+
}) | undefined;
|
|
749
|
+
session?: (BetterAuthDBOptions<"session", keyof BaseSession> & {
|
|
676
750
|
/**
|
|
677
751
|
* Expiration time for the session token. The value
|
|
678
752
|
* should be in seconds.
|
|
@@ -694,11 +768,13 @@ type BetterAuthOptions = {
|
|
|
694
768
|
*/
|
|
695
769
|
disableSessionRefresh?: boolean;
|
|
696
770
|
/**
|
|
697
|
-
*
|
|
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
|
|
698
776
|
*/
|
|
699
|
-
|
|
700
|
-
[key: string]: DBFieldAttribute;
|
|
701
|
-
};
|
|
777
|
+
deferSessionRefresh?: boolean;
|
|
702
778
|
/**
|
|
703
779
|
* By default if secondary storage is provided
|
|
704
780
|
* the session is stored in the secondary storage.
|
|
@@ -797,22 +873,8 @@ type BetterAuthOptions = {
|
|
|
797
873
|
* @default 1 day (60 * 60 * 24)
|
|
798
874
|
*/
|
|
799
875
|
freshAge?: number;
|
|
800
|
-
} | undefined;
|
|
801
|
-
account?: {
|
|
802
|
-
/**
|
|
803
|
-
* The model name for the account. Defaults to "account".
|
|
804
|
-
*/
|
|
805
|
-
modelName?: string;
|
|
806
|
-
/**
|
|
807
|
-
* Map fields
|
|
808
|
-
*/
|
|
809
|
-
fields?: Partial<Record<keyof OmitId<Account>, string>>;
|
|
810
|
-
/**
|
|
811
|
-
* Additional fields for the account
|
|
812
|
-
*/
|
|
813
|
-
additionalFields?: {
|
|
814
|
-
[key: string]: DBFieldAttribute;
|
|
815
|
-
};
|
|
876
|
+
}) | undefined;
|
|
877
|
+
account?: (BetterAuthDBOptions<"account", keyof BaseAccount> & {
|
|
816
878
|
/**
|
|
817
879
|
* When enabled (true), the user account data (accessToken, idToken, refreshToken, etc.)
|
|
818
880
|
* will be updated on sign in with the latest data from the provider.
|
|
@@ -831,9 +893,38 @@ type BetterAuthOptions = {
|
|
|
831
893
|
*/
|
|
832
894
|
enabled?: boolean;
|
|
833
895
|
/**
|
|
834
|
-
*
|
|
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
|
+
* ```
|
|
835
926
|
*/
|
|
836
|
-
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>>>);
|
|
837
928
|
/**
|
|
838
929
|
* If enabled (true), this will allow users to manually linking accounts with different email addresses than the main user.
|
|
839
930
|
*
|
|
@@ -895,31 +986,30 @@ type BetterAuthOptions = {
|
|
|
895
986
|
* @note This is automatically set to true if you haven't passed a database
|
|
896
987
|
*/
|
|
897
988
|
storeAccountCookie?: boolean;
|
|
898
|
-
} | undefined;
|
|
899
|
-
|
|
900
|
-
* Verification configuration
|
|
901
|
-
*/
|
|
902
|
-
verification?: {
|
|
903
|
-
/**
|
|
904
|
-
* Change the modelName of the verification table
|
|
905
|
-
*/
|
|
906
|
-
modelName?: string;
|
|
989
|
+
}) | undefined;
|
|
990
|
+
verification?: (BetterAuthDBOptions<"verification", keyof BaseVerification> & {
|
|
907
991
|
/**
|
|
908
|
-
*
|
|
992
|
+
* disable cleaning up expired values when a verification value is
|
|
993
|
+
* fetched
|
|
909
994
|
*/
|
|
910
|
-
|
|
995
|
+
disableCleanup?: boolean;
|
|
911
996
|
/**
|
|
912
|
-
*
|
|
997
|
+
* How to store verification identifiers (tokens, OTPs, etc.)
|
|
998
|
+
*
|
|
999
|
+
* @example "hashed"
|
|
1000
|
+
*
|
|
1001
|
+
* @default "plain"
|
|
913
1002
|
*/
|
|
914
|
-
|
|
915
|
-
|
|
1003
|
+
storeIdentifier?: StoreIdentifierOption | {
|
|
1004
|
+
default: StoreIdentifierOption;
|
|
1005
|
+
overrides?: Record<string, StoreIdentifierOption>;
|
|
916
1006
|
};
|
|
917
1007
|
/**
|
|
918
|
-
*
|
|
919
|
-
*
|
|
1008
|
+
* Store verification data in database even when secondary storage is configured.
|
|
1009
|
+
* @default false
|
|
920
1010
|
*/
|
|
921
|
-
|
|
922
|
-
} | undefined;
|
|
1011
|
+
storeInDatabase?: boolean;
|
|
1012
|
+
}) | undefined;
|
|
923
1013
|
/**
|
|
924
1014
|
* List of trusted origins.
|
|
925
1015
|
*
|
|
@@ -1257,4 +1347,5 @@ type BetterAuthOptions = {
|
|
|
1257
1347
|
};
|
|
1258
1348
|
};
|
|
1259
1349
|
//#endregion
|
|
1260
|
-
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
|
package/dist/utils/deprecate.mjs
CHANGED