@better-auth/core 1.6.26 → 1.6.28
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 +37 -36
- package/dist/api/index.mjs +15 -19
- package/dist/async_hooks/index.d.mts +1 -0
- package/dist/async_hooks/pure.index.d.mts +1 -0
- package/dist/context/endpoint-context.d.mts +1 -1
- package/dist/context/global.d.mts +1 -0
- package/dist/context/global.mjs +1 -1
- package/dist/context/request-state.d.mts +1 -0
- package/dist/context/transaction.d.mts +1 -1
- package/dist/db/adapter/factory.d.mts +5 -3
- package/dist/db/adapter/factory.mjs +2 -2
- package/dist/db/adapter/get-default-field-name.d.mts +9 -2
- package/dist/db/adapter/get-default-model-name.d.mts +5 -1
- package/dist/db/adapter/get-field-attributes.d.mts +11 -4
- package/dist/db/adapter/get-field-name.d.mts +9 -2
- package/dist/db/adapter/get-id-field.d.mts +12 -4
- package/dist/db/adapter/get-model-name.d.mts +5 -1
- package/dist/db/adapter/index.d.mts +32 -7
- package/dist/db/adapter/types.d.mts +17 -5
- package/dist/db/adapter/utils.d.mts +1 -0
- package/dist/db/get-tables.d.mts +0 -1
- package/dist/db/plugin.d.mts +2 -1
- package/dist/db/schema/account.d.mts +1 -1
- package/dist/db/schema/rate-limit.d.mts +1 -1
- package/dist/db/schema/session.d.mts +1 -1
- package/dist/db/schema/shared.d.mts +1 -0
- package/dist/db/schema/user.d.mts +1 -1
- package/dist/db/schema/verification.d.mts +1 -1
- package/dist/db/type.d.mts +10 -6
- package/dist/env/logger.d.mts +25 -25
- package/dist/error/codes.d.mts +1 -0
- package/dist/error/index.d.mts +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/instrumentation/attributes.d.mts +1 -0
- package/dist/instrumentation/pure.index.d.mts +1 -0
- package/dist/instrumentation/tracer.mjs +1 -1
- package/dist/oauth2/client-credentials-token.d.mts +20 -4
- package/dist/oauth2/create-authorization-url.d.mts +20 -3
- package/dist/oauth2/oauth-provider.d.mts +0 -1
- package/dist/oauth2/refresh-access-token.d.mts +22 -4
- package/dist/oauth2/reject-redirects.mjs +1 -1
- package/dist/oauth2/utils.d.mts +1 -0
- package/dist/oauth2/validate-authorization-code.d.mts +37 -6
- package/dist/oauth2/verify.d.mts +10 -12
- package/dist/oauth2/verify.mjs +2 -2
- package/dist/social-providers/apple.d.mts +11 -4
- package/dist/social-providers/atlassian.d.mts +11 -3
- package/dist/social-providers/cognito.d.mts +11 -4
- package/dist/social-providers/discord.d.mts +9 -3
- package/dist/social-providers/dropbox.d.mts +11 -3
- package/dist/social-providers/facebook.d.mts +10 -4
- package/dist/social-providers/figma.d.mts +11 -3
- package/dist/social-providers/github.d.mts +12 -3
- package/dist/social-providers/gitlab.d.mts +12 -3
- package/dist/social-providers/google.d.mts +19 -5
- package/dist/social-providers/huggingface.d.mts +11 -3
- package/dist/social-providers/index.d.mts +364 -78
- package/dist/social-providers/kakao.d.mts +9 -3
- package/dist/social-providers/kick.d.mts +11 -3
- package/dist/social-providers/line.d.mts +12 -4
- package/dist/social-providers/linear.d.mts +10 -3
- package/dist/social-providers/linkedin.d.mts +10 -3
- package/dist/social-providers/microsoft-entra-id.d.mts +5 -3
- package/dist/social-providers/microsoft-entra-id.mjs +1 -2
- package/dist/social-providers/naver.d.mts +18 -22
- package/dist/social-providers/notion.d.mts +10 -3
- package/dist/social-providers/paybin.d.mts +12 -3
- package/dist/social-providers/paypal.d.mts +9 -4
- package/dist/social-providers/polar.d.mts +11 -3
- package/dist/social-providers/railway.d.mts +11 -3
- package/dist/social-providers/reddit.d.mts +9 -3
- package/dist/social-providers/roblox.d.mts +9 -3
- package/dist/social-providers/salesforce.d.mts +11 -3
- package/dist/social-providers/slack.d.mts +9 -3
- package/dist/social-providers/spotify.d.mts +11 -3
- package/dist/social-providers/tiktok.d.mts +10 -5
- package/dist/social-providers/twitch.d.mts +9 -3
- package/dist/social-providers/twitter.d.mts +16 -25
- package/dist/social-providers/vercel.d.mts +11 -3
- package/dist/social-providers/vk.d.mts +12 -3
- package/dist/social-providers/wechat.d.mts +8 -3
- package/dist/social-providers/zoom.d.mts +14 -5
- package/dist/types/context.d.mts +1 -2
- package/dist/types/cookie.d.mts +1 -0
- package/dist/types/helper.d.mts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/init-options.d.mts +7 -10
- package/dist/types/plugin-client.d.mts +3 -1
- package/dist/types/plugin.d.mts +2 -2
- package/dist/utils/async.d.mts +1 -0
- package/dist/utils/db.d.mts +0 -1
- package/dist/utils/deprecate.d.mts +1 -0
- package/dist/utils/email.d.mts +4 -1
- package/dist/utils/error-codes.d.mts +2 -2
- package/dist/utils/host.d.mts +1 -27
- package/dist/utils/host.mjs +1 -1
- package/dist/utils/ip.d.mts +0 -1
- package/dist/utils/ip.mjs +1 -1
- package/dist/utils/is-api-error.d.mts +1 -0
- package/dist/utils/redirect-uri.d.mts +1 -0
- package/package.json +4 -4
- package/src/api/index.ts +57 -51
- package/src/db/type.ts +2 -1
package/src/api/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
2
|
+
EndpointHandler,
|
|
3
3
|
EndpointOptions,
|
|
4
|
+
MiddlewareHandler,
|
|
4
5
|
StrictEndpoint,
|
|
5
6
|
} from "better-call";
|
|
6
7
|
import {
|
|
@@ -56,13 +57,37 @@ export const createAuthMiddleware = createMiddleware.create({
|
|
|
56
57
|
],
|
|
57
58
|
});
|
|
58
59
|
|
|
59
|
-
const
|
|
60
|
+
const createEndpointWithAuthContext = createEndpoint.create({
|
|
61
|
+
use: [optionsMiddleware],
|
|
62
|
+
});
|
|
60
63
|
|
|
61
|
-
type
|
|
64
|
+
type AuthEndpointHandler<
|
|
62
65
|
Path extends string,
|
|
63
66
|
Options extends EndpointOptions,
|
|
64
67
|
R,
|
|
65
|
-
> =
|
|
68
|
+
> = EndpointHandler<Path, Options, R, AuthContext>;
|
|
69
|
+
|
|
70
|
+
type PathlessAuthEndpointHandler<
|
|
71
|
+
Options extends EndpointOptions,
|
|
72
|
+
R,
|
|
73
|
+
> = AuthEndpointHandler<string, Options, R>;
|
|
74
|
+
|
|
75
|
+
function wrapEndpointHandler<
|
|
76
|
+
Path extends string,
|
|
77
|
+
Options extends EndpointOptions,
|
|
78
|
+
R,
|
|
79
|
+
>(
|
|
80
|
+
handler: AuthEndpointHandler<Path, Options, R>,
|
|
81
|
+
): AuthEndpointHandler<Path, Options, R> {
|
|
82
|
+
return async (context) => {
|
|
83
|
+
try {
|
|
84
|
+
return await runWithEndpointContext(context, () => handler(context));
|
|
85
|
+
} catch (error) {
|
|
86
|
+
attachResponseHeadersToAPIError(context.responseHeaders, error);
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
66
91
|
|
|
67
92
|
export function createAuthEndpoint<
|
|
68
93
|
Path extends string,
|
|
@@ -71,65 +96,42 @@ export function createAuthEndpoint<
|
|
|
71
96
|
>(
|
|
72
97
|
path: Path,
|
|
73
98
|
options: Options,
|
|
74
|
-
handler:
|
|
99
|
+
handler: AuthEndpointHandler<Path, Options, R>,
|
|
75
100
|
): StrictEndpoint<Path, Options, R>;
|
|
76
101
|
|
|
77
102
|
export function createAuthEndpoint<
|
|
78
|
-
|
|
103
|
+
InferredPath extends string,
|
|
79
104
|
Options extends EndpointOptions,
|
|
80
105
|
R,
|
|
81
106
|
>(
|
|
82
107
|
options: Options,
|
|
83
|
-
handler:
|
|
84
|
-
): StrictEndpoint<
|
|
108
|
+
handler: PathlessAuthEndpointHandler<Options, R>,
|
|
109
|
+
): StrictEndpoint<InferredPath, Options, R>;
|
|
85
110
|
|
|
86
111
|
export function createAuthEndpoint<
|
|
87
112
|
Path extends string,
|
|
88
|
-
|
|
113
|
+
Options extends EndpointOptions,
|
|
89
114
|
R,
|
|
90
115
|
>(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
116
|
+
...args:
|
|
117
|
+
| [
|
|
118
|
+
path: Path,
|
|
119
|
+
options: Options,
|
|
120
|
+
handler: AuthEndpointHandler<Path, Options, R>,
|
|
121
|
+
]
|
|
122
|
+
| [options: Options, handler: PathlessAuthEndpointHandler<Options, R>]
|
|
94
123
|
) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
typeof handlerOrOptions === "object"
|
|
99
|
-
? handlerOrOptions
|
|
100
|
-
: (pathOrOptions as Opts);
|
|
101
|
-
const handler: EndpointHandler<Path, Opts, R> =
|
|
102
|
-
typeof handlerOrOptions === "function" ? handlerOrOptions : handlerOrNever;
|
|
103
|
-
|
|
104
|
-
// todo: prettify the code, we want to call `runWithEndpointContext` to top level
|
|
105
|
-
const wrapped: EndpointHandler<Path, Opts, R> = async (ctx) => {
|
|
106
|
-
const runtimeCtx = ctx as unknown as { responseHeaders?: Headers };
|
|
107
|
-
try {
|
|
108
|
-
return await runWithEndpointContext(ctx as any, () => handler(ctx));
|
|
109
|
-
} catch (e) {
|
|
110
|
-
attachResponseHeadersToAPIError(runtimeCtx.responseHeaders, e);
|
|
111
|
-
throw e;
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
if (path) {
|
|
116
|
-
return createEndpoint(
|
|
124
|
+
if (args.length === 3) {
|
|
125
|
+
const [path, options, handler] = args;
|
|
126
|
+
return createEndpointWithAuthContext(
|
|
117
127
|
path,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
use: [...(options?.use || []), ...use],
|
|
121
|
-
},
|
|
122
|
-
wrapped,
|
|
128
|
+
options,
|
|
129
|
+
wrapEndpointHandler(handler),
|
|
123
130
|
);
|
|
124
131
|
}
|
|
125
132
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
...options,
|
|
129
|
-
use: [...(options?.use || []), ...use],
|
|
130
|
-
},
|
|
131
|
-
wrapped,
|
|
132
|
-
);
|
|
133
|
+
const [options, handler] = args;
|
|
134
|
+
return createEndpointWithAuthContext(options, wrapEndpointHandler(handler));
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
/**
|
|
@@ -168,18 +170,22 @@ function withServerOnly<Options extends EndpointOptions>(
|
|
|
168
170
|
* ```
|
|
169
171
|
*/
|
|
170
172
|
createAuthEndpoint.serverOnly = <
|
|
171
|
-
|
|
173
|
+
InferredPath extends string,
|
|
172
174
|
Options extends EndpointOptions,
|
|
173
175
|
R,
|
|
174
176
|
>(
|
|
175
177
|
options: Options,
|
|
176
|
-
handler:
|
|
177
|
-
): StrictEndpoint<
|
|
178
|
-
createAuthEndpoint
|
|
178
|
+
handler: PathlessAuthEndpointHandler<Options, R>,
|
|
179
|
+
): StrictEndpoint<InferredPath, Options, R> =>
|
|
180
|
+
createAuthEndpoint<InferredPath, Options, R>(
|
|
181
|
+
withServerOnly(options),
|
|
182
|
+
handler,
|
|
183
|
+
);
|
|
179
184
|
|
|
180
185
|
export type AuthEndpoint<
|
|
181
186
|
Path extends string,
|
|
182
187
|
Opts extends EndpointOptions,
|
|
183
188
|
R,
|
|
184
189
|
> = ReturnType<typeof createAuthEndpoint<Path, Opts, R>>;
|
|
185
|
-
|
|
190
|
+
|
|
191
|
+
export type AuthMiddleware = MiddlewareHandler;
|
package/src/db/type.ts
CHANGED
|
@@ -251,7 +251,8 @@ export type DBFieldAttributeConfig = {
|
|
|
251
251
|
*/
|
|
252
252
|
bigint?: boolean | undefined;
|
|
253
253
|
/**
|
|
254
|
-
* A
|
|
254
|
+
* A Standard Schema to validate the value. Works with any Standard Schema
|
|
255
|
+
* library, such as Zod, Valibot or ArkType.
|
|
255
256
|
*/
|
|
256
257
|
validator?:
|
|
257
258
|
| {
|