@better-auth/core 1.5.0-beta.2 → 1.5.0-beta.20
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/LICENSE.md +15 -12
- package/README.md +17 -0
- package/dist/api/index.d.mts +280 -2
- package/dist/api/index.mjs +4 -2
- 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 +20 -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 -53
- package/dist/context/index.mjs +5 -2
- package/dist/context/request-state.d.mts +28 -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 +20 -0
- package/dist/db/adapter/factory.mjs +725 -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 +520 -2
- package/dist/db/adapter/index.mjs +27 -972
- package/dist/db/adapter/index.mjs.map +1 -0
- package/dist/db/adapter/types.d.mts +108 -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/{get-tables-CMc_Emww.mjs → db/get-tables.mjs} +52 -39
- package/dist/db/get-tables.mjs.map +1 -0
- package/dist/db/index.d.mts +10 -2
- package/dist/db/index.mjs +7 -60
- package/dist/db/plugin.d.mts +13 -0
- package/dist/db/schema/account.d.mts +30 -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 +20 -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 +25 -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 +24 -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 +23 -0
- package/dist/db/schema/verification.mjs +13 -0
- package/dist/db/schema/verification.mjs.map +1 -0
- package/dist/db/type.d.mts +169 -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 -2
- package/dist/env/index.mjs +3 -1
- package/dist/{index-BRBu0-5h.d.mts → env/logger.d.mts} +2 -35
- package/dist/env/logger.mjs +82 -0
- package/dist/env/logger.mjs.map +1 -0
- package/dist/error/codes.d.mts +69 -0
- package/dist/{error-C7mY-p0f.mjs → error/codes.mjs} +7 -30
- package/dist/error/codes.mjs.map +1 -0
- package/dist/error/index.d.mts +6 -187
- package/dist/error/index.mjs +29 -4
- package/dist/error/index.mjs.map +1 -0
- package/dist/index.d.mts +8 -2
- package/dist/oauth2/client-credentials-token.d.mts +58 -0
- package/dist/oauth2/client-credentials-token.mjs +67 -0
- package/dist/oauth2/client-credentials-token.mjs.map +1 -0
- package/dist/oauth2/create-authorization-url.d.mts +48 -0
- package/dist/oauth2/create-authorization-url.mjs +44 -0
- package/dist/oauth2/create-authorization-url.mjs.map +1 -0
- package/dist/oauth2/index.d.mts +8 -2
- package/dist/oauth2/index.mjs +7 -3
- package/dist/oauth2/oauth-provider.d.mts +195 -0
- package/dist/oauth2/refresh-access-token.d.mts +56 -0
- package/dist/oauth2/refresh-access-token.mjs +76 -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 +88 -0
- package/dist/oauth2/validate-authorization-code.mjs +83 -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 +113 -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 +1777 -2
- package/dist/social-providers/index.mjs +37 -2570
- 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 +177 -0
- package/dist/social-providers/microsoft-entra-id.mjs +140 -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/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 +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 +166 -0
- package/dist/social-providers/zoom.mjs +73 -0
- package/dist/social-providers/zoom.mjs.map +1 -0
- package/dist/types/context.d.mts +274 -0
- package/dist/types/cookie.d.mts +16 -0
- package/dist/types/helper.d.mts +11 -0
- package/dist/types/index.d.mts +8 -0
- package/dist/types/init-options.d.mts +1298 -0
- package/dist/types/plugin-client.d.mts +113 -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/{index.d.mts → error-codes.d.mts} +9 -16
- 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 +36 -18
- package/src/context/endpoint-context.ts +7 -6
- package/src/context/global.ts +57 -0
- package/src/context/index.ts +2 -0
- package/src/context/request-state.ts +7 -6
- package/src/context/transaction.ts +77 -14
- package/src/db/adapter/factory.ts +54 -86
- package/src/db/adapter/get-default-model-name.ts +1 -1
- package/src/db/adapter/get-id-field.ts +4 -6
- package/src/db/adapter/index.ts +20 -15
- package/src/db/adapter/types.ts +2 -41
- package/src/db/get-tables.ts +54 -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 +18 -1
- package/src/error/index.ts +2 -3
- package/src/oauth2/client-credentials-token.ts +26 -2
- package/src/oauth2/create-authorization-url.ts +4 -2
- package/src/oauth2/index.ts +3 -0
- package/src/oauth2/oauth-provider.ts +7 -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 +38 -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/figma.ts +5 -3
- package/src/social-providers/github.ts +26 -4
- package/src/social-providers/gitlab.ts +2 -2
- 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 +241 -132
- package/src/types/cookie.ts +6 -4
- package/src/types/helper.ts +9 -0
- package/src/types/index.ts +19 -2
- package/src/types/init-options.ts +301 -186
- package/src/types/plugin-client.ts +1 -0
- package/src/types/plugin.ts +11 -6
- package/src/utils/db.ts +20 -0
- package/src/utils/deprecate.test.ts +71 -0
- package/src/utils/deprecate.ts +21 -0
- package/src/utils/error-codes.ts +12 -9
- package/src/utils/ip.test.ts +255 -0
- package/src/utils/ip.ts +211 -0
- package/src/utils/url.ts +43 -0
- package/.turbo/turbo-build.log +0 -43
- package/dist/context-DblZrIwO.mjs +0 -114
- package/dist/env-DbssmzoK.mjs +0 -245
- package/dist/index-BpRqx5_q.d.mts +0 -7833
- package/dist/oauth2-BjWM15hm.mjs +0 -326
- package/dist/utils/index.mjs +0 -4
- package/dist/utils-s65Fz0OM.mjs +0 -47
- package/src/utils/index.ts +0 -4
- package/tsconfig.json +0 -7
- package/tsdown.config.ts +0 -22
- package/vitest.config.ts +0 -3
package/LICENSE.md
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
Copyright (c) 2024 - present, Bereket Engida
|
|
3
3
|
|
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
|
-
and associated documentation files (the
|
|
6
|
-
including without limitation the rights to
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
|
+
this software and associated documentation files (the “Software”), to deal in
|
|
6
|
+
the Software without restriction, including without limitation the rights to
|
|
7
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
8
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
9
|
+
subject to the following conditions:
|
|
9
10
|
|
|
10
|
-
The above copyright notice and this permission notice shall be included in all
|
|
11
|
-
substantial portions of the Software.
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
12
13
|
|
|
13
|
-
THE SOFTWARE IS PROVIDED
|
|
14
|
-
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
16
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
19
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Better Auth Core
|
|
2
|
+
|
|
3
|
+
Core utilities and types for [Better Auth](https://www.better-auth.com) — the most comprehensive authentication framework for TypeScript.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @better-auth/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
For full documentation, visit [better-auth.com](https://www.better-auth.com).
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
|
|
17
|
+
MIT
|
package/dist/api/index.d.mts
CHANGED
|
@@ -1,2 +1,280 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { BetterAuthDBSchema, ModelNames, SecondaryStorage } from "../db/type.mjs";
|
|
2
|
+
import { DBAdapter } from "../db/adapter/index.mjs";
|
|
3
|
+
import { createLogger } from "../env/logger.mjs";
|
|
4
|
+
import "../db/index.mjs";
|
|
5
|
+
import { AuthContext } from "../types/context.mjs";
|
|
6
|
+
import "../types/index.mjs";
|
|
7
|
+
import { OAuthProvider } from "../oauth2/oauth-provider.mjs";
|
|
8
|
+
import "../oauth2/index.mjs";
|
|
9
|
+
import * as better_call0 from "better-call";
|
|
10
|
+
import { EndpointContext, EndpointOptions, StrictEndpoint } from "better-call";
|
|
11
|
+
import * as _better_auth_core0 from "@better-auth/core";
|
|
12
|
+
|
|
13
|
+
//#region src/api/index.d.ts
|
|
14
|
+
declare const optionsMiddleware: <InputCtx extends better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>>(inputContext: InputCtx) => Promise<AuthContext>;
|
|
15
|
+
declare const createAuthMiddleware: {
|
|
16
|
+
<Options extends better_call0.MiddlewareOptions, R>(options: Options, handler: (ctx: better_call0.MiddlewareContext<Options, {
|
|
17
|
+
returned?: unknown | undefined;
|
|
18
|
+
responseHeaders?: Headers | undefined;
|
|
19
|
+
} & _better_auth_core0.PluginContext<_better_auth_core0.BetterAuthOptions> & _better_auth_core0.InfoContext & {
|
|
20
|
+
options: _better_auth_core0.BetterAuthOptions;
|
|
21
|
+
trustedOrigins: string[];
|
|
22
|
+
trustedProviders: string[];
|
|
23
|
+
isTrustedOrigin: (url: string, settings?: {
|
|
24
|
+
allowRelativePaths: boolean;
|
|
25
|
+
}) => boolean;
|
|
26
|
+
oauthConfig: {
|
|
27
|
+
skipStateCookieCheck?: boolean | undefined;
|
|
28
|
+
storeStateStrategy: "database" | "cookie";
|
|
29
|
+
};
|
|
30
|
+
newSession: {
|
|
31
|
+
session: {
|
|
32
|
+
id: string;
|
|
33
|
+
createdAt: Date;
|
|
34
|
+
updatedAt: Date;
|
|
35
|
+
userId: string;
|
|
36
|
+
expiresAt: Date;
|
|
37
|
+
token: string;
|
|
38
|
+
ipAddress?: string | null | undefined;
|
|
39
|
+
userAgent?: string | null | undefined;
|
|
40
|
+
} & Record<string, any>;
|
|
41
|
+
user: {
|
|
42
|
+
id: string;
|
|
43
|
+
createdAt: Date;
|
|
44
|
+
updatedAt: Date;
|
|
45
|
+
email: string;
|
|
46
|
+
emailVerified: boolean;
|
|
47
|
+
name: string;
|
|
48
|
+
image?: string | null | undefined;
|
|
49
|
+
} & Record<string, any>;
|
|
50
|
+
} | null;
|
|
51
|
+
session: {
|
|
52
|
+
session: {
|
|
53
|
+
id: string;
|
|
54
|
+
createdAt: Date;
|
|
55
|
+
updatedAt: Date;
|
|
56
|
+
userId: string;
|
|
57
|
+
expiresAt: Date;
|
|
58
|
+
token: string;
|
|
59
|
+
ipAddress?: string | null | undefined;
|
|
60
|
+
userAgent?: string | null | undefined;
|
|
61
|
+
} & Record<string, any>;
|
|
62
|
+
user: {
|
|
63
|
+
id: string;
|
|
64
|
+
createdAt: Date;
|
|
65
|
+
updatedAt: Date;
|
|
66
|
+
email: string;
|
|
67
|
+
emailVerified: boolean;
|
|
68
|
+
name: string;
|
|
69
|
+
image?: string | null | undefined;
|
|
70
|
+
} & Record<string, any>;
|
|
71
|
+
} | null;
|
|
72
|
+
setNewSession: (session: {
|
|
73
|
+
session: {
|
|
74
|
+
id: string;
|
|
75
|
+
createdAt: Date;
|
|
76
|
+
updatedAt: Date;
|
|
77
|
+
userId: string;
|
|
78
|
+
expiresAt: Date;
|
|
79
|
+
token: string;
|
|
80
|
+
ipAddress?: string | null | undefined;
|
|
81
|
+
userAgent?: string | null | undefined;
|
|
82
|
+
} & Record<string, any>;
|
|
83
|
+
user: {
|
|
84
|
+
id: string;
|
|
85
|
+
createdAt: Date;
|
|
86
|
+
updatedAt: Date;
|
|
87
|
+
email: string;
|
|
88
|
+
emailVerified: boolean;
|
|
89
|
+
name: string;
|
|
90
|
+
image?: string | null | undefined;
|
|
91
|
+
} & Record<string, any>;
|
|
92
|
+
} | null) => void;
|
|
93
|
+
socialProviders: OAuthProvider[];
|
|
94
|
+
authCookies: _better_auth_core0.BetterAuthCookies;
|
|
95
|
+
logger: ReturnType<typeof createLogger>;
|
|
96
|
+
rateLimit: {
|
|
97
|
+
enabled: boolean;
|
|
98
|
+
window: number;
|
|
99
|
+
max: number;
|
|
100
|
+
storage: "memory" | "database" | "secondary-storage";
|
|
101
|
+
} & Omit<_better_auth_core0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
|
|
102
|
+
adapter: DBAdapter<_better_auth_core0.BetterAuthOptions>;
|
|
103
|
+
internalAdapter: _better_auth_core0.InternalAdapter<_better_auth_core0.BetterAuthOptions>;
|
|
104
|
+
createAuthCookie: (cookieName: string, overrideAttributes?: Partial<better_call0.CookieOptions> | undefined) => _better_auth_core0.BetterAuthCookie;
|
|
105
|
+
secret: string;
|
|
106
|
+
sessionConfig: {
|
|
107
|
+
updateAge: number;
|
|
108
|
+
expiresIn: number;
|
|
109
|
+
freshAge: number;
|
|
110
|
+
cookieRefreshCache: false | {
|
|
111
|
+
enabled: true;
|
|
112
|
+
updateAge: number;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
generateId: (options: {
|
|
116
|
+
model: ModelNames;
|
|
117
|
+
size?: number | undefined;
|
|
118
|
+
}) => string | false;
|
|
119
|
+
secondaryStorage: SecondaryStorage | undefined;
|
|
120
|
+
password: {
|
|
121
|
+
hash: (password: string) => Promise<string>;
|
|
122
|
+
verify: (data: {
|
|
123
|
+
password: string;
|
|
124
|
+
hash: string;
|
|
125
|
+
}) => Promise<boolean>;
|
|
126
|
+
config: {
|
|
127
|
+
minPasswordLength: number;
|
|
128
|
+
maxPasswordLength: number;
|
|
129
|
+
};
|
|
130
|
+
checkPassword: (userId: string, ctx: _better_auth_core0.GenericEndpointContext<_better_auth_core0.BetterAuthOptions>) => Promise<boolean>;
|
|
131
|
+
};
|
|
132
|
+
tables: BetterAuthDBSchema;
|
|
133
|
+
runMigrations: () => Promise<void>;
|
|
134
|
+
publishTelemetry: (event: {
|
|
135
|
+
type: string;
|
|
136
|
+
anonymousId?: string | undefined;
|
|
137
|
+
payload: Record<string, any>;
|
|
138
|
+
}) => Promise<void>;
|
|
139
|
+
skipOriginCheck: boolean | string[];
|
|
140
|
+
skipCSRFCheck: boolean;
|
|
141
|
+
runInBackground: (promise: Promise<unknown>) => void;
|
|
142
|
+
runInBackgroundOrAwait: (promise: Promise<unknown> | void) => _better_auth_core0.Awaitable<unknown>;
|
|
143
|
+
}>) => Promise<R>): (inputContext: better_call0.MiddlewareInputContext<Options>) => Promise<R>;
|
|
144
|
+
<Options extends better_call0.MiddlewareOptions, R_1>(handler: (ctx: better_call0.MiddlewareContext<Options, {
|
|
145
|
+
returned?: unknown | undefined;
|
|
146
|
+
responseHeaders?: Headers | undefined;
|
|
147
|
+
} & _better_auth_core0.PluginContext<_better_auth_core0.BetterAuthOptions> & _better_auth_core0.InfoContext & {
|
|
148
|
+
options: _better_auth_core0.BetterAuthOptions;
|
|
149
|
+
trustedOrigins: string[];
|
|
150
|
+
trustedProviders: string[];
|
|
151
|
+
isTrustedOrigin: (url: string, settings?: {
|
|
152
|
+
allowRelativePaths: boolean;
|
|
153
|
+
}) => boolean;
|
|
154
|
+
oauthConfig: {
|
|
155
|
+
skipStateCookieCheck?: boolean | undefined;
|
|
156
|
+
storeStateStrategy: "database" | "cookie";
|
|
157
|
+
};
|
|
158
|
+
newSession: {
|
|
159
|
+
session: {
|
|
160
|
+
id: string;
|
|
161
|
+
createdAt: Date;
|
|
162
|
+
updatedAt: Date;
|
|
163
|
+
userId: string;
|
|
164
|
+
expiresAt: Date;
|
|
165
|
+
token: string;
|
|
166
|
+
ipAddress?: string | null | undefined;
|
|
167
|
+
userAgent?: string | null | undefined;
|
|
168
|
+
} & Record<string, any>;
|
|
169
|
+
user: {
|
|
170
|
+
id: string;
|
|
171
|
+
createdAt: Date;
|
|
172
|
+
updatedAt: Date;
|
|
173
|
+
email: string;
|
|
174
|
+
emailVerified: boolean;
|
|
175
|
+
name: string;
|
|
176
|
+
image?: string | null | undefined;
|
|
177
|
+
} & Record<string, any>;
|
|
178
|
+
} | null;
|
|
179
|
+
session: {
|
|
180
|
+
session: {
|
|
181
|
+
id: string;
|
|
182
|
+
createdAt: Date;
|
|
183
|
+
updatedAt: Date;
|
|
184
|
+
userId: string;
|
|
185
|
+
expiresAt: Date;
|
|
186
|
+
token: string;
|
|
187
|
+
ipAddress?: string | null | undefined;
|
|
188
|
+
userAgent?: string | null | undefined;
|
|
189
|
+
} & Record<string, any>;
|
|
190
|
+
user: {
|
|
191
|
+
id: string;
|
|
192
|
+
createdAt: Date;
|
|
193
|
+
updatedAt: Date;
|
|
194
|
+
email: string;
|
|
195
|
+
emailVerified: boolean;
|
|
196
|
+
name: string;
|
|
197
|
+
image?: string | null | undefined;
|
|
198
|
+
} & Record<string, any>;
|
|
199
|
+
} | null;
|
|
200
|
+
setNewSession: (session: {
|
|
201
|
+
session: {
|
|
202
|
+
id: string;
|
|
203
|
+
createdAt: Date;
|
|
204
|
+
updatedAt: Date;
|
|
205
|
+
userId: string;
|
|
206
|
+
expiresAt: Date;
|
|
207
|
+
token: string;
|
|
208
|
+
ipAddress?: string | null | undefined;
|
|
209
|
+
userAgent?: string | null | undefined;
|
|
210
|
+
} & Record<string, any>;
|
|
211
|
+
user: {
|
|
212
|
+
id: string;
|
|
213
|
+
createdAt: Date;
|
|
214
|
+
updatedAt: Date;
|
|
215
|
+
email: string;
|
|
216
|
+
emailVerified: boolean;
|
|
217
|
+
name: string;
|
|
218
|
+
image?: string | null | undefined;
|
|
219
|
+
} & Record<string, any>;
|
|
220
|
+
} | null) => void;
|
|
221
|
+
socialProviders: OAuthProvider[];
|
|
222
|
+
authCookies: _better_auth_core0.BetterAuthCookies;
|
|
223
|
+
logger: ReturnType<typeof createLogger>;
|
|
224
|
+
rateLimit: {
|
|
225
|
+
enabled: boolean;
|
|
226
|
+
window: number;
|
|
227
|
+
max: number;
|
|
228
|
+
storage: "memory" | "database" | "secondary-storage";
|
|
229
|
+
} & Omit<_better_auth_core0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
|
|
230
|
+
adapter: DBAdapter<_better_auth_core0.BetterAuthOptions>;
|
|
231
|
+
internalAdapter: _better_auth_core0.InternalAdapter<_better_auth_core0.BetterAuthOptions>;
|
|
232
|
+
createAuthCookie: (cookieName: string, overrideAttributes?: Partial<better_call0.CookieOptions> | undefined) => _better_auth_core0.BetterAuthCookie;
|
|
233
|
+
secret: string;
|
|
234
|
+
sessionConfig: {
|
|
235
|
+
updateAge: number;
|
|
236
|
+
expiresIn: number;
|
|
237
|
+
freshAge: number;
|
|
238
|
+
cookieRefreshCache: false | {
|
|
239
|
+
enabled: true;
|
|
240
|
+
updateAge: number;
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
generateId: (options: {
|
|
244
|
+
model: ModelNames;
|
|
245
|
+
size?: number | undefined;
|
|
246
|
+
}) => string | false;
|
|
247
|
+
secondaryStorage: SecondaryStorage | undefined;
|
|
248
|
+
password: {
|
|
249
|
+
hash: (password: string) => Promise<string>;
|
|
250
|
+
verify: (data: {
|
|
251
|
+
password: string;
|
|
252
|
+
hash: string;
|
|
253
|
+
}) => Promise<boolean>;
|
|
254
|
+
config: {
|
|
255
|
+
minPasswordLength: number;
|
|
256
|
+
maxPasswordLength: number;
|
|
257
|
+
};
|
|
258
|
+
checkPassword: (userId: string, ctx: _better_auth_core0.GenericEndpointContext<_better_auth_core0.BetterAuthOptions>) => Promise<boolean>;
|
|
259
|
+
};
|
|
260
|
+
tables: BetterAuthDBSchema;
|
|
261
|
+
runMigrations: () => Promise<void>;
|
|
262
|
+
publishTelemetry: (event: {
|
|
263
|
+
type: string;
|
|
264
|
+
anonymousId?: string | undefined;
|
|
265
|
+
payload: Record<string, any>;
|
|
266
|
+
}) => Promise<void>;
|
|
267
|
+
skipOriginCheck: boolean | string[];
|
|
268
|
+
skipCSRFCheck: boolean;
|
|
269
|
+
runInBackground: (promise: Promise<unknown>) => void;
|
|
270
|
+
runInBackgroundOrAwait: (promise: Promise<unknown> | void) => _better_auth_core0.Awaitable<unknown>;
|
|
271
|
+
}>) => Promise<R_1>): (inputContext: better_call0.MiddlewareInputContext<Options>) => Promise<R_1>;
|
|
272
|
+
};
|
|
273
|
+
type EndpointHandler<Path extends string, Options extends EndpointOptions, R> = (context: EndpointContext<Path, Options, AuthContext>) => Promise<R>;
|
|
274
|
+
declare function createAuthEndpoint<Path extends string, Options extends EndpointOptions, R>(path: Path, options: Options, handler: EndpointHandler<Path, Options, R>): StrictEndpoint<Path, Options, R>;
|
|
275
|
+
declare function createAuthEndpoint<Path extends string, Options extends EndpointOptions, R>(options: Options, handler: EndpointHandler<Path, Options, R>): StrictEndpoint<Path, Options, R>;
|
|
276
|
+
type AuthEndpoint<Path extends string, Opts extends EndpointOptions, R> = ReturnType<typeof createAuthEndpoint<Path, Opts, R>>;
|
|
277
|
+
type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;
|
|
278
|
+
//#endregion
|
|
279
|
+
export { AuthEndpoint, AuthMiddleware, createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
|
|
280
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/api/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { runWithEndpointContext } from "../context/endpoint-context.mjs";
|
|
2
|
+
import "../context/index.mjs";
|
|
2
3
|
import { createEndpoint, createMiddleware } from "better-call";
|
|
3
4
|
|
|
4
5
|
//#region src/api/index.ts
|
|
@@ -29,4 +30,5 @@ function createAuthEndpoint(pathOrOptions, handlerOrOptions, handlerOrNever) {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
//#endregion
|
|
32
|
-
export { createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
|
|
33
|
+
export { createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
|
|
34
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/api/index.ts"],"sourcesContent":["import type {\n\tEndpointContext,\n\tEndpointOptions,\n\tStrictEndpoint,\n} from \"better-call\";\nimport { createEndpoint, createMiddleware } from \"better-call\";\nimport { runWithEndpointContext } from \"../context\";\nimport type { AuthContext } from \"../types\";\n\nexport const optionsMiddleware = createMiddleware(async () => {\n\t/**\n\t * This will be passed on the instance of\n\t * the context. Used to infer the type\n\t * here.\n\t */\n\treturn {} as AuthContext;\n});\n\nexport const createAuthMiddleware = createMiddleware.create({\n\tuse: [\n\t\toptionsMiddleware,\n\t\t/**\n\t\t * Only use for post hooks\n\t\t */\n\t\tcreateMiddleware(async () => {\n\t\t\treturn {} as {\n\t\t\t\treturned?: unknown | undefined;\n\t\t\t\tresponseHeaders?: Headers | undefined;\n\t\t\t};\n\t\t}),\n\t],\n});\n\nconst use = [optionsMiddleware];\n\ntype EndpointHandler<\n\tPath extends string,\n\tOptions extends EndpointOptions,\n\tR,\n> = (context: EndpointContext<Path, Options, AuthContext>) => Promise<R>;\n\nexport function createAuthEndpoint<\n\tPath extends string,\n\tOptions extends EndpointOptions,\n\tR,\n>(\n\tpath: Path,\n\toptions: Options,\n\thandler: EndpointHandler<Path, Options, R>,\n): StrictEndpoint<Path, Options, R>;\n\nexport function createAuthEndpoint<\n\tPath extends string,\n\tOptions extends EndpointOptions,\n\tR,\n>(\n\toptions: Options,\n\thandler: EndpointHandler<Path, Options, R>,\n): StrictEndpoint<Path, Options, R>;\n\nexport function createAuthEndpoint<\n\tPath extends string,\n\tOpts extends EndpointOptions,\n\tR,\n>(\n\tpathOrOptions: Path | Opts,\n\thandlerOrOptions: EndpointHandler<Path, Opts, R> | Opts,\n\thandlerOrNever?: any,\n) {\n\tconst path: Path | undefined =\n\t\ttypeof pathOrOptions === \"string\" ? pathOrOptions : undefined;\n\tconst options: Opts =\n\t\ttypeof handlerOrOptions === \"object\"\n\t\t\t? handlerOrOptions\n\t\t\t: (pathOrOptions as Opts);\n\tconst handler: EndpointHandler<Path, Opts, R> =\n\t\ttypeof handlerOrOptions === \"function\" ? handlerOrOptions : handlerOrNever;\n\n\tif (path) {\n\t\treturn createEndpoint(\n\t\t\tpath,\n\t\t\t{\n\t\t\t\t...options,\n\t\t\t\tuse: [...(options?.use || []), ...use],\n\t\t\t},\n\t\t\t// todo: prettify the code, we want to call `runWithEndpointContext` to top level\n\t\t\tasync (ctx) => runWithEndpointContext(ctx as any, () => handler(ctx)),\n\t\t);\n\t}\n\n\treturn createEndpoint(\n\t\t{\n\t\t\t...options,\n\t\t\tuse: [...(options?.use || []), ...use],\n\t\t},\n\t\t// todo: prettify the code, we want to call `runWithEndpointContext` to top level\n\t\tasync (ctx) => runWithEndpointContext(ctx as any, () => handler(ctx)),\n\t);\n}\n\nexport type AuthEndpoint<\n\tPath extends string,\n\tOpts extends EndpointOptions,\n\tR,\n> = ReturnType<typeof createAuthEndpoint<Path, Opts, R>>;\nexport type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;\n"],"mappings":";;;;;AASA,MAAa,oBAAoB,iBAAiB,YAAY;;;;;;AAM7D,QAAO,EAAE;EACR;AAEF,MAAa,uBAAuB,iBAAiB,OAAO,EAC3D,KAAK,CACJ,mBAIA,iBAAiB,YAAY;AAC5B,QAAO,EAAE;EAIR,CACF,EACD,CAAC;AAEF,MAAM,MAAM,CAAC,kBAAkB;AA2B/B,SAAgB,mBAKf,eACA,kBACA,gBACC;CACD,MAAM,OACL,OAAO,kBAAkB,WAAW,gBAAgB;CACrD,MAAM,UACL,OAAO,qBAAqB,WACzB,mBACC;CACL,MAAM,UACL,OAAO,qBAAqB,aAAa,mBAAmB;AAE7D,KAAI,KACH,QAAO,eACN,MACA;EACC,GAAG;EACH,KAAK,CAAC,GAAI,SAAS,OAAO,EAAE,EAAG,GAAG,IAAI;EACtC,EAED,OAAO,QAAQ,uBAAuB,WAAkB,QAAQ,IAAI,CAAC,CACrE;AAGF,QAAO,eACN;EACC,GAAG;EACH,KAAK,CAAC,GAAI,SAAS,OAAO,EAAE,EAAG,GAAG,IAAI;EACtC,EAED,OAAO,QAAQ,uBAAuB,WAAkB,QAAQ,IAAI,CAAC,CACrE"}
|
|
@@ -3,4 +3,5 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
3
3
|
//#region src/async_hooks/index.d.ts
|
|
4
4
|
declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
|
|
5
5
|
//#endregion
|
|
6
|
-
export { type AsyncLocalStorage, getAsyncLocalStorage };
|
|
6
|
+
export { type AsyncLocalStorage, getAsyncLocalStorage };
|
|
7
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/async_hooks/index.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"node:async_hooks\";\n\nexport type { AsyncLocalStorage };\n\nconst AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage | null> =\n\timport(\n\t\t/* @vite-ignore */\n\t\t/* webpackIgnore: true */\n\t\t\"node:async_hooks\"\n\t)\n\t\t.then((mod) => mod.AsyncLocalStorage)\n\t\t.catch((err) => {\n\t\t\tif (\"AsyncLocalStorage\" in globalThis) {\n\t\t\t\treturn (globalThis as any).AsyncLocalStorage;\n\t\t\t}\n\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconsole.warn(\n\t\t\t\t\"[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected.\",\n\t\t\t);\n\t\t\tconsole.warn(\n\t\t\t\t\"[better-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler\",\n\t\t\t);\n\t\t\tconsole.warn(\n\t\t\t\t\"[better-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag\",\n\t\t\t);\n\t\t\tthrow err;\n\t\t});\n\nexport async function getAsyncLocalStorage(): Promise<\n\ttypeof AsyncLocalStorage\n> {\n\tconst mod = await AsyncLocalStoragePromise;\n\tif (mod === null) {\n\t\tthrow new Error(\"getAsyncLocalStorage is only available in server code\");\n\t} else {\n\t\treturn mod;\n\t}\n}\n"],"mappings":";AAIA,MAAM,2BACL;;;CAGC;EAEC,MAAM,QAAQ,IAAI,kBAAkB,CACpC,OAAO,QAAQ;AACf,KAAI,uBAAuB,WAC1B,QAAQ,WAAmB;AAE5B,KAAI,OAAO,WAAW,YACrB,QAAO;AAER,SAAQ,KACP,yHACA;AACD,SAAQ,KACP,+GACA;AACD,SAAQ,KACP,wKACA;AACD,OAAM;EACL;AAEJ,eAAsB,uBAEpB;CACD,MAAM,MAAM,MAAM;AAClB,KAAI,QAAQ,KACX,OAAM,IAAI,MAAM,wDAAwD;KAExE,QAAO"}
|
|
@@ -3,4 +3,5 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
3
3
|
//#region src/async_hooks/pure.index.d.ts
|
|
4
4
|
declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
|
|
5
5
|
//#endregion
|
|
6
|
-
export { getAsyncLocalStorage };
|
|
6
|
+
export { getAsyncLocalStorage };
|
|
7
|
+
//# sourceMappingURL=pure.index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pure.index.mjs","names":["#current"],"sources":["../../src/async_hooks/pure.index.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"node:async_hooks\";\n\n/**\n * Due to the lack of AsyncLocalStorage in some environments (like Convex),\n *\n * We assume serverless functions are short-lived and single-threaded, so we can use a simple polyfill.\n */\nclass AsyncLocalStoragePolyfill<T> {\n\t#current: T | undefined = undefined;\n\n\trun(store: T, fn: () => unknown): unknown {\n\t\tconst prev = this.#current;\n\t\tthis.#current = store;\n\t\tconst result = fn();\n\t\tif (result instanceof Promise) {\n\t\t\treturn result.finally(() => {\n\t\t\t\tthis.#current = prev;\n\t\t\t});\n\t\t}\n\t\tthis.#current = prev;\n\t\treturn result;\n\t}\n\n\tgetStore(): T | undefined {\n\t\treturn this.#current;\n\t}\n}\n\nconst AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage | null> =\n\tPromise.resolve().then(() => {\n\t\tif (\"AsyncLocalStorage\" in globalThis) {\n\t\t\treturn (globalThis as any).AsyncLocalStorage;\n\t\t}\n\t\treturn AsyncLocalStoragePolyfill;\n\t});\n\nexport async function getAsyncLocalStorage(): Promise<\n\ttypeof AsyncLocalStorage\n> {\n\tconst mod = await AsyncLocalStoragePromise;\n\tif (mod === null) {\n\t\tthrow new Error(\"getAsyncLocalStorage is only available in server code\");\n\t} else {\n\t\treturn mod;\n\t}\n}\n"],"mappings":";;;;;;AAOA,IAAM,4BAAN,MAAmC;CAClC,WAA0B;CAE1B,IAAI,OAAU,IAA4B;EACzC,MAAM,OAAO,MAAKA;AAClB,QAAKA,UAAW;EAChB,MAAM,SAAS,IAAI;AACnB,MAAI,kBAAkB,QACrB,QAAO,OAAO,cAAc;AAC3B,SAAKA,UAAW;IACf;AAEH,QAAKA,UAAW;AAChB,SAAO;;CAGR,WAA0B;AACzB,SAAO,MAAKA;;;AAId,MAAM,2BACL,QAAQ,SAAS,CAAC,WAAW;AAC5B,KAAI,uBAAuB,WAC1B,QAAQ,WAAmB;AAE5B,QAAO;EACN;AAEH,eAAsB,uBAEpB;CACD,MAAM,MAAM,MAAM;AAClB,KAAI,QAAQ,KACX,OAAM,IAAI,MAAM,wDAAwD;KAExE,QAAO"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AuthContext } from "../types/context.mjs";
|
|
2
|
+
import "../types/index.mjs";
|
|
3
|
+
import { EndpointContext, InputContext } from "better-call";
|
|
4
|
+
import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
|
|
5
|
+
|
|
6
|
+
//#region src/context/endpoint-context.d.ts
|
|
7
|
+
type AuthEndpointContext = Partial<InputContext<string, any> & EndpointContext<string, any>> & {
|
|
8
|
+
context: AuthContext;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* This is for internal use only. Most users should use `getCurrentAuthContext` instead.
|
|
12
|
+
*
|
|
13
|
+
* It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
|
|
14
|
+
*/
|
|
15
|
+
declare function getCurrentAuthContextAsyncLocalStorage(): Promise<AsyncLocalStorage<AuthEndpointContext>>;
|
|
16
|
+
declare function getCurrentAuthContext(): Promise<AuthEndpointContext>;
|
|
17
|
+
declare function runWithEndpointContext<T>(context: AuthEndpointContext, fn: () => T): Promise<T>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { AuthEndpointContext, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, runWithEndpointContext };
|
|
20
|
+
//# sourceMappingURL=endpoint-context.d.mts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { __getBetterAuthGlobal } from "./global.mjs";
|
|
2
|
+
import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
|
|
3
|
+
|
|
4
|
+
//#region src/context/endpoint-context.ts
|
|
5
|
+
const ensureAsyncStorage = async () => {
|
|
6
|
+
const betterAuthGlobal = __getBetterAuthGlobal();
|
|
7
|
+
if (!betterAuthGlobal.context.endpointContextAsyncStorage) {
|
|
8
|
+
const AsyncLocalStorage = await getAsyncLocalStorage();
|
|
9
|
+
betterAuthGlobal.context.endpointContextAsyncStorage = new AsyncLocalStorage();
|
|
10
|
+
}
|
|
11
|
+
return betterAuthGlobal.context.endpointContextAsyncStorage;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* This is for internal use only. Most users should use `getCurrentAuthContext` instead.
|
|
15
|
+
*
|
|
16
|
+
* It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
|
|
17
|
+
*/
|
|
18
|
+
async function getCurrentAuthContextAsyncLocalStorage() {
|
|
19
|
+
return ensureAsyncStorage();
|
|
20
|
+
}
|
|
21
|
+
async function getCurrentAuthContext() {
|
|
22
|
+
const context = (await ensureAsyncStorage()).getStore();
|
|
23
|
+
if (!context) throw new Error("No auth context found. Please make sure you are calling this function within a `runWithEndpointContext` callback.");
|
|
24
|
+
return context;
|
|
25
|
+
}
|
|
26
|
+
async function runWithEndpointContext(context, fn) {
|
|
27
|
+
return (await ensureAsyncStorage()).run(context, fn);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, runWithEndpointContext };
|
|
32
|
+
//# sourceMappingURL=endpoint-context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint-context.mjs","names":[],"sources":["../../src/context/endpoint-context.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"@better-auth/core/async_hooks\";\nimport { getAsyncLocalStorage } from \"@better-auth/core/async_hooks\";\nimport type { EndpointContext, InputContext } from \"better-call\";\nimport type { AuthContext } from \"../types\";\nimport { __getBetterAuthGlobal } from \"./global\";\n\nexport type AuthEndpointContext = Partial<\n\tInputContext<string, any> & EndpointContext<string, any>\n> & {\n\tcontext: AuthContext;\n};\n\nconst ensureAsyncStorage = async () => {\n\tconst betterAuthGlobal = __getBetterAuthGlobal();\n\tif (!betterAuthGlobal.context.endpointContextAsyncStorage) {\n\t\tconst AsyncLocalStorage = await getAsyncLocalStorage();\n\t\tbetterAuthGlobal.context.endpointContextAsyncStorage =\n\t\t\tnew AsyncLocalStorage<AuthEndpointContext>();\n\t}\n\treturn betterAuthGlobal.context\n\t\t.endpointContextAsyncStorage as AsyncLocalStorage<AuthEndpointContext>;\n};\n\n/**\n * This is for internal use only. Most users should use `getCurrentAuthContext` instead.\n *\n * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.\n */\nexport async function getCurrentAuthContextAsyncLocalStorage() {\n\treturn ensureAsyncStorage();\n}\n\nexport async function getCurrentAuthContext(): Promise<AuthEndpointContext> {\n\tconst als = await ensureAsyncStorage();\n\tconst context = als.getStore();\n\tif (!context) {\n\t\tthrow new Error(\n\t\t\t\"No auth context found. Please make sure you are calling this function within a `runWithEndpointContext` callback.\",\n\t\t);\n\t}\n\treturn context;\n}\n\nexport async function runWithEndpointContext<T>(\n\tcontext: AuthEndpointContext,\n\tfn: () => T,\n): Promise<T> {\n\tconst als = await ensureAsyncStorage();\n\treturn als.run(context, fn);\n}\n"],"mappings":";;;;AAYA,MAAM,qBAAqB,YAAY;CACtC,MAAM,mBAAmB,uBAAuB;AAChD,KAAI,CAAC,iBAAiB,QAAQ,6BAA6B;EAC1D,MAAM,oBAAoB,MAAM,sBAAsB;AACtD,mBAAiB,QAAQ,8BACxB,IAAI,mBAAwC;;AAE9C,QAAO,iBAAiB,QACtB;;;;;;;AAQH,eAAsB,yCAAyC;AAC9D,QAAO,oBAAoB;;AAG5B,eAAsB,wBAAsD;CAE3E,MAAM,WADM,MAAM,oBAAoB,EAClB,UAAU;AAC9B,KAAI,CAAC,QACJ,OAAM,IAAI,MACT,oHACA;AAEF,QAAO;;AAGR,eAAsB,uBACrB,SACA,IACa;AAEb,SADY,MAAM,oBAAoB,EAC3B,IAAI,SAAS,GAAG"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/context/global.ts
|
|
2
|
+
const symbol = Symbol.for("better-auth:global");
|
|
3
|
+
let bind = null;
|
|
4
|
+
const __context = {};
|
|
5
|
+
const __betterAuthVersion = "1.5.0-beta.20";
|
|
6
|
+
/**
|
|
7
|
+
* We store context instance in the globalThis.
|
|
8
|
+
*
|
|
9
|
+
* The reason we do this is that some bundlers, web framework, or package managers might
|
|
10
|
+
* create multiple copies of BetterAuth in the same process intentionally or unintentionally.
|
|
11
|
+
*
|
|
12
|
+
* For example, yarn v1, Next.js, SSR, Vite...
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
function __getBetterAuthGlobal() {
|
|
17
|
+
if (!globalThis[symbol]) {
|
|
18
|
+
globalThis[symbol] = {
|
|
19
|
+
version: __betterAuthVersion,
|
|
20
|
+
epoch: 1,
|
|
21
|
+
context: __context
|
|
22
|
+
};
|
|
23
|
+
bind = globalThis[symbol];
|
|
24
|
+
}
|
|
25
|
+
bind = globalThis[symbol];
|
|
26
|
+
if (bind.version !== __betterAuthVersion) {
|
|
27
|
+
bind.version = __betterAuthVersion;
|
|
28
|
+
bind.epoch++;
|
|
29
|
+
}
|
|
30
|
+
return globalThis[symbol];
|
|
31
|
+
}
|
|
32
|
+
function getBetterAuthVersion() {
|
|
33
|
+
return __getBetterAuthGlobal().version;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { __getBetterAuthGlobal, getBetterAuthVersion };
|
|
38
|
+
//# sourceMappingURL=global.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.mjs","names":[],"sources":["../../src/context/global.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"@better-auth/core/async_hooks\";\n\ninterface BetterAuthGlobal {\n\t/**\n\t * The version of BetterAuth.\n\t */\n\tversion: string;\n\t/**\n\t * Used to track the number of BetterAuth instances in the same process.\n\t *\n\t * Debugging purposes only.\n\t */\n\tepoch: number;\n\t/**\n\t * Stores the AsyncLocalStorage instances for each context.\n\t */\n\tcontext: Record<string, AsyncLocalStorage<unknown>>;\n}\n\nconst symbol = Symbol.for(\"better-auth:global\");\nlet bind: BetterAuthGlobal | null = null;\n\nconst __context: Record<string, AsyncLocalStorage<unknown>> = {};\nconst __betterAuthVersion: string = import.meta.env\n\t.BETTER_AUTH_VERSION as string;\n\n/**\n * We store context instance in the globalThis.\n *\n * The reason we do this is that some bundlers, web framework, or package managers might\n * create multiple copies of BetterAuth in the same process intentionally or unintentionally.\n *\n * For example, yarn v1, Next.js, SSR, Vite...\n *\n * @internal\n */\nexport function __getBetterAuthGlobal(): BetterAuthGlobal {\n\tif (!(globalThis as any)[symbol]) {\n\t\t(globalThis as any)[symbol] = {\n\t\t\tversion: __betterAuthVersion,\n\t\t\tepoch: 1,\n\t\t\tcontext: __context,\n\t\t};\n\t\tbind = (globalThis as any)[symbol] as BetterAuthGlobal;\n\t}\n\tbind = (globalThis as any)[symbol] as BetterAuthGlobal;\n\tif (bind.version !== __betterAuthVersion) {\n\t\tbind.version = __betterAuthVersion;\n\t\t// Different versions of BetterAuth are loaded in the same process.\n\t\tbind.epoch++;\n\t}\n\treturn (globalThis as any)[symbol] as BetterAuthGlobal;\n}\n\nexport function getBetterAuthVersion(): string {\n\treturn __getBetterAuthGlobal().version;\n}\n"],"mappings":";AAmBA,MAAM,SAAS,OAAO,IAAI,qBAAqB;AAC/C,IAAI,OAAgC;AAEpC,MAAM,YAAwD,EAAE;AAChE,MAAM;;;;;;;;;;;AAaN,SAAgB,wBAA0C;AACzD,KAAI,CAAE,WAAmB,SAAS;AACjC,EAAC,WAAmB,UAAU;GAC7B,SAAS;GACT,OAAO;GACP,SAAS;GACT;AACD,SAAQ,WAAmB;;AAE5B,QAAQ,WAAmB;AAC3B,KAAI,KAAK,YAAY,qBAAqB;AACzC,OAAK,UAAU;AAEf,OAAK;;AAEN,QAAQ,WAAmB;;AAG5B,SAAgB,uBAA+B;AAC9C,QAAO,uBAAuB,CAAC"}
|
package/dist/context/index.d.mts
CHANGED
|
@@ -1,53 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type AuthEndpointContext = Partial<InputContext<string, any> & EndpointContext<string, any>> & {
|
|
7
|
-
context: AuthContext;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* This is for internal use only. Most users should use `getCurrentAuthContext` instead.
|
|
11
|
-
*
|
|
12
|
-
* It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
|
|
13
|
-
*/
|
|
14
|
-
declare function getCurrentAuthContextAsyncLocalStorage(): Promise<AsyncLocalStorage<AuthEndpointContext>>;
|
|
15
|
-
declare function getCurrentAuthContext(): Promise<AuthEndpointContext>;
|
|
16
|
-
declare function runWithEndpointContext<T>(context: AuthEndpointContext, fn: () => T): Promise<T>;
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/context/request-state.d.ts
|
|
19
|
-
type RequestStateWeakMap = WeakMap<object, any>;
|
|
20
|
-
declare function getRequestStateAsyncLocalStorage(): Promise<AsyncLocalStorage<RequestStateWeakMap>>;
|
|
21
|
-
declare function hasRequestState(): Promise<boolean>;
|
|
22
|
-
declare function getCurrentRequestState(): Promise<RequestStateWeakMap>;
|
|
23
|
-
declare function runWithRequestState<T>(store: RequestStateWeakMap, fn: () => T): Promise<T>;
|
|
24
|
-
interface RequestState<T> {
|
|
25
|
-
get(): Promise<T>;
|
|
26
|
-
set(value: T): Promise<void>;
|
|
27
|
-
readonly ref: Readonly<object>;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Defines a request-scoped state with lazy initialization.
|
|
31
|
-
*
|
|
32
|
-
* @param initFn - A function that initializes the state. It is called the first time `get()` is invoked within each request context, and only once per context.
|
|
33
|
-
* @returns A RequestState object with `get` and `set` methods, and a unique `ref` for debugging.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* const userState = defineRequestState(() => ({ id: '', name: '' }));
|
|
37
|
-
* // Later, within a request context:
|
|
38
|
-
* const user = await userState.get();
|
|
39
|
-
*/
|
|
40
|
-
declare function defineRequestState<T>(initFn: () => T | Promise<T>): RequestState<T>;
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/context/transaction.d.ts
|
|
43
|
-
/**
|
|
44
|
-
* This is for internal use only. Most users should use `getCurrentAdapter` instead.
|
|
45
|
-
*
|
|
46
|
-
* It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
|
|
47
|
-
*/
|
|
48
|
-
declare const getCurrentDBAdapterAsyncLocalStorage: () => Promise<AsyncLocalStorage<DBTransactionAdapter>>;
|
|
49
|
-
declare const getCurrentAdapter: (fallback: DBTransactionAdapter) => Promise<DBTransactionAdapter>;
|
|
50
|
-
declare const runWithAdapter: <R>(adapter: DBAdapter, fn: () => R) => Promise<R>;
|
|
51
|
-
declare const runWithTransaction: <R>(adapter: DBAdapter, fn: () => R) => Promise<R>;
|
|
52
|
-
//#endregion
|
|
53
|
-
export { type AuthEndpointContext, type RequestState, type RequestStateWeakMap, defineRequestState, getCurrentAdapter, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentDBAdapterAsyncLocalStorage, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithAdapter, runWithEndpointContext, runWithRequestState, runWithTransaction };
|
|
1
|
+
import { AuthEndpointContext, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, runWithEndpointContext } from "./endpoint-context.mjs";
|
|
2
|
+
import { getBetterAuthVersion } from "./global.mjs";
|
|
3
|
+
import { RequestState, RequestStateWeakMap, defineRequestState, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithRequestState } from "./request-state.mjs";
|
|
4
|
+
import { getCurrentAdapter, getCurrentDBAdapterAsyncLocalStorage, queueAfterTransactionHook, runWithAdapter, runWithTransaction } from "./transaction.mjs";
|
|
5
|
+
export { type AuthEndpointContext, type RequestState, type RequestStateWeakMap, defineRequestState, getBetterAuthVersion, getCurrentAdapter, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentDBAdapterAsyncLocalStorage, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, queueAfterTransactionHook, runWithAdapter, runWithEndpointContext, runWithRequestState, runWithTransaction };
|
package/dist/context/index.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getBetterAuthVersion } from "./global.mjs";
|
|
2
|
+
import { getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, runWithEndpointContext } from "./endpoint-context.mjs";
|
|
3
|
+
import { defineRequestState, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithRequestState } from "./request-state.mjs";
|
|
4
|
+
import { getCurrentAdapter, getCurrentDBAdapterAsyncLocalStorage, queueAfterTransactionHook, runWithAdapter, runWithTransaction } from "./transaction.mjs";
|
|
2
5
|
|
|
3
|
-
export { defineRequestState, getCurrentAdapter, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentDBAdapterAsyncLocalStorage, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithAdapter, runWithEndpointContext, runWithRequestState, runWithTransaction };
|
|
6
|
+
export { defineRequestState, getBetterAuthVersion, getCurrentAdapter, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentDBAdapterAsyncLocalStorage, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, queueAfterTransactionHook, runWithAdapter, runWithEndpointContext, runWithRequestState, runWithTransaction };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
|
|
2
|
+
|
|
3
|
+
//#region src/context/request-state.d.ts
|
|
4
|
+
type RequestStateWeakMap = WeakMap<object, any>;
|
|
5
|
+
declare function getRequestStateAsyncLocalStorage(): Promise<AsyncLocalStorage<RequestStateWeakMap>>;
|
|
6
|
+
declare function hasRequestState(): Promise<boolean>;
|
|
7
|
+
declare function getCurrentRequestState(): Promise<RequestStateWeakMap>;
|
|
8
|
+
declare function runWithRequestState<T>(store: RequestStateWeakMap, fn: () => T): Promise<T>;
|
|
9
|
+
interface RequestState<T> {
|
|
10
|
+
get(): Promise<T>;
|
|
11
|
+
set(value: T): Promise<void>;
|
|
12
|
+
readonly ref: Readonly<object>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Defines a request-scoped state with lazy initialization.
|
|
16
|
+
*
|
|
17
|
+
* @param initFn - A function that initializes the state. It is called the first time `get()` is invoked within each request context, and only once per context.
|
|
18
|
+
* @returns A RequestState object with `get` and `set` methods, and a unique `ref` for debugging.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const userState = defineRequestState(() => ({ id: '', name: '' }));
|
|
22
|
+
* // Later, within a request context:
|
|
23
|
+
* const user = await userState.get();
|
|
24
|
+
*/
|
|
25
|
+
declare function defineRequestState<T>(initFn: () => T | Promise<T>): RequestState<T>;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { RequestState, RequestStateWeakMap, defineRequestState, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithRequestState };
|
|
28
|
+
//# sourceMappingURL=request-state.d.mts.map
|