@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.
Files changed (103) hide show
  1. package/dist/api/index.d.mts +37 -36
  2. package/dist/api/index.mjs +15 -19
  3. package/dist/async_hooks/index.d.mts +1 -0
  4. package/dist/async_hooks/pure.index.d.mts +1 -0
  5. package/dist/context/endpoint-context.d.mts +1 -1
  6. package/dist/context/global.d.mts +1 -0
  7. package/dist/context/global.mjs +1 -1
  8. package/dist/context/request-state.d.mts +1 -0
  9. package/dist/context/transaction.d.mts +1 -1
  10. package/dist/db/adapter/factory.d.mts +5 -3
  11. package/dist/db/adapter/factory.mjs +2 -2
  12. package/dist/db/adapter/get-default-field-name.d.mts +9 -2
  13. package/dist/db/adapter/get-default-model-name.d.mts +5 -1
  14. package/dist/db/adapter/get-field-attributes.d.mts +11 -4
  15. package/dist/db/adapter/get-field-name.d.mts +9 -2
  16. package/dist/db/adapter/get-id-field.d.mts +12 -4
  17. package/dist/db/adapter/get-model-name.d.mts +5 -1
  18. package/dist/db/adapter/index.d.mts +32 -7
  19. package/dist/db/adapter/types.d.mts +17 -5
  20. package/dist/db/adapter/utils.d.mts +1 -0
  21. package/dist/db/get-tables.d.mts +0 -1
  22. package/dist/db/plugin.d.mts +2 -1
  23. package/dist/db/schema/account.d.mts +1 -1
  24. package/dist/db/schema/rate-limit.d.mts +1 -1
  25. package/dist/db/schema/session.d.mts +1 -1
  26. package/dist/db/schema/shared.d.mts +1 -0
  27. package/dist/db/schema/user.d.mts +1 -1
  28. package/dist/db/schema/verification.d.mts +1 -1
  29. package/dist/db/type.d.mts +10 -6
  30. package/dist/env/logger.d.mts +25 -25
  31. package/dist/error/codes.d.mts +1 -0
  32. package/dist/error/index.d.mts +1 -0
  33. package/dist/index.d.mts +1 -1
  34. package/dist/instrumentation/attributes.d.mts +1 -0
  35. package/dist/instrumentation/pure.index.d.mts +1 -0
  36. package/dist/instrumentation/tracer.mjs +1 -1
  37. package/dist/oauth2/client-credentials-token.d.mts +20 -4
  38. package/dist/oauth2/create-authorization-url.d.mts +20 -3
  39. package/dist/oauth2/oauth-provider.d.mts +0 -1
  40. package/dist/oauth2/refresh-access-token.d.mts +22 -4
  41. package/dist/oauth2/reject-redirects.mjs +1 -1
  42. package/dist/oauth2/utils.d.mts +1 -0
  43. package/dist/oauth2/validate-authorization-code.d.mts +37 -6
  44. package/dist/oauth2/verify.d.mts +10 -12
  45. package/dist/oauth2/verify.mjs +2 -2
  46. package/dist/social-providers/apple.d.mts +11 -4
  47. package/dist/social-providers/atlassian.d.mts +11 -3
  48. package/dist/social-providers/cognito.d.mts +11 -4
  49. package/dist/social-providers/discord.d.mts +9 -3
  50. package/dist/social-providers/dropbox.d.mts +11 -3
  51. package/dist/social-providers/facebook.d.mts +10 -4
  52. package/dist/social-providers/figma.d.mts +11 -3
  53. package/dist/social-providers/github.d.mts +12 -3
  54. package/dist/social-providers/gitlab.d.mts +12 -3
  55. package/dist/social-providers/google.d.mts +19 -5
  56. package/dist/social-providers/huggingface.d.mts +11 -3
  57. package/dist/social-providers/index.d.mts +364 -78
  58. package/dist/social-providers/kakao.d.mts +9 -3
  59. package/dist/social-providers/kick.d.mts +11 -3
  60. package/dist/social-providers/line.d.mts +12 -4
  61. package/dist/social-providers/linear.d.mts +10 -3
  62. package/dist/social-providers/linkedin.d.mts +10 -3
  63. package/dist/social-providers/microsoft-entra-id.d.mts +5 -3
  64. package/dist/social-providers/microsoft-entra-id.mjs +1 -2
  65. package/dist/social-providers/naver.d.mts +18 -22
  66. package/dist/social-providers/notion.d.mts +10 -3
  67. package/dist/social-providers/paybin.d.mts +12 -3
  68. package/dist/social-providers/paypal.d.mts +9 -4
  69. package/dist/social-providers/polar.d.mts +11 -3
  70. package/dist/social-providers/railway.d.mts +11 -3
  71. package/dist/social-providers/reddit.d.mts +9 -3
  72. package/dist/social-providers/roblox.d.mts +9 -3
  73. package/dist/social-providers/salesforce.d.mts +11 -3
  74. package/dist/social-providers/slack.d.mts +9 -3
  75. package/dist/social-providers/spotify.d.mts +11 -3
  76. package/dist/social-providers/tiktok.d.mts +10 -5
  77. package/dist/social-providers/twitch.d.mts +9 -3
  78. package/dist/social-providers/twitter.d.mts +16 -25
  79. package/dist/social-providers/vercel.d.mts +11 -3
  80. package/dist/social-providers/vk.d.mts +12 -3
  81. package/dist/social-providers/wechat.d.mts +8 -3
  82. package/dist/social-providers/zoom.d.mts +14 -5
  83. package/dist/types/context.d.mts +1 -2
  84. package/dist/types/cookie.d.mts +1 -0
  85. package/dist/types/helper.d.mts +1 -1
  86. package/dist/types/index.d.mts +1 -1
  87. package/dist/types/init-options.d.mts +7 -10
  88. package/dist/types/plugin-client.d.mts +3 -1
  89. package/dist/types/plugin.d.mts +2 -2
  90. package/dist/utils/async.d.mts +1 -0
  91. package/dist/utils/db.d.mts +0 -1
  92. package/dist/utils/deprecate.d.mts +1 -0
  93. package/dist/utils/email.d.mts +4 -1
  94. package/dist/utils/error-codes.d.mts +2 -2
  95. package/dist/utils/host.d.mts +1 -27
  96. package/dist/utils/host.mjs +1 -1
  97. package/dist/utils/ip.d.mts +0 -1
  98. package/dist/utils/ip.mjs +1 -1
  99. package/dist/utils/is-api-error.d.mts +1 -0
  100. package/dist/utils/redirect-uri.d.mts +1 -0
  101. package/package.json +4 -4
  102. package/src/api/index.ts +57 -51
  103. package/src/db/type.ts +2 -1
