@better-auth/core 1.6.23 → 1.6.25
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/dist/api/index.d.mts +28 -28
- package/dist/async_hooks/index.d.mts +0 -1
- package/dist/async_hooks/pure.index.d.mts +0 -1
- package/dist/context/endpoint-context.d.mts +1 -1
- package/dist/context/global.d.mts +0 -1
- package/dist/context/global.mjs +1 -1
- package/dist/context/request-state.d.mts +0 -1
- package/dist/context/request-state.mjs +8 -5
- package/dist/context/transaction.d.mts +1 -1
- package/dist/db/adapter/factory.d.mts +3 -5
- package/dist/db/adapter/factory.mjs +1 -1
- package/dist/db/adapter/get-default-field-name.d.mts +2 -9
- package/dist/db/adapter/get-default-model-name.d.mts +1 -5
- package/dist/db/adapter/get-default-model-name.mjs +6 -5
- package/dist/db/adapter/get-field-attributes.d.mts +4 -11
- package/dist/db/adapter/get-field-name.d.mts +2 -9
- package/dist/db/adapter/get-id-field.d.mts +4 -12
- package/dist/db/adapter/get-model-name.d.mts +1 -5
- package/dist/db/adapter/index.d.mts +7 -32
- package/dist/db/adapter/types.d.mts +5 -17
- package/dist/db/adapter/utils.d.mts +0 -1
- package/dist/db/get-tables.d.mts +1 -0
- package/dist/db/get-tables.mjs +2 -2
- package/dist/db/plugin.d.mts +1 -2
- package/dist/db/schema/account.d.mts +1 -1
- package/dist/db/schema/account.mjs +12 -0
- package/dist/db/schema/rate-limit.d.mts +1 -1
- package/dist/db/schema/rate-limit.mjs +9 -0
- package/dist/db/schema/session.d.mts +1 -1
- package/dist/db/schema/shared.d.mts +0 -1
- package/dist/db/schema/user.d.mts +1 -1
- package/dist/db/schema/verification.d.mts +1 -1
- package/dist/db/type.d.mts +5 -8
- package/dist/env/logger.d.mts +25 -25
- package/dist/error/codes.d.mts +0 -1
- package/dist/error/index.d.mts +0 -1
- package/dist/index.d.mts +1 -1
- package/dist/instrumentation/attributes.d.mts +0 -1
- package/dist/instrumentation/pure.index.d.mts +0 -1
- package/dist/instrumentation/tracer.mjs +1 -1
- package/dist/oauth2/client-credentials-token.d.mts +4 -20
- package/dist/oauth2/client-credentials-token.mjs +1 -4
- package/dist/oauth2/create-authorization-url.d.mts +3 -20
- package/dist/oauth2/oauth-provider.d.mts +9 -3
- package/dist/oauth2/refresh-access-token.d.mts +4 -22
- package/dist/oauth2/refresh-access-token.mjs +2 -8
- package/dist/oauth2/reject-redirects.mjs +1 -1
- package/dist/oauth2/utils.d.mts +0 -1
- package/dist/oauth2/utils.mjs +1 -2
- package/dist/oauth2/validate-authorization-code.d.mts +6 -37
- package/dist/oauth2/verify.d.mts +12 -10
- package/dist/oauth2/verify.mjs +2 -2
- package/dist/social-providers/apple.d.mts +7 -28
- package/dist/social-providers/apple.mjs +4 -3
- package/dist/social-providers/atlassian.d.mts +3 -11
- package/dist/social-providers/cognito.d.mts +6 -12
- package/dist/social-providers/cognito.mjs +2 -2
- package/dist/social-providers/discord.d.mts +3 -9
- package/dist/social-providers/dropbox.d.mts +3 -11
- package/dist/social-providers/facebook.d.mts +6 -11
- package/dist/social-providers/facebook.mjs +2 -2
- package/dist/social-providers/figma.d.mts +3 -11
- package/dist/social-providers/github.d.mts +3 -12
- package/dist/social-providers/gitlab.d.mts +3 -12
- package/dist/social-providers/google.d.mts +7 -20
- package/dist/social-providers/google.mjs +2 -2
- package/dist/social-providers/huggingface.d.mts +3 -11
- package/dist/social-providers/index.d.mts +78 -362
- package/dist/social-providers/kakao.d.mts +3 -9
- package/dist/social-providers/kick.d.mts +3 -11
- package/dist/social-providers/line.d.mts +6 -13
- package/dist/social-providers/line.mjs +2 -2
- package/dist/social-providers/linear.d.mts +3 -10
- package/dist/social-providers/linkedin.d.mts +3 -10
- package/dist/social-providers/microsoft-entra-id.d.mts +5 -6
- package/dist/social-providers/microsoft-entra-id.mjs +4 -3
- package/dist/social-providers/naver.d.mts +22 -18
- package/dist/social-providers/notion.d.mts +3 -10
- package/dist/social-providers/paybin.d.mts +3 -12
- package/dist/social-providers/paypal.d.mts +6 -10
- package/dist/social-providers/paypal.mjs +2 -2
- package/dist/social-providers/polar.d.mts +3 -11
- package/dist/social-providers/railway.d.mts +3 -11
- package/dist/social-providers/reddit.d.mts +3 -9
- package/dist/social-providers/roblox.d.mts +3 -9
- package/dist/social-providers/salesforce.d.mts +3 -11
- package/dist/social-providers/slack.d.mts +3 -9
- package/dist/social-providers/spotify.d.mts +3 -11
- package/dist/social-providers/tiktok.d.mts +5 -10
- package/dist/social-providers/twitch.d.mts +3 -9
- package/dist/social-providers/twitter.d.mts +26 -17
- package/dist/social-providers/vercel.d.mts +3 -11
- package/dist/social-providers/vk.d.mts +3 -12
- package/dist/social-providers/vk.mjs +4 -5
- package/dist/social-providers/wechat.d.mts +3 -8
- package/dist/social-providers/zoom.d.mts +5 -14
- package/dist/types/context.d.mts +2 -1
- package/dist/types/cookie.d.mts +0 -1
- package/dist/types/helper.d.mts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/init-options.d.mts +10 -7
- package/dist/types/plugin-client.d.mts +1 -3
- package/dist/types/plugin.d.mts +2 -2
- package/dist/utils/async.d.mts +0 -1
- package/dist/utils/db.d.mts +1 -0
- package/dist/utils/deprecate.d.mts +0 -1
- package/dist/utils/error-codes.d.mts +2 -2
- package/dist/utils/host.d.mts +27 -1
- package/dist/utils/host.mjs +1 -1
- package/dist/utils/ip.d.mts +1 -0
- package/dist/utils/ip.mjs +1 -1
- package/dist/utils/is-api-error.d.mts +0 -1
- package/dist/utils/redirect-uri.d.mts +0 -1
- package/package.json +2 -2
- package/src/context/request-state.ts +26 -6
- package/src/db/adapter/get-default-model-name.ts +23 -14
- package/src/db/get-tables.ts +17 -2
- package/src/oauth2/oauth-provider.ts +20 -4
- package/src/social-providers/apple.ts +9 -3
- package/src/social-providers/cognito.ts +7 -2
- package/src/social-providers/facebook.ts +7 -2
- package/src/social-providers/google.ts +7 -2
- package/src/social-providers/line.ts +7 -2
- package/src/social-providers/microsoft-entra-id.ts +7 -2
- package/src/social-providers/paypal.ts +7 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
2
3
|
//#region src/social-providers/tiktok.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* [More info](https://developers.tiktok.com/doc/tiktok-api-v2-get-user-info/)
|
|
@@ -51,7 +52,8 @@ interface TiktokProfile extends Record<string, any> {
|
|
|
51
52
|
*
|
|
52
53
|
* To return this field, add `fields=username` in the user profile request's query parameter.
|
|
53
54
|
*/
|
|
54
|
-
username: string;
|
|
55
|
+
username: string;
|
|
56
|
+
/** @note Email is currently unsupported by TikTok */
|
|
55
57
|
email?: string | undefined;
|
|
56
58
|
/**
|
|
57
59
|
* User's bio description if there is a valid one.
|
|
@@ -121,11 +123,7 @@ interface TiktokOptions extends ProviderOptions {
|
|
|
121
123
|
declare const tiktok: (options: TiktokOptions) => {
|
|
122
124
|
id: "tiktok";
|
|
123
125
|
name: string;
|
|
124
|
-
createAuthorizationURL({
|
|
125
|
-
state,
|
|
126
|
-
scopes,
|
|
127
|
-
redirectURI
|
|
128
|
-
}: {
|
|
126
|
+
createAuthorizationURL({ state, scopes, redirectURI }: {
|
|
129
127
|
state: string;
|
|
130
128
|
codeVerifier: string;
|
|
131
129
|
scopes?: string[] | undefined;
|
|
@@ -133,10 +131,7 @@ declare const tiktok: (options: TiktokOptions) => {
|
|
|
133
131
|
display?: string | undefined;
|
|
134
132
|
loginHint?: string | undefined;
|
|
135
133
|
}): URL;
|
|
136
|
-
validateAuthorizationCode: ({
|
|
137
|
-
code,
|
|
138
|
-
redirectURI
|
|
139
|
-
}: {
|
|
134
|
+
validateAuthorizationCode: ({ code, redirectURI }: {
|
|
140
135
|
code: string;
|
|
141
136
|
redirectURI: string;
|
|
142
137
|
codeVerifier?: string | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
2
3
|
//#region src/social-providers/twitch.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* @see https://dev.twitch.tv/docs/authentication/getting-tokens-oidc/#requesting-claims
|
|
@@ -32,11 +33,7 @@ interface TwitchOptions extends ProviderOptions<TwitchProfile> {
|
|
|
32
33
|
declare const twitch: (options: TwitchOptions) => {
|
|
33
34
|
id: "twitch";
|
|
34
35
|
name: string;
|
|
35
|
-
createAuthorizationURL({
|
|
36
|
-
state,
|
|
37
|
-
scopes,
|
|
38
|
-
redirectURI
|
|
39
|
-
}: {
|
|
36
|
+
createAuthorizationURL({ state, scopes, redirectURI }: {
|
|
40
37
|
state: string;
|
|
41
38
|
codeVerifier: string;
|
|
42
39
|
scopes?: string[] | undefined;
|
|
@@ -44,10 +41,7 @@ declare const twitch: (options: TwitchOptions) => {
|
|
|
44
41
|
display?: string | undefined;
|
|
45
42
|
loginHint?: string | undefined;
|
|
46
43
|
}): Promise<URL>;
|
|
47
|
-
validateAuthorizationCode: ({
|
|
48
|
-
code,
|
|
49
|
-
redirectURI
|
|
50
|
-
}: {
|
|
44
|
+
validateAuthorizationCode: ({ code, redirectURI }: {
|
|
51
45
|
code: string;
|
|
52
46
|
redirectURI: string;
|
|
53
47
|
codeVerifier?: string | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
2
3
|
//#region src/social-providers/twitter.d.ts
|
|
3
4
|
interface TwitterProfile {
|
|
4
5
|
data: {
|
|
@@ -6,9 +7,12 @@ interface TwitterProfile {
|
|
|
6
7
|
* Unique identifier of this user. This is returned as a string in order to avoid complications with languages and tools
|
|
7
8
|
* that cannot handle large integers.
|
|
8
9
|
*/
|
|
9
|
-
id: string;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
id: string;
|
|
11
|
+
/** The friendly name of this user, as shown on their profile. */
|
|
12
|
+
name: string;
|
|
13
|
+
/** The email address of this user. */
|
|
14
|
+
email?: string | undefined;
|
|
15
|
+
/** The Twitter handle (screen name) of this user. */
|
|
12
16
|
username: string;
|
|
13
17
|
/**
|
|
14
18
|
* The location specified in the user's profile, if the user provided one.
|
|
@@ -23,15 +27,23 @@ interface TwitterProfile {
|
|
|
23
27
|
*To return this field, add `user.fields=entities` in the authorization request's query parameter.
|
|
24
28
|
*/
|
|
25
29
|
entities?: {
|
|
26
|
-
/** Contains details about the user's profile website. */
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
/** Contains details about the user's profile website. */
|
|
31
|
+
url: {
|
|
32
|
+
/** Contains details about the user's profile website. */
|
|
33
|
+
urls: Array<{
|
|
34
|
+
/** The start position (zero-based) of the recognized user's profile website. All start indices are inclusive. */
|
|
35
|
+
start: number;
|
|
36
|
+
/** The end position (zero-based) of the recognized user's profile website. This end index is exclusive. */
|
|
37
|
+
end: number;
|
|
38
|
+
/** The URL in the format entered by the user. */
|
|
39
|
+
url: string;
|
|
40
|
+
/** The fully resolved URL. */
|
|
41
|
+
expanded_url: string;
|
|
42
|
+
/** The URL as displayed in the user's profile. */
|
|
32
43
|
display_url: string;
|
|
33
44
|
}>;
|
|
34
|
-
};
|
|
45
|
+
};
|
|
46
|
+
/** Contains details about URLs, Hashtags, Cashtags, or mentions located within a user's description. */
|
|
35
47
|
description: {
|
|
36
48
|
hashtags: Array<{
|
|
37
49
|
start: number;
|
|
@@ -57,7 +69,8 @@ interface TwitterProfile {
|
|
|
57
69
|
*
|
|
58
70
|
* To return this field, add `user.fields=url` in the authorization request's query parameter.
|
|
59
71
|
*/
|
|
60
|
-
url?: string | undefined;
|
|
72
|
+
url?: string | undefined;
|
|
73
|
+
/** The URL to the profile image for this user, as shown on the user's profile. */
|
|
61
74
|
profile_image_url?: string | undefined;
|
|
62
75
|
protected?: boolean | undefined;
|
|
63
76
|
/**
|
|
@@ -90,11 +103,7 @@ declare const twitter: (options: TwitterOption) => {
|
|
|
90
103
|
display?: string | undefined;
|
|
91
104
|
loginHint?: string | undefined;
|
|
92
105
|
}): Promise<URL>;
|
|
93
|
-
validateAuthorizationCode: ({
|
|
94
|
-
code,
|
|
95
|
-
codeVerifier,
|
|
96
|
-
redirectURI
|
|
97
|
-
}: {
|
|
106
|
+
validateAuthorizationCode: ({ code, codeVerifier, redirectURI }: {
|
|
98
107
|
code: string;
|
|
99
108
|
redirectURI: string;
|
|
100
109
|
codeVerifier?: string | undefined;
|
|
@@ -103,7 +112,7 @@ declare const twitter: (options: TwitterOption) => {
|
|
|
103
112
|
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
104
113
|
getUserInfo(token: OAuth2Tokens & {
|
|
105
114
|
user?: {
|
|
106
|
-
name
|
|
115
|
+
name?: {
|
|
107
116
|
firstName?: string;
|
|
108
117
|
lastName?: string;
|
|
109
118
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
2
3
|
//#region src/social-providers/vercel.d.ts
|
|
3
4
|
interface VercelProfile {
|
|
4
5
|
sub: string;
|
|
@@ -14,12 +15,7 @@ interface VercelOptions extends ProviderOptions<VercelProfile> {
|
|
|
14
15
|
declare const vercel: (options: VercelOptions) => {
|
|
15
16
|
id: "vercel";
|
|
16
17
|
name: string;
|
|
17
|
-
createAuthorizationURL({
|
|
18
|
-
state,
|
|
19
|
-
scopes,
|
|
20
|
-
codeVerifier,
|
|
21
|
-
redirectURI
|
|
22
|
-
}: {
|
|
18
|
+
createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }: {
|
|
23
19
|
state: string;
|
|
24
20
|
codeVerifier: string;
|
|
25
21
|
scopes?: string[] | undefined;
|
|
@@ -27,11 +23,7 @@ declare const vercel: (options: VercelOptions) => {
|
|
|
27
23
|
display?: string | undefined;
|
|
28
24
|
loginHint?: string | undefined;
|
|
29
25
|
}): Promise<URL>;
|
|
30
|
-
validateAuthorizationCode: ({
|
|
31
|
-
code,
|
|
32
|
-
codeVerifier,
|
|
33
|
-
redirectURI
|
|
34
|
-
}: {
|
|
26
|
+
validateAuthorizationCode: ({ code, codeVerifier, redirectURI }: {
|
|
35
27
|
code: string;
|
|
36
28
|
redirectURI: string;
|
|
37
29
|
codeVerifier?: string | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
2
3
|
//#region src/social-providers/vk.d.ts
|
|
3
4
|
interface VkProfile {
|
|
4
5
|
user: {
|
|
@@ -20,12 +21,7 @@ interface VkOption extends ProviderOptions {
|
|
|
20
21
|
declare const vk: (options: VkOption) => {
|
|
21
22
|
id: "vk";
|
|
22
23
|
name: string;
|
|
23
|
-
createAuthorizationURL({
|
|
24
|
-
state,
|
|
25
|
-
scopes,
|
|
26
|
-
codeVerifier,
|
|
27
|
-
redirectURI
|
|
28
|
-
}: {
|
|
24
|
+
createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }: {
|
|
29
25
|
state: string;
|
|
30
26
|
codeVerifier: string;
|
|
31
27
|
scopes?: string[] | undefined;
|
|
@@ -33,12 +29,7 @@ declare const vk: (options: VkOption) => {
|
|
|
33
29
|
display?: string | undefined;
|
|
34
30
|
loginHint?: string | undefined;
|
|
35
31
|
}): Promise<URL>;
|
|
36
|
-
validateAuthorizationCode: ({
|
|
37
|
-
code,
|
|
38
|
-
codeVerifier,
|
|
39
|
-
redirectURI,
|
|
40
|
-
deviceId
|
|
41
|
-
}: {
|
|
32
|
+
validateAuthorizationCode: ({ code, codeVerifier, redirectURI, deviceId }: {
|
|
42
33
|
code: string;
|
|
43
34
|
redirectURI: string;
|
|
44
35
|
codeVerifier?: string | undefined;
|
|
@@ -46,14 +46,13 @@ const vk = (options) => {
|
|
|
46
46
|
async getUserInfo(data) {
|
|
47
47
|
if (options.getUserInfo) return options.getUserInfo(data);
|
|
48
48
|
if (!data.accessToken) return null;
|
|
49
|
-
const formBody = new URLSearchParams({
|
|
50
|
-
access_token: data.accessToken,
|
|
51
|
-
client_id: options.clientId
|
|
52
|
-
}).toString();
|
|
53
49
|
const { data: profile, error } = await betterFetch("https://id.vk.com/oauth2/user_info", {
|
|
54
50
|
method: "POST",
|
|
55
51
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
56
|
-
body:
|
|
52
|
+
body: new URLSearchParams({
|
|
53
|
+
access_token: data.accessToken,
|
|
54
|
+
client_id: options.clientId
|
|
55
|
+
}).toString()
|
|
57
56
|
});
|
|
58
57
|
if (error) return null;
|
|
59
58
|
const userMap = await options.mapProfileToUser?.(profile);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
2
3
|
//#region src/social-providers/wechat.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* WeChat user profile information
|
|
@@ -53,11 +54,7 @@ interface WeChatOptions extends ProviderOptions<WeChatProfile> {
|
|
|
53
54
|
declare const wechat: (options: WeChatOptions) => {
|
|
54
55
|
id: "wechat";
|
|
55
56
|
name: string;
|
|
56
|
-
createAuthorizationURL({
|
|
57
|
-
state,
|
|
58
|
-
scopes,
|
|
59
|
-
redirectURI
|
|
60
|
-
}: {
|
|
57
|
+
createAuthorizationURL({ state, scopes, redirectURI }: {
|
|
61
58
|
state: string;
|
|
62
59
|
codeVerifier: string;
|
|
63
60
|
scopes?: string[] | undefined;
|
|
@@ -65,9 +62,7 @@ declare const wechat: (options: WeChatOptions) => {
|
|
|
65
62
|
display?: string | undefined;
|
|
66
63
|
loginHint?: string | undefined;
|
|
67
64
|
}): URL;
|
|
68
|
-
validateAuthorizationCode: ({
|
|
69
|
-
code
|
|
70
|
-
}: {
|
|
65
|
+
validateAuthorizationCode: ({ code }: {
|
|
71
66
|
code: string;
|
|
72
67
|
redirectURI: string;
|
|
73
68
|
codeVerifier?: string | undefined;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
2
3
|
//#region src/social-providers/zoom.d.ts
|
|
3
|
-
type LoginType = 0 /** Facebook OAuth */ |
|
|
4
|
-
/** Single Sign-On (SSO) */
|
|
4
|
+
type LoginType = 0 | /** Facebook OAuth */ 1 | /** Google OAuth */ 24 | /** Apple OAuth */ 27 | /** Microsoft OAuth */ 97 | /** Mobile device */ 98 | /** RingCentral OAuth */ 99 | /** API user */ 100 | /** Zoom Work email */ 101; /** Single Sign-On (SSO) */
|
|
5
5
|
type AccountStatus = "pending" | "active" | "inactive";
|
|
6
|
-
type PronounOption = 1 /** Ask the user every time */ |
|
|
7
|
-
/** Do not display */
|
|
6
|
+
type PronounOption = 1 | /** Ask the user every time */ 2 | /** Always display */ 3; /** Do not display */
|
|
8
7
|
interface PhoneNumber {
|
|
9
8
|
/** The country code of the phone number (Example: "+1") */
|
|
10
9
|
code: string;
|
|
@@ -116,11 +115,7 @@ interface ZoomOptions extends ProviderOptions<ZoomProfile> {
|
|
|
116
115
|
declare const zoom: (userOptions: ZoomOptions) => {
|
|
117
116
|
id: "zoom";
|
|
118
117
|
name: string;
|
|
119
|
-
createAuthorizationURL: ({
|
|
120
|
-
state,
|
|
121
|
-
redirectURI,
|
|
122
|
-
codeVerifier
|
|
123
|
-
}: {
|
|
118
|
+
createAuthorizationURL: ({ state, redirectURI, codeVerifier }: {
|
|
124
119
|
state: string;
|
|
125
120
|
codeVerifier: string;
|
|
126
121
|
scopes?: string[] | undefined;
|
|
@@ -128,11 +123,7 @@ declare const zoom: (userOptions: ZoomOptions) => {
|
|
|
128
123
|
display?: string | undefined;
|
|
129
124
|
loginHint?: string | undefined;
|
|
130
125
|
}) => Promise<URL>;
|
|
131
|
-
validateAuthorizationCode: ({
|
|
132
|
-
code,
|
|
133
|
-
redirectURI,
|
|
134
|
-
codeVerifier
|
|
135
|
-
}: {
|
|
126
|
+
validateAuthorizationCode: ({ code, redirectURI, codeVerifier }: {
|
|
136
127
|
code: string;
|
|
137
128
|
redirectURI: string;
|
|
138
129
|
codeVerifier?: string | undefined;
|
package/dist/types/context.d.mts
CHANGED
|
@@ -8,11 +8,12 @@ import { Awaitable, LiteralString } from "./helper.mjs";
|
|
|
8
8
|
import { BetterAuthPlugin } from "./plugin.mjs";
|
|
9
9
|
import { BetterAuthOptions, BetterAuthRateLimitOptions } from "./init-options.mjs";
|
|
10
10
|
import { Account } from "../db/schema/account.mjs";
|
|
11
|
+
import "../db/index.mjs";
|
|
11
12
|
import { BetterAuthCookie, BetterAuthCookies } from "./cookie.mjs";
|
|
12
13
|
import { SecretConfig } from "./secret.mjs";
|
|
13
14
|
import { OAuthProvider } from "../oauth2/oauth-provider.mjs";
|
|
15
|
+
import "../oauth2/index.mjs";
|
|
14
16
|
import { CookieOptions, EndpointContext } from "better-call";
|
|
15
|
-
|
|
16
17
|
//#region src/types/context.d.ts
|
|
17
18
|
/**
|
|
18
19
|
* @internal
|
package/dist/types/cookie.d.mts
CHANGED
package/dist/types/helper.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ type Awaitable<T> = T | Promise<T>;
|
|
|
4
4
|
type AwaitableFunction<T> = T | (() => Awaitable<T>);
|
|
5
5
|
type LiteralString = "" | (string & Record<never, never>);
|
|
6
6
|
type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
7
|
-
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
7
|
+
type Prettify<T> = { [K in keyof T]: T[K]; } & {};
|
|
8
8
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
9
9
|
//#endregion
|
|
10
10
|
export { Awaitable, AwaitableFunction, LiteralString, LiteralUnion, Prettify, Primitive, UnionToIntersection };
|
package/dist/types/index.d.mts
CHANGED
|
@@ -6,4 +6,4 @@ import { SecretConfig } from "./secret.mjs";
|
|
|
6
6
|
import { AuthContext, BetterAuthPluginRegistry, BetterAuthPluginRegistryIdentifier, GenericEndpointContext, InfoContext, InternalAdapter, PluginContext } from "./context.mjs";
|
|
7
7
|
import { BetterAuthClientOptions, BetterAuthClientPlugin, ClientAtomListener, ClientFetchOption, ClientStore } from "./plugin-client.mjs";
|
|
8
8
|
import { StandardSchemaV1 as StandardSchemaV1$1 } from "@standard-schema/spec";
|
|
9
|
-
export {
|
|
9
|
+
export type { AuthContext, Awaitable, AwaitableFunction, BaseURLConfig, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookie, BetterAuthCookies, BetterAuthDBOptions, BetterAuthOptions, BetterAuthPlugin, BetterAuthPluginErrorCodePart, BetterAuthPluginRegistry, BetterAuthPluginRegistryIdentifier, BetterAuthRateLimitOptions, BetterAuthRateLimitRule, BetterAuthRateLimitStorage, ClientAtomListener, ClientFetchOption, ClientStore, DynamicBaseURLConfig, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InfoContext, InternalAdapter, LiteralString, LiteralUnion, PluginContext, Prettify, Primitive, SecretConfig, StandardSchemaV1$1 as StandardSchemaV1, StoreIdentifierOption, UnionToIntersection };
|
|
@@ -9,6 +9,7 @@ import { SocialProviderList, SocialProviders } from "../social-providers/index.m
|
|
|
9
9
|
import { Awaitable, LiteralString, LiteralUnion } from "./helper.mjs";
|
|
10
10
|
import { BetterAuthPlugin } from "./plugin.mjs";
|
|
11
11
|
import { Account, BaseAccount } from "../db/schema/account.mjs";
|
|
12
|
+
import "../db/index.mjs";
|
|
12
13
|
import { AuthContext, GenericEndpointContext } from "./context.mjs";
|
|
13
14
|
import { AuthMiddleware } from "../api/index.mjs";
|
|
14
15
|
import { CookieOptions } from "better-call";
|
|
@@ -16,10 +17,9 @@ import { Database } from "bun:sqlite";
|
|
|
16
17
|
import { DatabaseSync } from "node:sqlite";
|
|
17
18
|
import { D1Database } from "@cloudflare/workers-types";
|
|
18
19
|
import { Dialect, Kysely, MysqlPool, PostgresPool, SqliteDatabase } from "kysely";
|
|
19
|
-
|
|
20
20
|
//#region src/types/init-options.d.ts
|
|
21
21
|
type KyselyDatabaseType = "postgres" | "mysql" | "sqlite" | "mssql";
|
|
22
|
-
type Optional<T> = { [P in keyof T]?: T[P] | undefined };
|
|
22
|
+
type Optional<T> = { [P in keyof T]?: T[P] | undefined; };
|
|
23
23
|
type StoreIdentifierOption = "plain" | "hashed" | {
|
|
24
24
|
hash: (identifier: string) => Promise<string>;
|
|
25
25
|
};
|
|
@@ -130,7 +130,7 @@ type BetterAuthDBOptions<ModelName extends string, Keys extends string = string>
|
|
|
130
130
|
/**
|
|
131
131
|
* Additional fields for the model
|
|
132
132
|
*/
|
|
133
|
-
additionalFields?: { [Key in Exclude<string, Keys | "id">]: DBFieldAttribute };
|
|
133
|
+
additionalFields?: { [Key in Exclude<string, Keys | "id">]: DBFieldAttribute; };
|
|
134
134
|
};
|
|
135
135
|
type BetterAuthRateLimitOptions = Optional<BetterAuthRateLimitRule> & Omit<BetterAuthDBOptions<"rateLimit", keyof BaseRateLimit>, "additionalFields"> & {
|
|
136
136
|
/**
|
|
@@ -314,7 +314,7 @@ type BetterAuthAdvancedOptions = {
|
|
|
314
314
|
/**
|
|
315
315
|
* Trusted proxy headers
|
|
316
316
|
*
|
|
317
|
-
|
|
317
|
+
* - `x-forwarded-host`
|
|
318
318
|
* - `x-forwarded-proto`
|
|
319
319
|
*
|
|
320
320
|
* If set to `true` and no `baseURL` option is provided, we will use the headers to infer the
|
|
@@ -704,15 +704,18 @@ type BetterAuthOptions = {
|
|
|
704
704
|
* ```
|
|
705
705
|
*/
|
|
706
706
|
customSyntheticUser?: (params: {
|
|
707
|
-
/** Core user fields: name, email, emailVerified, image, createdAt, updatedAt */
|
|
707
|
+
/** Core user fields: name, email, emailVerified, image, createdAt, updatedAt */
|
|
708
|
+
coreFields: {
|
|
708
709
|
name: string;
|
|
709
710
|
email: string;
|
|
710
711
|
emailVerified: boolean;
|
|
711
712
|
image: string | null;
|
|
712
713
|
createdAt: Date;
|
|
713
714
|
updatedAt: Date;
|
|
714
|
-
};
|
|
715
|
-
|
|
715
|
+
};
|
|
716
|
+
/** Processed additional fields from options.user.additionalFields (with defaults applied) */
|
|
717
|
+
additionalFields: Record<string, unknown>;
|
|
718
|
+
/** Generated user ID */
|
|
716
719
|
id: string;
|
|
717
720
|
}) => Record<string, unknown>;
|
|
718
721
|
} | undefined;
|
|
@@ -2,7 +2,6 @@ import { LiteralString } from "./helper.mjs";
|
|
|
2
2
|
import { BetterAuthOptions } from "./init-options.mjs";
|
|
3
3
|
import { BetterFetch, BetterFetchOption, BetterFetchPlugin } from "@better-fetch/fetch";
|
|
4
4
|
import { Atom, WritableAtom } from "nanostores";
|
|
5
|
-
|
|
6
5
|
//#region src/types/plugin-client.d.ts
|
|
7
6
|
type InferableServerPlugin = {
|
|
8
7
|
id?: LiteralString | undefined;
|
|
@@ -89,7 +88,6 @@ interface BetterAuthClientPlugin {
|
|
|
89
88
|
/**
|
|
90
89
|
* better-auth client options
|
|
91
90
|
*/
|
|
92
|
-
|
|
93
91
|
options: BetterAuthClientOptions | undefined) => Record<string, any>;
|
|
94
92
|
/**
|
|
95
93
|
* State atoms that'll be resolved by each framework
|
|
@@ -120,4 +118,4 @@ interface BetterAuthClientPlugin {
|
|
|
120
118
|
}>;
|
|
121
119
|
}
|
|
122
120
|
//#endregion
|
|
123
|
-
export { BetterAuthClientOptions, BetterAuthClientPlugin, ClientAtomListener, ClientFetchOption, ClientStore };
|
|
121
|
+
export { BetterAuthClientOptions, BetterAuthClientPlugin, ClientAtomListener, ClientFetchOption, ClientStore, RevalidateOptions };
|
package/dist/types/plugin.d.mts
CHANGED
|
@@ -2,13 +2,13 @@ import { BetterAuthPluginDBSchema } from "../db/plugin.mjs";
|
|
|
2
2
|
import { Awaitable, LiteralString } from "./helper.mjs";
|
|
3
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";
|
|
8
9
|
import { Migration } from "kysely";
|
|
9
|
-
|
|
10
10
|
//#region src/types/plugin.d.ts
|
|
11
|
-
type DeepPartial<T> = T extends Function ? T : T extends object ? { [K in keyof T]?: DeepPartial<T[K]
|
|
11
|
+
type DeepPartial<T> = T extends Function ? T : T extends object ? { [K in keyof T]?: DeepPartial<T[K]>; } : T;
|
|
12
12
|
type HookEndpointContext = Partial<EndpointContext<string, any> & Omit<InputContext<string, any>, "method">> & {
|
|
13
13
|
path?: string;
|
|
14
14
|
context: AuthContext & {
|
package/dist/utils/async.d.mts
CHANGED
package/dist/utils/db.d.mts
CHANGED
|
@@ -3,11 +3,11 @@ type UpperLetter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "
|
|
|
3
3
|
type SpecialCharacter = "_";
|
|
4
4
|
type IsValidUpperSnakeCase<S extends string> = S extends `${infer F}${infer R}` ? F extends UpperLetter | SpecialCharacter ? IsValidUpperSnakeCase<R> : false : true;
|
|
5
5
|
type InvalidKeyError<K extends string> = `Invalid error code key: "${K}" - must only contain uppercase letters (A-Z) and underscores (_)`;
|
|
6
|
-
type ValidateErrorCodes<T> = { [K in keyof T]: K extends string ? IsValidUpperSnakeCase<K> extends false ? InvalidKeyError<K> : T[K] : T[K] };
|
|
6
|
+
type ValidateErrorCodes<T> = { [K in keyof T]: K extends string ? IsValidUpperSnakeCase<K> extends false ? InvalidKeyError<K> : T[K] : T[K]; };
|
|
7
7
|
type RawError<K extends string = string> = {
|
|
8
8
|
readonly code: K;
|
|
9
9
|
message: string;
|
|
10
10
|
};
|
|
11
|
-
declare function defineErrorCodes<const T extends Record<string, string>, R extends { [K in keyof T & string]: RawError<K
|
|
11
|
+
declare function defineErrorCodes<const T extends Record<string, string>, R extends { [K in keyof T & string]: RawError<K>; }>(codes: ValidateErrorCodes<T>): R;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { RawError, defineErrorCodes };
|
package/dist/utils/host.d.mts
CHANGED
|
@@ -26,7 +26,33 @@
|
|
|
26
26
|
* The semantic kind of a host, derived from RFC 6890 special-purpose registries
|
|
27
27
|
* plus a few domain-name categories (localhost, cloud metadata FQDNs).
|
|
28
28
|
*/
|
|
29
|
-
type HostKind =
|
|
29
|
+
type HostKind =
|
|
30
|
+
/** IPv4 `127.0.0.0/8` or IPv6 `::1`. */
|
|
31
|
+
"loopback" |
|
|
32
|
+
/** DNS name `localhost` or RFC 6761 `.localhost` TLD. */
|
|
33
|
+
"localhost" |
|
|
34
|
+
/** IPv4 `0.0.0.0` or IPv6 `::` — "this host on this network", not loopback. */
|
|
35
|
+
"unspecified" |
|
|
36
|
+
/** RFC 1918 `10/8`, `172.16/12`, `192.168/16`, or IPv6 ULA `fc00::/7`. */
|
|
37
|
+
"private" |
|
|
38
|
+
/** IPv4 `169.254/16` or IPv6 `fe80::/10`. Includes AWS IMDS `169.254.169.254`. */
|
|
39
|
+
"linkLocal" |
|
|
40
|
+
/** RFC 6598 carrier-grade NAT `100.64.0.0/10`. */
|
|
41
|
+
"sharedAddressSpace" |
|
|
42
|
+
/** RFC 5737 `192.0.2/24`, `198.51.100/24`, `203.0.113/24`, or RFC 3849 `2001:db8::/32`. */
|
|
43
|
+
"documentation" |
|
|
44
|
+
/** RFC 2544 `198.18.0.0/15`. */
|
|
45
|
+
"benchmarking" |
|
|
46
|
+
/** IPv4 `224.0.0.0/4` or IPv6 `ff00::/8`. */
|
|
47
|
+
"multicast" |
|
|
48
|
+
/** IPv4 limited broadcast `255.255.255.255`. */
|
|
49
|
+
"broadcast" |
|
|
50
|
+
/** Other RFC 6890 special-purpose ranges (0/8, 192.0.0/24, 240/4, 2001::/32, etc.). */
|
|
51
|
+
"reserved" |
|
|
52
|
+
/** Cloud metadata service FQDN (e.g. `metadata.google.internal`). */
|
|
53
|
+
"cloudMetadata" |
|
|
54
|
+
/** Any host not matching a special-purpose range above. */
|
|
55
|
+
"public";
|
|
30
56
|
/**
|
|
31
57
|
* The syntactic form of the input host: an IPv4 literal, an IPv6 literal, or
|
|
32
58
|
* a domain name. IPv4-mapped IPv6 (`::ffff:192.0.2.1`) is reported as `ipv4`
|
package/dist/utils/host.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { isValidIP, normalizeIP } from "./ip.mjs";
|
|
|
9
9
|
* only exists for the FQDN form that a naive server-side fetch might resolve
|
|
10
10
|
* via its own resolver.
|
|
11
11
|
*/
|
|
12
|
-
const CLOUD_METADATA_HOSTS = new Set([
|
|
12
|
+
const CLOUD_METADATA_HOSTS = /* @__PURE__ */ new Set([
|
|
13
13
|
"metadata.google.internal",
|
|
14
14
|
"metadata.goog",
|
|
15
15
|
"metadata",
|
package/dist/utils/ip.d.mts
CHANGED
package/dist/utils/ip.mjs
CHANGED
|
@@ -111,7 +111,7 @@ function ipToBytes(ip) {
|
|
|
111
111
|
const mapped = extractIPv4FromMapped(ip);
|
|
112
112
|
if (mapped) return Uint8Array.from(mapped.split(".").map((octet) => Number(octet)));
|
|
113
113
|
const groups = expandIPv6(ip);
|
|
114
|
-
const bytes = new Uint8Array(16);
|
|
114
|
+
const bytes = /* @__PURE__ */ new Uint8Array(16);
|
|
115
115
|
for (let i = 0; i < 8; i++) {
|
|
116
116
|
const group = Number.parseInt(groups[i] ?? "0", 16);
|
|
117
117
|
bytes[i * 2] = group >> 8 & 255;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/core",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.25",
|
|
4
4
|
"description": "The most comprehensive authentication framework for TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -162,7 +162,7 @@
|
|
|
162
162
|
"jose": "^6.1.3",
|
|
163
163
|
"kysely": "^0.28.17 || ^0.29.0",
|
|
164
164
|
"nanostores": "^1.1.1",
|
|
165
|
-
"tsdown": "0.
|
|
165
|
+
"tsdown": "0.22.7"
|
|
166
166
|
},
|
|
167
167
|
"peerDependencies": {
|
|
168
168
|
"@better-auth/utils": "0.4.2",
|
|
@@ -4,15 +4,35 @@ import { __getBetterAuthGlobal } from "./global";
|
|
|
4
4
|
|
|
5
5
|
export type RequestStateWeakMap = WeakMap<object, any>;
|
|
6
6
|
|
|
7
|
+
// Memoizes the in-flight AsyncLocalStorage initialization so concurrent
|
|
8
|
+
// first-callers share a single instance instead of each constructing one.
|
|
9
|
+
let asyncStorageInit: Promise<AsyncLocalStorage<RequestStateWeakMap>> | null =
|
|
10
|
+
null;
|
|
11
|
+
|
|
7
12
|
const ensureAsyncStorage = async () => {
|
|
8
13
|
const betterAuthGlobal = __getBetterAuthGlobal();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
const existing = betterAuthGlobal.context.requestStateAsyncStorage;
|
|
15
|
+
if (existing) {
|
|
16
|
+
return existing as AsyncLocalStorage<RequestStateWeakMap>;
|
|
17
|
+
}
|
|
18
|
+
// Without memoizing the init, several concurrent callers can each pass the
|
|
19
|
+
// check above, each `await getAsyncLocalStorage()`, and each assign a fresh
|
|
20
|
+
// instance — last write wins. `runWithRequestState().run()` then executes on
|
|
21
|
+
// one instance while a nested `getCurrentRequestState()` reads the
|
|
22
|
+
// overwritten one, throwing "No request state found". This shows up
|
|
23
|
+
// intermittently on serverless cold start (e.g. Cloudflare Workers), where
|
|
24
|
+
// the first requests hit before the lazy `node:async_hooks` import settles.
|
|
25
|
+
// The idempotent `??=` keeps the global singleton stable even if multiple
|
|
26
|
+
// BetterAuth copies (Dual Module Hazard) race here.
|
|
27
|
+
if (!asyncStorageInit) {
|
|
28
|
+
asyncStorageInit = getAsyncLocalStorage().then((AsyncLocalStorage) => {
|
|
29
|
+
betterAuthGlobal.context.requestStateAsyncStorage ??=
|
|
30
|
+
new AsyncLocalStorage<RequestStateWeakMap>();
|
|
31
|
+
return betterAuthGlobal.context
|
|
32
|
+
.requestStateAsyncStorage as AsyncLocalStorage<RequestStateWeakMap>;
|
|
33
|
+
});
|
|
13
34
|
}
|
|
14
|
-
return
|
|
15
|
-
.requestStateAsyncStorage as AsyncLocalStorage<RequestStateWeakMap>;
|
|
35
|
+
return asyncStorageInit;
|
|
16
36
|
};
|
|
17
37
|
|
|
18
38
|
export async function getRequestStateAsyncLocalStorage() {
|