@hammadj/better-auth-core 1.5.0-beta.9
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/.turbo/turbo-build.log +266 -0
- package/.turbo/turbo-test.log +2 -0
- package/LICENSE.md +20 -0
- package/dist/api/index.d.mts +181 -0
- package/dist/api/index.mjs +34 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/async_hooks/index.d.mts +7 -0
- package/dist/async_hooks/index.mjs +22 -0
- package/dist/async_hooks/index.mjs.map +1 -0
- package/dist/async_hooks/pure.index.d.mts +7 -0
- package/dist/async_hooks/pure.index.mjs +35 -0
- package/dist/async_hooks/pure.index.mjs.map +1 -0
- package/dist/context/endpoint-context.d.mts +19 -0
- package/dist/context/endpoint-context.mjs +32 -0
- package/dist/context/endpoint-context.mjs.map +1 -0
- package/dist/context/global.d.mts +7 -0
- package/dist/context/global.mjs +38 -0
- package/dist/context/global.mjs.map +1 -0
- package/dist/context/index.d.mts +5 -0
- package/dist/context/index.mjs +6 -0
- package/dist/context/request-state.d.mts +26 -0
- package/dist/context/request-state.mjs +50 -0
- package/dist/context/request-state.mjs.map +1 -0
- package/dist/context/transaction.d.mts +25 -0
- package/dist/context/transaction.mjs +96 -0
- package/dist/context/transaction.mjs.map +1 -0
- package/dist/db/adapter/factory.d.mts +28 -0
- package/dist/db/adapter/factory.mjs +716 -0
- package/dist/db/adapter/factory.mjs.map +1 -0
- package/dist/db/adapter/get-default-field-name.d.mts +19 -0
- package/dist/db/adapter/get-default-field-name.mjs +39 -0
- package/dist/db/adapter/get-default-field-name.mjs.map +1 -0
- package/dist/db/adapter/get-default-model-name.d.mts +13 -0
- package/dist/db/adapter/get-default-model-name.mjs +33 -0
- package/dist/db/adapter/get-default-model-name.mjs.map +1 -0
- package/dist/db/adapter/get-field-attributes.d.mts +30 -0
- package/dist/db/adapter/get-field-attributes.mjs +40 -0
- package/dist/db/adapter/get-field-attributes.mjs.map +1 -0
- package/dist/db/adapter/get-field-name.d.mts +19 -0
- package/dist/db/adapter/get-field-name.mjs +34 -0
- package/dist/db/adapter/get-field-name.mjs.map +1 -0
- package/dist/db/adapter/get-id-field.d.mts +40 -0
- package/dist/db/adapter/get-id-field.mjs +68 -0
- package/dist/db/adapter/get-id-field.mjs.map +1 -0
- package/dist/db/adapter/get-model-name.d.mts +13 -0
- package/dist/db/adapter/get-model-name.mjs +24 -0
- package/dist/db/adapter/get-model-name.mjs.map +1 -0
- package/dist/db/adapter/index.d.mts +515 -0
- package/dist/db/adapter/index.mjs +10 -0
- package/dist/db/adapter/types.d.mts +140 -0
- package/dist/db/adapter/utils.d.mts +8 -0
- package/dist/db/adapter/utils.mjs +39 -0
- package/dist/db/adapter/utils.mjs.map +1 -0
- package/dist/db/get-tables.d.mts +9 -0
- package/dist/db/get-tables.mjs +267 -0
- package/dist/db/get-tables.mjs.map +1 -0
- package/dist/db/index.d.mts +10 -0
- package/dist/db/index.mjs +9 -0
- package/dist/db/plugin.d.mts +13 -0
- package/dist/db/schema/account.d.mts +27 -0
- package/dist/db/schema/account.mjs +20 -0
- package/dist/db/schema/account.mjs.map +1 -0
- package/dist/db/schema/rate-limit.d.mts +15 -0
- package/dist/db/schema/rate-limit.mjs +12 -0
- package/dist/db/schema/rate-limit.mjs.map +1 -0
- package/dist/db/schema/session.d.mts +22 -0
- package/dist/db/schema/session.mjs +15 -0
- package/dist/db/schema/session.mjs.map +1 -0
- package/dist/db/schema/shared.d.mts +11 -0
- package/dist/db/schema/shared.mjs +12 -0
- package/dist/db/schema/shared.mjs.map +1 -0
- package/dist/db/schema/user.d.mts +21 -0
- package/dist/db/schema/user.mjs +14 -0
- package/dist/db/schema/user.mjs.map +1 -0
- package/dist/db/schema/verification.d.mts +20 -0
- package/dist/db/schema/verification.mjs +13 -0
- package/dist/db/schema/verification.mjs.map +1 -0
- package/dist/db/type.d.mts +147 -0
- package/dist/env/color-depth.d.mts +5 -0
- package/dist/env/color-depth.mjs +89 -0
- package/dist/env/color-depth.mjs.map +1 -0
- package/dist/env/env-impl.d.mts +33 -0
- package/dist/env/env-impl.mjs +83 -0
- package/dist/env/env-impl.mjs.map +1 -0
- package/dist/env/index.d.mts +4 -0
- package/dist/env/index.mjs +5 -0
- package/dist/env/logger.d.mts +49 -0
- package/dist/env/logger.mjs +82 -0
- package/dist/env/logger.mjs.map +1 -0
- package/dist/error/codes.d.mts +199 -0
- package/dist/error/codes.mjs +57 -0
- package/dist/error/codes.mjs.map +1 -0
- package/dist/error/index.d.mts +20 -0
- package/dist/error/index.mjs +30 -0
- package/dist/error/index.mjs.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +1 -0
- package/dist/oauth2/client-credentials-token.d.mts +37 -0
- package/dist/oauth2/client-credentials-token.mjs +55 -0
- package/dist/oauth2/client-credentials-token.mjs.map +1 -0
- package/dist/oauth2/create-authorization-url.d.mts +46 -0
- package/dist/oauth2/create-authorization-url.mjs +43 -0
- package/dist/oauth2/create-authorization-url.mjs.map +1 -0
- package/dist/oauth2/index.d.mts +8 -0
- package/dist/oauth2/index.mjs +8 -0
- package/dist/oauth2/oauth-provider.d.mts +195 -0
- package/dist/oauth2/refresh-access-token.d.mts +36 -0
- package/dist/oauth2/refresh-access-token.mjs +59 -0
- package/dist/oauth2/refresh-access-token.mjs.map +1 -0
- package/dist/oauth2/utils.d.mts +8 -0
- package/dist/oauth2/utils.mjs +28 -0
- package/dist/oauth2/utils.mjs.map +1 -0
- package/dist/oauth2/validate-authorization-code.d.mts +56 -0
- package/dist/oauth2/validate-authorization-code.mjs +72 -0
- package/dist/oauth2/validate-authorization-code.mjs.map +1 -0
- package/dist/oauth2/verify.d.mts +43 -0
- package/dist/oauth2/verify.mjs +96 -0
- package/dist/oauth2/verify.mjs.map +1 -0
- package/dist/social-providers/apple.d.mts +120 -0
- package/dist/social-providers/apple.mjs +105 -0
- package/dist/social-providers/apple.mjs.map +1 -0
- package/dist/social-providers/atlassian.d.mts +73 -0
- package/dist/social-providers/atlassian.mjs +84 -0
- package/dist/social-providers/atlassian.mjs.map +1 -0
- package/dist/social-providers/cognito.d.mts +88 -0
- package/dist/social-providers/cognito.mjs +166 -0
- package/dist/social-providers/cognito.mjs.map +1 -0
- package/dist/social-providers/discord.d.mts +127 -0
- package/dist/social-providers/discord.mjs +65 -0
- package/dist/social-providers/discord.mjs.map +1 -0
- package/dist/social-providers/dropbox.d.mts +72 -0
- package/dist/social-providers/dropbox.mjs +76 -0
- package/dist/social-providers/dropbox.mjs.map +1 -0
- package/dist/social-providers/facebook.d.mts +82 -0
- package/dist/social-providers/facebook.mjs +121 -0
- package/dist/social-providers/facebook.mjs.map +1 -0
- package/dist/social-providers/figma.d.mts +64 -0
- package/dist/social-providers/figma.mjs +87 -0
- package/dist/social-providers/figma.mjs.map +1 -0
- package/dist/social-providers/github.d.mts +105 -0
- package/dist/social-providers/github.mjs +97 -0
- package/dist/social-providers/github.mjs.map +1 -0
- package/dist/social-providers/gitlab.d.mts +126 -0
- package/dist/social-providers/gitlab.mjs +83 -0
- package/dist/social-providers/gitlab.mjs.map +1 -0
- package/dist/social-providers/google.d.mts +100 -0
- package/dist/social-providers/google.mjs +109 -0
- package/dist/social-providers/google.mjs.map +1 -0
- package/dist/social-providers/huggingface.d.mts +86 -0
- package/dist/social-providers/huggingface.mjs +76 -0
- package/dist/social-providers/huggingface.mjs.map +1 -0
- package/dist/social-providers/index.d.mts +1725 -0
- package/dist/social-providers/index.mjs +77 -0
- package/dist/social-providers/index.mjs.map +1 -0
- package/dist/social-providers/kakao.d.mts +164 -0
- package/dist/social-providers/kakao.mjs +73 -0
- package/dist/social-providers/kakao.mjs.map +1 -0
- package/dist/social-providers/kick.d.mts +76 -0
- package/dist/social-providers/kick.mjs +72 -0
- package/dist/social-providers/kick.mjs.map +1 -0
- package/dist/social-providers/line.d.mts +108 -0
- package/dist/social-providers/line.mjs +114 -0
- package/dist/social-providers/line.mjs.map +1 -0
- package/dist/social-providers/linear.d.mts +71 -0
- package/dist/social-providers/linear.mjs +89 -0
- package/dist/social-providers/linear.mjs.map +1 -0
- package/dist/social-providers/linkedin.d.mts +70 -0
- package/dist/social-providers/linkedin.mjs +77 -0
- package/dist/social-providers/linkedin.mjs.map +1 -0
- package/dist/social-providers/microsoft-entra-id.d.mts +175 -0
- package/dist/social-providers/microsoft-entra-id.mjs +107 -0
- package/dist/social-providers/microsoft-entra-id.mjs.map +1 -0
- package/dist/social-providers/naver.d.mts +95 -0
- package/dist/social-providers/naver.mjs +68 -0
- package/dist/social-providers/naver.mjs.map +1 -0
- package/dist/social-providers/notion.d.mts +67 -0
- package/dist/social-providers/notion.mjs +76 -0
- package/dist/social-providers/notion.mjs.map +1 -0
- package/dist/social-providers/paybin.d.mts +74 -0
- package/dist/social-providers/paybin.mjs +86 -0
- package/dist/social-providers/paybin.mjs.map +1 -0
- package/dist/social-providers/paypal.d.mts +132 -0
- package/dist/social-providers/paypal.mjs +145 -0
- package/dist/social-providers/paypal.mjs.map +1 -0
- package/dist/social-providers/polar.d.mts +77 -0
- package/dist/social-providers/polar.mjs +74 -0
- package/dist/social-providers/polar.mjs.map +1 -0
- package/dist/social-providers/reddit.d.mts +65 -0
- package/dist/social-providers/reddit.mjs +84 -0
- package/dist/social-providers/reddit.mjs.map +1 -0
- package/dist/social-providers/roblox.d.mts +73 -0
- package/dist/social-providers/roblox.mjs +60 -0
- package/dist/social-providers/roblox.mjs.map +1 -0
- package/dist/social-providers/salesforce.d.mts +82 -0
- package/dist/social-providers/salesforce.mjs +92 -0
- package/dist/social-providers/salesforce.mjs.map +1 -0
- package/dist/social-providers/slack.d.mts +86 -0
- package/dist/social-providers/slack.mjs +69 -0
- package/dist/social-providers/slack.mjs.map +1 -0
- package/dist/social-providers/spotify.d.mts +66 -0
- package/dist/social-providers/spotify.mjs +72 -0
- package/dist/social-providers/spotify.mjs.map +1 -0
- package/dist/social-providers/tiktok.d.mts +171 -0
- package/dist/social-providers/tiktok.mjs +63 -0
- package/dist/social-providers/tiktok.mjs.map +1 -0
- package/dist/social-providers/twitch.d.mts +82 -0
- package/dist/social-providers/twitch.mjs +79 -0
- package/dist/social-providers/twitch.mjs.map +1 -0
- package/dist/social-providers/twitter.d.mts +129 -0
- package/dist/social-providers/twitter.mjs +88 -0
- package/dist/social-providers/twitter.mjs.map +1 -0
- package/dist/social-providers/vercel.d.mts +65 -0
- package/dist/social-providers/vercel.mjs +62 -0
- package/dist/social-providers/vercel.mjs.map +1 -0
- package/dist/social-providers/vk.d.mts +73 -0
- package/dist/social-providers/vk.mjs +84 -0
- package/dist/social-providers/vk.mjs.map +1 -0
- package/dist/social-providers/zoom.d.mts +173 -0
- package/dist/social-providers/zoom.mjs +73 -0
- package/dist/social-providers/zoom.mjs.map +1 -0
- package/dist/types/context.d.mts +267 -0
- package/dist/types/cookie.d.mts +16 -0
- package/dist/types/helper.d.mts +10 -0
- package/dist/types/index.d.mts +8 -0
- package/dist/types/init-options.d.mts +1314 -0
- package/dist/types/plugin-client.d.mts +112 -0
- package/dist/types/plugin.d.mts +125 -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 +10 -0
- package/dist/utils/deprecate.mjs +18 -0
- package/dist/utils/deprecate.mjs.map +1 -0
- package/dist/utils/error-codes.d.mts +13 -0
- package/dist/utils/error-codes.mjs +12 -0
- package/dist/utils/error-codes.mjs.map +1 -0
- package/dist/utils/id.d.mts +5 -0
- package/dist/utils/id.mjs +10 -0
- 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 +5 -0
- package/dist/utils/json.mjs +26 -0
- package/dist/utils/json.mjs.map +1 -0
- package/dist/utils/string.d.mts +5 -0
- package/dist/utils/string.mjs +8 -0
- package/dist/utils/string.mjs.map +1 -0
- package/dist/utils/url.d.mts +21 -0
- package/dist/utils/url.mjs +33 -0
- package/dist/utils/url.mjs.map +1 -0
- package/package.json +147 -0
- package/src/api/index.ts +106 -0
- package/src/async_hooks/index.ts +40 -0
- package/src/async_hooks/pure.index.ts +46 -0
- package/src/context/endpoint-context.ts +50 -0
- package/src/context/global.ts +57 -0
- package/src/context/index.ts +23 -0
- package/src/context/request-state.test.ts +94 -0
- package/src/context/request-state.ts +91 -0
- package/src/context/transaction.ts +136 -0
- package/src/db/adapter/factory.ts +1362 -0
- package/src/db/adapter/get-default-field-name.ts +59 -0
- package/src/db/adapter/get-default-model-name.ts +51 -0
- package/src/db/adapter/get-field-attributes.ts +62 -0
- package/src/db/adapter/get-field-name.ts +43 -0
- package/src/db/adapter/get-id-field.ts +141 -0
- package/src/db/adapter/get-model-name.ts +36 -0
- package/src/db/adapter/index.ts +554 -0
- package/src/db/adapter/types.ts +171 -0
- package/src/db/adapter/utils.ts +61 -0
- package/src/db/get-tables.ts +296 -0
- package/src/db/index.ts +18 -0
- package/src/db/plugin.ts +11 -0
- package/src/db/schema/account.ts +34 -0
- package/src/db/schema/rate-limit.ts +21 -0
- package/src/db/schema/session.ts +17 -0
- package/src/db/schema/shared.ts +7 -0
- package/src/db/schema/user.ts +16 -0
- package/src/db/schema/verification.ts +15 -0
- package/src/db/test/get-tables.test.ts +116 -0
- package/src/db/type.ts +180 -0
- package/src/env/color-depth.ts +172 -0
- package/src/env/env-impl.ts +124 -0
- package/src/env/index.ts +23 -0
- package/src/env/logger.test.ts +34 -0
- package/src/env/logger.ts +145 -0
- package/src/error/codes.ts +58 -0
- package/src/error/index.ts +35 -0
- package/src/index.ts +1 -0
- package/src/oauth2/client-credentials-token.ts +102 -0
- package/src/oauth2/create-authorization-url.ts +87 -0
- package/src/oauth2/index.ts +26 -0
- package/src/oauth2/oauth-provider.ts +222 -0
- package/src/oauth2/refresh-access-token.ts +124 -0
- package/src/oauth2/utils.ts +38 -0
- package/src/oauth2/validate-authorization-code.ts +149 -0
- package/src/oauth2/validate-token.test.ts +174 -0
- package/src/oauth2/verify.ts +221 -0
- package/src/social-providers/apple.ts +223 -0
- package/src/social-providers/atlassian.ts +132 -0
- package/src/social-providers/cognito.ts +279 -0
- package/src/social-providers/discord.ts +169 -0
- package/src/social-providers/dropbox.ts +112 -0
- package/src/social-providers/facebook.ts +206 -0
- package/src/social-providers/figma.ts +117 -0
- package/src/social-providers/github.ts +184 -0
- package/src/social-providers/gitlab.ts +155 -0
- package/src/social-providers/google.ts +199 -0
- package/src/social-providers/huggingface.ts +118 -0
- package/src/social-providers/index.ts +127 -0
- package/src/social-providers/kakao.ts +178 -0
- package/src/social-providers/kick.ts +109 -0
- package/src/social-providers/line.ts +169 -0
- package/src/social-providers/linear.ts +121 -0
- package/src/social-providers/linkedin.ts +110 -0
- package/src/social-providers/microsoft-entra-id.ts +259 -0
- package/src/social-providers/naver.ts +112 -0
- package/src/social-providers/notion.ts +108 -0
- package/src/social-providers/paybin.ts +122 -0
- package/src/social-providers/paypal.ts +263 -0
- package/src/social-providers/polar.ts +110 -0
- package/src/social-providers/reddit.ts +122 -0
- package/src/social-providers/roblox.ts +111 -0
- package/src/social-providers/salesforce.ts +159 -0
- package/src/social-providers/slack.ts +111 -0
- package/src/social-providers/spotify.ts +93 -0
- package/src/social-providers/tiktok.ts +209 -0
- package/src/social-providers/twitch.ts +111 -0
- package/src/social-providers/twitter.ts +198 -0
- package/src/social-providers/vercel.ts +87 -0
- package/src/social-providers/vk.ts +124 -0
- package/src/social-providers/zoom.ts +238 -0
- package/src/types/context.ts +396 -0
- package/src/types/cookie.ts +10 -0
- package/src/types/helper.ts +26 -0
- package/src/types/index.ts +32 -0
- package/src/types/init-options.ts +1529 -0
- package/src/types/plugin-client.ts +127 -0
- package/src/types/plugin.ts +157 -0
- package/src/utils/db.ts +20 -0
- package/src/utils/deprecate.test.ts +72 -0
- package/src/utils/deprecate.ts +21 -0
- package/src/utils/error-codes.ts +65 -0
- package/src/utils/id.ts +5 -0
- package/src/utils/ip.test.ts +255 -0
- package/src/utils/ip.ts +211 -0
- package/src/utils/json.ts +25 -0
- package/src/utils/string.ts +3 -0
- package/src/utils/url.ts +43 -0
- package/tsconfig.json +7 -0
- package/tsdown.config.ts +35 -0
- package/vitest.config.ts +3 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import type { CookieOptions, EndpointContext } from "better-call";
|
|
2
|
+
import type {
|
|
3
|
+
Account,
|
|
4
|
+
BetterAuthDBSchema,
|
|
5
|
+
ModelNames,
|
|
6
|
+
SecondaryStorage,
|
|
7
|
+
Session,
|
|
8
|
+
User,
|
|
9
|
+
Verification,
|
|
10
|
+
} from "../db";
|
|
11
|
+
import type { DBAdapter, Where } from "../db/adapter";
|
|
12
|
+
import type { createLogger } from "../env";
|
|
13
|
+
import type { OAuthProvider } from "../oauth2";
|
|
14
|
+
import type { BetterAuthCookie, BetterAuthCookies } from "./cookie";
|
|
15
|
+
import type { Awaitable, LiteralString } from "./helper";
|
|
16
|
+
import type {
|
|
17
|
+
BetterAuthOptions,
|
|
18
|
+
BetterAuthRateLimitOptions,
|
|
19
|
+
} from "./init-options";
|
|
20
|
+
import type { BetterAuthPlugin } from "./plugin";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
type InferPluginID<O extends BetterAuthOptions> =
|
|
26
|
+
O["plugins"] extends Array<infer P>
|
|
27
|
+
? P extends BetterAuthPlugin
|
|
28
|
+
? P["id"]
|
|
29
|
+
: never
|
|
30
|
+
: never;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
type InferPluginOptions<
|
|
36
|
+
O extends BetterAuthOptions,
|
|
37
|
+
ID extends BetterAuthPluginRegistryIdentifier | LiteralString,
|
|
38
|
+
> = O["plugins"] extends Array<infer P>
|
|
39
|
+
? P extends BetterAuthPlugin
|
|
40
|
+
? P["id"] extends ID
|
|
41
|
+
? P extends { options: infer O }
|
|
42
|
+
? O
|
|
43
|
+
: never
|
|
44
|
+
: never
|
|
45
|
+
: never
|
|
46
|
+
: never;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Mutators are defined in each plugin
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* interface MyPluginOptions {
|
|
54
|
+
* useFeature: boolean
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* const createMyPlugin = <Options extends MyPluginOptions>(options?: Options) => ({
|
|
58
|
+
* id: 'my-plugin',
|
|
59
|
+
* options,
|
|
60
|
+
* } satisfies BetterAuthPlugin);
|
|
61
|
+
*
|
|
62
|
+
* declare module "@better-auth/core" {
|
|
63
|
+
* interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
64
|
+
* 'my-plugin': {
|
|
65
|
+
* creator: Options extends MyPluginOptions ? typeof createMyPlugin<Options>: typeof createMyPlugin
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
// biome-ignore lint/correctness/noUnusedVariables: Auth and Context is used in the declaration merging
|
|
72
|
+
export interface BetterAuthPluginRegistry<AuthOptions, Options> {}
|
|
73
|
+
export type BetterAuthPluginRegistryIdentifier = keyof BetterAuthPluginRegistry<
|
|
74
|
+
unknown,
|
|
75
|
+
unknown
|
|
76
|
+
>;
|
|
77
|
+
|
|
78
|
+
export type GenericEndpointContext<
|
|
79
|
+
Options extends BetterAuthOptions = BetterAuthOptions,
|
|
80
|
+
> = EndpointContext<string, any> & {
|
|
81
|
+
context: AuthContext<Options>;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export interface InternalAdapter<
|
|
85
|
+
_Options extends BetterAuthOptions = BetterAuthOptions,
|
|
86
|
+
> {
|
|
87
|
+
createOAuthUser(
|
|
88
|
+
user: Omit<User, "id" | "createdAt" | "updatedAt">,
|
|
89
|
+
account: Omit<Account, "userId" | "id" | "createdAt" | "updatedAt"> &
|
|
90
|
+
Partial<Account>,
|
|
91
|
+
): Promise<{ user: User; account: Account }>;
|
|
92
|
+
|
|
93
|
+
createUser<T extends Record<string, any>>(
|
|
94
|
+
user: Omit<User, "id" | "createdAt" | "updatedAt" | "emailVerified"> &
|
|
95
|
+
Partial<User> &
|
|
96
|
+
Record<string, any>,
|
|
97
|
+
): Promise<T & User>;
|
|
98
|
+
|
|
99
|
+
createAccount<T extends Record<string, any>>(
|
|
100
|
+
account: Omit<Account, "id" | "createdAt" | "updatedAt"> &
|
|
101
|
+
Partial<Account> &
|
|
102
|
+
T,
|
|
103
|
+
): Promise<T & Account>;
|
|
104
|
+
|
|
105
|
+
listSessions(userId: string): Promise<Session[]>;
|
|
106
|
+
|
|
107
|
+
listUsers(
|
|
108
|
+
limit?: number | undefined,
|
|
109
|
+
offset?: number | undefined,
|
|
110
|
+
sortBy?: { field: string; direction: "asc" | "desc" } | undefined,
|
|
111
|
+
where?: Where[] | undefined,
|
|
112
|
+
): Promise<User[]>;
|
|
113
|
+
|
|
114
|
+
countTotalUsers(where?: Where[] | undefined): Promise<number>;
|
|
115
|
+
|
|
116
|
+
deleteUser(userId: string): Promise<void>;
|
|
117
|
+
|
|
118
|
+
createSession(
|
|
119
|
+
userId: string,
|
|
120
|
+
dontRememberMe?: boolean | undefined,
|
|
121
|
+
override?: (Partial<Session> & Record<string, any>) | undefined,
|
|
122
|
+
overrideAll?: boolean | undefined,
|
|
123
|
+
): Promise<Session>;
|
|
124
|
+
|
|
125
|
+
findSession(token: string): Promise<{
|
|
126
|
+
session: Session & Record<string, any>;
|
|
127
|
+
user: User & Record<string, any>;
|
|
128
|
+
} | null>;
|
|
129
|
+
|
|
130
|
+
findSessions(
|
|
131
|
+
sessionTokens: string[],
|
|
132
|
+
): Promise<{ session: Session; user: User }[]>;
|
|
133
|
+
|
|
134
|
+
updateSession(
|
|
135
|
+
sessionToken: string,
|
|
136
|
+
session: Partial<Session> & Record<string, any>,
|
|
137
|
+
): Promise<Session | null>;
|
|
138
|
+
|
|
139
|
+
deleteSession(token: string): Promise<void>;
|
|
140
|
+
|
|
141
|
+
deleteAccounts(userId: string): Promise<void>;
|
|
142
|
+
|
|
143
|
+
deleteAccount(accountId: string): Promise<void>;
|
|
144
|
+
|
|
145
|
+
deleteSessions(userIdOrSessionTokens: string | string[]): Promise<void>;
|
|
146
|
+
|
|
147
|
+
findOAuthUser(
|
|
148
|
+
email: string,
|
|
149
|
+
accountId: string,
|
|
150
|
+
providerId: string,
|
|
151
|
+
): Promise<{
|
|
152
|
+
user: User;
|
|
153
|
+
linkedAccount: Account | null;
|
|
154
|
+
accounts: Account[];
|
|
155
|
+
} | null>;
|
|
156
|
+
|
|
157
|
+
findUserByEmail(
|
|
158
|
+
email: string,
|
|
159
|
+
options?: { includeAccounts: boolean } | undefined,
|
|
160
|
+
): Promise<{ user: User; accounts: Account[] } | null>;
|
|
161
|
+
|
|
162
|
+
findUserById(userId: string): Promise<User | null>;
|
|
163
|
+
|
|
164
|
+
linkAccount(
|
|
165
|
+
account: Omit<Account, "id" | "createdAt" | "updatedAt"> & Partial<Account>,
|
|
166
|
+
): Promise<Account>;
|
|
167
|
+
|
|
168
|
+
// Record<string, any> is to take into account additional fields or plugin-added fields
|
|
169
|
+
updateUser<T extends Record<string, any>>(
|
|
170
|
+
userId: string,
|
|
171
|
+
data: Partial<User> & Record<string, any>,
|
|
172
|
+
): Promise<User & T>;
|
|
173
|
+
|
|
174
|
+
updateUserByEmail<T extends Record<string, any>>(
|
|
175
|
+
email: string,
|
|
176
|
+
data: Partial<User & Record<string, any>>,
|
|
177
|
+
): Promise<User & T>;
|
|
178
|
+
|
|
179
|
+
updatePassword(userId: string, password: string): Promise<void>;
|
|
180
|
+
|
|
181
|
+
findAccounts(userId: string): Promise<Account[]>;
|
|
182
|
+
|
|
183
|
+
findAccount(accountId: string): Promise<Account | null>;
|
|
184
|
+
|
|
185
|
+
findAccountByProviderId(
|
|
186
|
+
accountId: string,
|
|
187
|
+
providerId: string,
|
|
188
|
+
): Promise<Account | null>;
|
|
189
|
+
|
|
190
|
+
findAccountByUserId(userId: string): Promise<Account[]>;
|
|
191
|
+
|
|
192
|
+
updateAccount(id: string, data: Partial<Account>): Promise<Account>;
|
|
193
|
+
|
|
194
|
+
createVerificationValue(
|
|
195
|
+
data: Omit<Verification, "createdAt" | "id" | "updatedAt"> &
|
|
196
|
+
Partial<Verification>,
|
|
197
|
+
): Promise<Verification>;
|
|
198
|
+
|
|
199
|
+
findVerificationValue(identifier: string): Promise<Verification | null>;
|
|
200
|
+
|
|
201
|
+
deleteVerificationValue(id: string): Promise<void>;
|
|
202
|
+
|
|
203
|
+
deleteVerificationByIdentifier(identifier: string): Promise<void>;
|
|
204
|
+
|
|
205
|
+
updateVerificationValue(
|
|
206
|
+
id: string,
|
|
207
|
+
data: Partial<Verification>,
|
|
208
|
+
): Promise<Verification>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
type CreateCookieGetterFn = (
|
|
212
|
+
cookieName: string,
|
|
213
|
+
overrideAttributes?: Partial<CookieOptions> | undefined,
|
|
214
|
+
) => BetterAuthCookie;
|
|
215
|
+
|
|
216
|
+
type CheckPasswordFn<Options extends BetterAuthOptions = BetterAuthOptions> = (
|
|
217
|
+
userId: string,
|
|
218
|
+
ctx: GenericEndpointContext<Options>,
|
|
219
|
+
) => Promise<boolean>;
|
|
220
|
+
|
|
221
|
+
export type PluginContext<Options extends BetterAuthOptions> = {
|
|
222
|
+
getPlugin: <
|
|
223
|
+
ID extends BetterAuthPluginRegistryIdentifier | LiteralString,
|
|
224
|
+
PluginOptions extends InferPluginOptions<Options, ID>,
|
|
225
|
+
>(
|
|
226
|
+
pluginId: ID,
|
|
227
|
+
) =>
|
|
228
|
+
| (ID extends BetterAuthPluginRegistryIdentifier
|
|
229
|
+
? ReturnType<
|
|
230
|
+
BetterAuthPluginRegistry<Options, PluginOptions>[ID]["creator"]
|
|
231
|
+
>
|
|
232
|
+
: BetterAuthPlugin)
|
|
233
|
+
| null;
|
|
234
|
+
/**
|
|
235
|
+
* Checks if a plugin is enabled by its ID.
|
|
236
|
+
*
|
|
237
|
+
* @param pluginId - The ID of the plugin to check
|
|
238
|
+
* @returns `true` if the plugin is enabled, `false` otherwise
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* if (ctx.context.hasPlugin("organization")) {
|
|
243
|
+
* // organization plugin is enabled
|
|
244
|
+
* }
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
hasPlugin: <ID extends BetterAuthPluginRegistryIdentifier | LiteralString>(
|
|
248
|
+
pluginId: ID,
|
|
249
|
+
) => ID extends InferPluginID<Options> ? true : boolean;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export type InfoContext = {
|
|
253
|
+
appName: string;
|
|
254
|
+
baseURL: string;
|
|
255
|
+
version: string;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
export type AuthContext<Options extends BetterAuthOptions = BetterAuthOptions> =
|
|
259
|
+
PluginContext<Options> &
|
|
260
|
+
InfoContext & {
|
|
261
|
+
options: Options;
|
|
262
|
+
trustedOrigins: string[];
|
|
263
|
+
/**
|
|
264
|
+
* Verifies whether url is a trusted origin according to the "trustedOrigins" configuration
|
|
265
|
+
* @param url The url to verify against the "trustedOrigins" configuration
|
|
266
|
+
* @param settings Specify supported pattern matching settings
|
|
267
|
+
* @returns {boolean} true if the URL matches the origin pattern, false otherwise.
|
|
268
|
+
*/
|
|
269
|
+
isTrustedOrigin: (
|
|
270
|
+
url: string,
|
|
271
|
+
settings?: { allowRelativePaths: boolean },
|
|
272
|
+
) => boolean;
|
|
273
|
+
oauthConfig: {
|
|
274
|
+
/**
|
|
275
|
+
* This is dangerous and should only be used in dev or staging environments.
|
|
276
|
+
*/
|
|
277
|
+
skipStateCookieCheck?: boolean | undefined;
|
|
278
|
+
/**
|
|
279
|
+
* Strategy for storing OAuth state
|
|
280
|
+
*
|
|
281
|
+
* - "cookie": Store state in an encrypted cookie (stateless)
|
|
282
|
+
* - "database": Store state in the database
|
|
283
|
+
*
|
|
284
|
+
* @default "cookie"
|
|
285
|
+
*/
|
|
286
|
+
storeStateStrategy: "database" | "cookie";
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* New session that will be set after the request
|
|
290
|
+
* meaning: there is a `set-cookie` header that will set
|
|
291
|
+
* the session cookie. This is the fetched session. And it's set
|
|
292
|
+
* by `setNewSession` method.
|
|
293
|
+
*/
|
|
294
|
+
newSession: {
|
|
295
|
+
session: Session & Record<string, any>;
|
|
296
|
+
user: User & Record<string, any>;
|
|
297
|
+
} | null;
|
|
298
|
+
session: {
|
|
299
|
+
session: Session & Record<string, any>;
|
|
300
|
+
user: User & Record<string, any>;
|
|
301
|
+
} | null;
|
|
302
|
+
setNewSession: (
|
|
303
|
+
session: {
|
|
304
|
+
session: Session & Record<string, any>;
|
|
305
|
+
user: User & Record<string, any>;
|
|
306
|
+
} | null,
|
|
307
|
+
) => void;
|
|
308
|
+
socialProviders: OAuthProvider[];
|
|
309
|
+
authCookies: BetterAuthCookies;
|
|
310
|
+
logger: ReturnType<typeof createLogger>;
|
|
311
|
+
rateLimit: {
|
|
312
|
+
enabled: boolean;
|
|
313
|
+
window: number;
|
|
314
|
+
max: number;
|
|
315
|
+
storage: "memory" | "database" | "secondary-storage";
|
|
316
|
+
} & Omit<
|
|
317
|
+
BetterAuthRateLimitOptions,
|
|
318
|
+
"enabled" | "window" | "max" | "storage"
|
|
319
|
+
>;
|
|
320
|
+
adapter: DBAdapter<Options>;
|
|
321
|
+
internalAdapter: InternalAdapter<Options>;
|
|
322
|
+
createAuthCookie: CreateCookieGetterFn;
|
|
323
|
+
secret: string;
|
|
324
|
+
sessionConfig: {
|
|
325
|
+
updateAge: number;
|
|
326
|
+
expiresIn: number;
|
|
327
|
+
freshAge: number;
|
|
328
|
+
cookieRefreshCache:
|
|
329
|
+
| false
|
|
330
|
+
| {
|
|
331
|
+
enabled: true;
|
|
332
|
+
updateAge: number;
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
generateId: (options: {
|
|
336
|
+
model: ModelNames;
|
|
337
|
+
size?: number | undefined;
|
|
338
|
+
}) => string | false;
|
|
339
|
+
secondaryStorage: SecondaryStorage | undefined;
|
|
340
|
+
password: {
|
|
341
|
+
hash: (password: string) => Promise<string>;
|
|
342
|
+
verify: (data: { password: string; hash: string }) => Promise<boolean>;
|
|
343
|
+
config: {
|
|
344
|
+
minPasswordLength: number;
|
|
345
|
+
maxPasswordLength: number;
|
|
346
|
+
};
|
|
347
|
+
checkPassword: CheckPasswordFn<Options>;
|
|
348
|
+
};
|
|
349
|
+
tables: BetterAuthDBSchema;
|
|
350
|
+
runMigrations: () => Promise<void>;
|
|
351
|
+
publishTelemetry: (event: {
|
|
352
|
+
type: string;
|
|
353
|
+
anonymousId?: string | undefined;
|
|
354
|
+
payload: Record<string, any>;
|
|
355
|
+
}) => Promise<void>;
|
|
356
|
+
/**
|
|
357
|
+
* Skip origin check for requests.
|
|
358
|
+
*
|
|
359
|
+
* - `true`: Skip for ALL requests (DANGEROUS - disables CSRF protection)
|
|
360
|
+
* - `string[]`: Skip only for specific paths (e.g., SAML callbacks)
|
|
361
|
+
* - `false`: Enable origin check (default)
|
|
362
|
+
*
|
|
363
|
+
* Paths support prefix matching (e.g., "/sso/saml2/callback" matches
|
|
364
|
+
* "/sso/saml2/callback/provider-name").
|
|
365
|
+
*
|
|
366
|
+
* @default false (true in test environments)
|
|
367
|
+
*/
|
|
368
|
+
skipOriginCheck: boolean | string[];
|
|
369
|
+
/**
|
|
370
|
+
* This skips the CSRF check for all requests.
|
|
371
|
+
*
|
|
372
|
+
* This is inferred from the `options.advanced?.
|
|
373
|
+
* disableCSRFCheck` option.
|
|
374
|
+
*
|
|
375
|
+
* @default false
|
|
376
|
+
*/
|
|
377
|
+
skipCSRFCheck: boolean;
|
|
378
|
+
/**
|
|
379
|
+
* Background task handler for deferred operations.
|
|
380
|
+
*
|
|
381
|
+
* This is inferred from the `options.advanced?.backgroundTasks?.handler` option.
|
|
382
|
+
* Defaults to a no-op that just runs the promise.
|
|
383
|
+
*/
|
|
384
|
+
runInBackground: (promise: Promise<unknown>) => void;
|
|
385
|
+
/**
|
|
386
|
+
* Runs a task in the background if `runInBackground` is configured,
|
|
387
|
+
* otherwise awaits the task directly.
|
|
388
|
+
*
|
|
389
|
+
* This is useful for operations like sending emails where we want
|
|
390
|
+
* to avoid blocking the response when possible (for timing attack
|
|
391
|
+
* mitigation), but still ensure the operation completes.
|
|
392
|
+
*/
|
|
393
|
+
runInBackgroundOrAwait: (
|
|
394
|
+
promise: Promise<unknown> | void,
|
|
395
|
+
) => Awaitable<unknown>;
|
|
396
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CookieOptions } from "better-call";
|
|
2
|
+
|
|
3
|
+
export type BetterAuthCookie = { name: string; attributes: CookieOptions };
|
|
4
|
+
|
|
5
|
+
export type BetterAuthCookies = {
|
|
6
|
+
sessionToken: BetterAuthCookie;
|
|
7
|
+
sessionData: BetterAuthCookie;
|
|
8
|
+
accountData: BetterAuthCookie;
|
|
9
|
+
dontRememberToken: BetterAuthCookie;
|
|
10
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type Primitive =
|
|
2
|
+
| string
|
|
3
|
+
| number
|
|
4
|
+
| symbol
|
|
5
|
+
| bigint
|
|
6
|
+
| boolean
|
|
7
|
+
| null
|
|
8
|
+
| undefined;
|
|
9
|
+
|
|
10
|
+
export type Awaitable<T> = T | Promise<T>;
|
|
11
|
+
export type LiteralString = "" | (string & Record<never, never>);
|
|
12
|
+
export type LiteralUnion<LiteralType, BaseType extends Primitive> =
|
|
13
|
+
| LiteralType
|
|
14
|
+
| (BaseType & Record<never, never>);
|
|
15
|
+
|
|
16
|
+
export type Prettify<T> = {
|
|
17
|
+
[K in keyof T]: T[K];
|
|
18
|
+
} & {};
|
|
19
|
+
|
|
20
|
+
export type UnionToIntersection<U> = (
|
|
21
|
+
U extends any
|
|
22
|
+
? (k: U) => void
|
|
23
|
+
: never
|
|
24
|
+
) extends (k: infer I) => void
|
|
25
|
+
? I
|
|
26
|
+
: never;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
export type {
|
|
3
|
+
AuthContext,
|
|
4
|
+
BetterAuthPluginRegistry,
|
|
5
|
+
BetterAuthPluginRegistryIdentifier,
|
|
6
|
+
GenericEndpointContext,
|
|
7
|
+
InfoContext,
|
|
8
|
+
InternalAdapter,
|
|
9
|
+
PluginContext,
|
|
10
|
+
} from "./context";
|
|
11
|
+
export type {
|
|
12
|
+
BetterAuthCookie,
|
|
13
|
+
BetterAuthCookies,
|
|
14
|
+
} from "./cookie";
|
|
15
|
+
export type * from "./helper";
|
|
16
|
+
export type {
|
|
17
|
+
BetterAuthAdvancedOptions,
|
|
18
|
+
BetterAuthOptions,
|
|
19
|
+
BetterAuthRateLimitOptions,
|
|
20
|
+
BetterAuthRateLimitRule,
|
|
21
|
+
BetterAuthRateLimitStorage,
|
|
22
|
+
GenerateIdFn,
|
|
23
|
+
StoreIdentifierOption,
|
|
24
|
+
} from "./init-options";
|
|
25
|
+
export type { BetterAuthPlugin, HookEndpointContext } from "./plugin";
|
|
26
|
+
export type {
|
|
27
|
+
BetterAuthClientOptions,
|
|
28
|
+
BetterAuthClientPlugin,
|
|
29
|
+
ClientAtomListener,
|
|
30
|
+
ClientFetchOption,
|
|
31
|
+
ClientStore,
|
|
32
|
+
} from "./plugin-client";
|