package/src/api/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type {
2
- EndpointContext,
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 use = [optionsMiddleware];
60
+ const createEndpointWithAuthContext = createEndpoint.create({
61
+ use: [optionsMiddleware],
62
+ });
60
63
 
61
- type EndpointHandler<
64
+ type AuthEndpointHandler<
62
65
  Path extends string,
63
66
  Options extends EndpointOptions,
64
67
  R,
65
- > = (context: EndpointContext<Path, Options, AuthContext>) => Promise<R>;
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: EndpointHandler<Path, Options, R>,
99
+ handler: AuthEndpointHandler<Path, Options, R>,
75
100
  ): StrictEndpoint<Path, Options, R>;
76
101
 
77
102
  export function createAuthEndpoint<
78
- Path extends string,
103
+ InferredPath extends string,
79
104
  Options extends EndpointOptions,
80
105
  R,
81
106
  >(
82
107
  options: Options,
83
- handler: EndpointHandler<Path, Options, R>,
84
- ): StrictEndpoint<Path, Options, R>;
108
+ handler: PathlessAuthEndpointHandler<Options, R>,
109
+ ): StrictEndpoint<InferredPath, Options, R>;
85
110
 
86
111
  export function createAuthEndpoint<
87
112
  Path extends string,
88
- Opts extends EndpointOptions,
113
+ Options extends EndpointOptions,
89
114
  R,
90
115
  >(
91
- pathOrOptions: Path | Opts,
92
- handlerOrOptions: EndpointHandler<Path, Opts, R> | Opts,
93
- handlerOrNever?: any,
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
- const path: Path | undefined =
96
- typeof pathOrOptions === "string" ? pathOrOptions : undefined;
97
- const options: Opts =
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
- ...options,
120
- use: [...(options?.use || []), ...use],
121
- },
122
- wrapped,
128
+ options,
129
+ wrapEndpointHandler(handler),
123
130
  );
124
131
  }
125
132
 
126
- return createEndpoint(
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
- Path extends string,
173
+ InferredPath extends string,
172
174
  Options extends EndpointOptions,
173
175
  R,
174
176
  >(
175
177
  options: Options,
176
- handler: EndpointHandler<Path, Options, R>,
177
- ): StrictEndpoint<Path, Options, R> =>
178
- createAuthEndpoint(withServerOnly(options), handler);
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
- export type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;
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 zod schema to validate the value.
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
  | {