better-auth 1.8.0-beta.2 → 1.8.0-beta.4

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 (279) hide show
  1. package/dist/adapters/index.d.mts +5 -10
  2. package/dist/api/dispatch.d.mts +3 -5
  3. package/dist/api/dispatch.mjs +7 -5
  4. package/dist/api/index.d.mts +506 -508
  5. package/dist/api/index.mjs +35 -34
  6. package/dist/api/middlewares/authorization.d.mts +15 -12
  7. package/dist/api/middlewares/authorization.mjs +2 -1
  8. package/dist/api/middlewares/index.d.mts +2 -1
  9. package/dist/api/middlewares/origin-check.d.mts +4 -7
  10. package/dist/api/routes/account.d.mts +11 -15
  11. package/dist/api/routes/account.mjs +7 -4
  12. package/dist/api/routes/callback.d.mts +2 -5
  13. package/dist/api/routes/callback.mjs +4 -2
  14. package/dist/api/routes/email-verification.d.mts +7 -12
  15. package/dist/api/routes/error.d.mts +2 -5
  16. package/dist/api/routes/index.d.mts +2 -1
  17. package/dist/api/routes/ok.d.mts +2 -5
  18. package/dist/api/routes/password.d.mts +8 -11
  19. package/dist/api/routes/password.mjs +3 -2
  20. package/dist/api/routes/session.d.mts +26 -29
  21. package/dist/api/routes/sign-in.d.mts +4 -6
  22. package/dist/api/routes/sign-out.d.mts +2 -5
  23. package/dist/api/routes/sign-up.d.mts +4 -6
  24. package/dist/api/routes/update-session.d.mts +4 -6
  25. package/dist/api/routes/update-user.d.mts +14 -16
  26. package/dist/api/routes/update-user.mjs +1 -1
  27. package/dist/api/state/oauth.d.mts +0 -3
  28. package/dist/api/state/oauth.mjs +2 -1
  29. package/dist/auth/full.d.mts +3 -4
  30. package/dist/auth/minimal.d.mts +3 -3
  31. package/dist/client/broadcast-channel.d.mts +6 -7
  32. package/dist/client/config.d.mts +15 -19
  33. package/dist/client/config.mjs +2 -2
  34. package/dist/client/equality.d.mts +3 -5
  35. package/dist/client/focus-manager.d.mts +4 -5
  36. package/dist/client/index.d.mts +8 -7
  37. package/dist/client/lynx/index.d.mts +6 -7
  38. package/dist/client/lynx/index.mjs +3 -2
  39. package/dist/client/lynx/lynx-store.d.mts +3 -4
  40. package/dist/client/online-manager.d.mts +4 -5
  41. package/dist/client/parser.d.mts +9 -5
  42. package/dist/client/parser.mjs +1 -11
  43. package/dist/client/path-to-object.d.mts +13 -14
  44. package/dist/client/plugins/index.d.mts +1 -1
  45. package/dist/client/plugins/infer-plugin.d.mts +2 -4
  46. package/dist/client/query.d.mts +4 -6
  47. package/dist/client/react/index.d.mts +6 -7
  48. package/dist/client/react/index.mjs +3 -2
  49. package/dist/client/react/react-store.d.mts +3 -4
  50. package/dist/client/session-atom.d.mts +4 -4
  51. package/dist/client/session-refresh.d.mts +3 -5
  52. package/dist/client/solid/index.d.mts +6 -7
  53. package/dist/client/solid/index.mjs +3 -2
  54. package/dist/client/svelte/index.d.mts +6 -7
  55. package/dist/client/svelte/index.mjs +3 -2
  56. package/dist/client/types.d.mts +11 -11
  57. package/dist/client/vanilla.d.mts +4 -5
  58. package/dist/client/vanilla.mjs +3 -2
  59. package/dist/client/vue/index.d.mts +6 -7
  60. package/dist/client/vue/index.mjs +16 -9
  61. package/dist/context/create-context.mjs +7 -7
  62. package/dist/context/helpers.mjs +9 -7
  63. package/dist/context/secret-utils.mjs +3 -3
  64. package/dist/cookies/cookie-utils.d.mts +13 -13
  65. package/dist/cookies/cookie-utils.mjs +1 -3
  66. package/dist/cookies/index.d.mts +17 -18
  67. package/dist/cookies/index.mjs +11 -7
  68. package/dist/cookies/jwt.mjs +2 -1
  69. package/dist/cookies/session-store.d.mts +6 -5
  70. package/dist/cookies/session-store.mjs +3 -2
  71. package/dist/crypto/buffer.d.mts +2 -3
  72. package/dist/crypto/index.d.mts +9 -16
  73. package/dist/crypto/index.mjs +2 -1
  74. package/dist/crypto/jwt.d.mts +5 -7
  75. package/dist/crypto/jwt.mjs +2 -1
  76. package/dist/crypto/password.d.mts +1 -5
  77. package/dist/crypto/random.d.mts +2 -3
  78. package/dist/db/adapter-base.d.mts +2 -4
  79. package/dist/db/adapter-kysely.d.mts +2 -4
  80. package/dist/db/field-converter.d.mts +3 -5
  81. package/dist/db/field.d.mts +11 -12
  82. package/dist/db/get-migration.d.mts +4 -8
  83. package/dist/db/get-migration.mjs +22 -22
  84. package/dist/db/get-schema.d.mts +2 -4
  85. package/dist/db/internal-adapter.d.mts +2 -4
  86. package/dist/db/internal-adapter.mjs +6 -4
  87. package/dist/db/revoke-unproven-account-access.d.mts +3 -4
  88. package/dist/db/schema.d.mts +15 -16
  89. package/dist/db/schema.mjs +6 -3
  90. package/dist/db/to-zod.d.mts +5 -9
  91. package/dist/db/with-hooks.d.mts +3 -5
  92. package/dist/index.d.mts +4 -3
  93. package/dist/integrations/next-js.d.mts +7 -11
  94. package/dist/integrations/node.d.mts +5 -7
  95. package/dist/integrations/node.mjs +4 -2
  96. package/dist/integrations/solid-start.d.mts +2 -3
  97. package/dist/integrations/svelte-kit.d.mts +6 -14
  98. package/dist/integrations/tanstack-start-solid.d.mts +4 -8
  99. package/dist/integrations/tanstack-start.d.mts +4 -8
  100. package/dist/oauth2/link-account.d.mts +5 -11
  101. package/dist/oauth2/link-account.mjs +12 -6
  102. package/dist/oauth2/state.d.mts +5 -7
  103. package/dist/oauth2/state.mjs +1 -1
  104. package/dist/oauth2/utils.d.mts +4 -6
  105. package/dist/package.mjs +1 -1
  106. package/dist/plugins/access/access.d.mts +4 -6
  107. package/dist/plugins/access/index.mjs +1 -2
  108. package/dist/plugins/access/types.d.mts +12 -14
  109. package/dist/plugins/additional-fields/client.d.mts +2 -4
  110. package/dist/plugins/admin/access/index.mjs +1 -2
  111. package/dist/plugins/admin/access/statement.d.mts +7 -7
  112. package/dist/plugins/admin/admin.d.mts +124 -129
  113. package/dist/plugins/admin/admin.mjs +4 -4
  114. package/dist/plugins/admin/client.d.mts +33 -32
  115. package/dist/plugins/admin/client.mjs +1 -1
  116. package/dist/plugins/admin/error-codes.d.mts +26 -28
  117. package/dist/plugins/admin/error-codes.mjs +2 -1
  118. package/dist/plugins/admin/index.d.mts +1 -1
  119. package/dist/plugins/admin/index.mjs +1 -2
  120. package/dist/plugins/admin/routes.mjs +1 -0
  121. package/dist/plugins/admin/schema.d.mts +3 -4
  122. package/dist/plugins/admin/types.d.mts +8 -8
  123. package/dist/plugins/anonymous/client.d.mts +10 -12
  124. package/dist/plugins/anonymous/client.mjs +1 -1
  125. package/dist/plugins/anonymous/error-codes.d.mts +10 -13
  126. package/dist/plugins/anonymous/index.d.mts +17 -21
  127. package/dist/plugins/anonymous/schema.d.mts +2 -3
  128. package/dist/plugins/anonymous/types.d.mts +5 -6
  129. package/dist/plugins/bearer/index.d.mts +7 -11
  130. package/dist/plugins/captcha/constants.d.mts +2 -3
  131. package/dist/plugins/captcha/index.d.mts +6 -9
  132. package/dist/plugins/captcha/types.d.mts +11 -13
  133. package/dist/plugins/custom-session/client.d.mts +2 -4
  134. package/dist/plugins/custom-session/index.d.mts +10 -16
  135. package/dist/plugins/device-authorization/client.d.mts +2 -4
  136. package/dist/plugins/device-authorization/index.d.mts +39 -44
  137. package/dist/plugins/device-authorization/index.mjs +9 -8
  138. package/dist/plugins/device-authorization/routes.d.mts +11 -9
  139. package/dist/plugins/device-authorization/routes.mjs +6 -5
  140. package/dist/plugins/device-authorization/schema.d.mts +2 -3
  141. package/dist/plugins/email-otp/client.d.mts +5 -7
  142. package/dist/plugins/email-otp/client.mjs +1 -1
  143. package/dist/plugins/email-otp/error-codes.d.mts +5 -8
  144. package/dist/plugins/email-otp/index.d.mts +69 -76
  145. package/dist/plugins/email-otp/otp-token.mjs +19 -7
  146. package/dist/plugins/email-otp/types.d.mts +2 -4
  147. package/dist/plugins/generic-oauth/index.d.mts +9 -13
  148. package/dist/plugins/generic-oauth/index.mjs +6 -4
  149. package/dist/plugins/generic-oauth/providers/auth0.d.mts +3 -5
  150. package/dist/plugins/generic-oauth/providers/gumroad.d.mts +3 -5
  151. package/dist/plugins/generic-oauth/providers/gumroad.mjs +1 -1
  152. package/dist/plugins/generic-oauth/providers/hubspot.d.mts +3 -5
  153. package/dist/plugins/generic-oauth/providers/hubspot.mjs +5 -1
  154. package/dist/plugins/generic-oauth/providers/index.d.mts +2 -1
  155. package/dist/plugins/generic-oauth/providers/keycloak.d.mts +3 -5
  156. package/dist/plugins/generic-oauth/providers/line.d.mts +3 -5
  157. package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +3 -5
  158. package/dist/plugins/generic-oauth/providers/okta.d.mts +3 -5
  159. package/dist/plugins/generic-oauth/providers/patreon.d.mts +3 -5
  160. package/dist/plugins/generic-oauth/providers/patreon.mjs +2 -2
  161. package/dist/plugins/generic-oauth/providers/slack.d.mts +3 -5
  162. package/dist/plugins/generic-oauth/providers/slack.mjs +5 -2
  163. package/dist/plugins/generic-oauth/providers/yandex.d.mts +3 -5
  164. package/dist/plugins/generic-oauth/types.d.mts +6 -7
  165. package/dist/plugins/haveibeenpwned/index.d.mts +7 -11
  166. package/dist/plugins/index.d.mts +4 -1
  167. package/dist/plugins/jwt/client.d.mts +2 -3
  168. package/dist/plugins/jwt/index.d.mts +11 -14
  169. package/dist/plugins/jwt/index.mjs +1 -1
  170. package/dist/plugins/jwt/schema.d.mts +2 -3
  171. package/dist/plugins/jwt/sign.d.mts +9 -8
  172. package/dist/plugins/jwt/types.d.mts +7 -8
  173. package/dist/plugins/jwt/utils.d.mts +6 -9
  174. package/dist/plugins/jwt/verify.d.mts +2 -4
  175. package/dist/plugins/last-login-method/client.d.mts +3 -4
  176. package/dist/plugins/last-login-method/index.d.mts +5 -9
  177. package/dist/plugins/last-login-method/index.mjs +1 -1
  178. package/dist/plugins/magic-link/client.d.mts +2 -4
  179. package/dist/plugins/magic-link/index.d.mts +7 -10
  180. package/dist/plugins/magic-link/index.mjs +20 -17
  181. package/dist/plugins/multi-session/client.d.mts +3 -5
  182. package/dist/plugins/multi-session/client.mjs +1 -1
  183. package/dist/plugins/multi-session/error-codes.d.mts +3 -6
  184. package/dist/plugins/multi-session/index.d.mts +10 -14
  185. package/dist/plugins/oauth-popup/client.d.mts +11 -17
  186. package/dist/plugins/oauth-popup/client.mjs +6 -4
  187. package/dist/plugins/oauth-popup/constants.d.mts +5 -6
  188. package/dist/plugins/oauth-popup/error-codes.d.mts +6 -9
  189. package/dist/plugins/oauth-popup/index.d.mts +11 -15
  190. package/dist/plugins/oauth-popup/index.mjs +8 -7
  191. package/dist/plugins/oauth-popup/types.d.mts +4 -6
  192. package/dist/plugins/oauth-proxy/index.d.mts +11 -15
  193. package/dist/plugins/oauth-proxy/index.mjs +10 -7
  194. package/dist/plugins/one-tap/client.d.mts +6 -9
  195. package/dist/plugins/one-tap/index.d.mts +4 -7
  196. package/dist/plugins/one-time-token/client.d.mts +2 -3
  197. package/dist/plugins/one-time-token/index.d.mts +8 -10
  198. package/dist/plugins/open-api/generator.d.mts +8 -8
  199. package/dist/plugins/open-api/generator.mjs +5 -5
  200. package/dist/plugins/open-api/index.d.mts +5 -7
  201. package/dist/plugins/organization/access/index.mjs +1 -2
  202. package/dist/plugins/organization/access/statement.d.mts +8 -8
  203. package/dist/plugins/organization/adapter.d.mts +60 -87
  204. package/dist/plugins/organization/adapter.mjs +14 -10
  205. package/dist/plugins/organization/client.d.mts +108 -107
  206. package/dist/plugins/organization/client.mjs +9 -5
  207. package/dist/plugins/organization/error-codes.d.mts +61 -64
  208. package/dist/plugins/organization/has-permission.d.mts +2 -4
  209. package/dist/plugins/organization/has-permission.mjs +1 -1
  210. package/dist/plugins/organization/index.d.mts +1 -1
  211. package/dist/plugins/organization/organization.d.mts +20 -20
  212. package/dist/plugins/organization/organization.mjs +13 -8
  213. package/dist/plugins/organization/permission.d.mts +4 -5
  214. package/dist/plugins/organization/routes/crud-access-control.d.mts +28 -28
  215. package/dist/plugins/organization/routes/crud-invites.d.mts +64 -65
  216. package/dist/plugins/organization/routes/crud-invites.mjs +21 -18
  217. package/dist/plugins/organization/routes/crud-members.d.mts +53 -56
  218. package/dist/plugins/organization/routes/crud-members.mjs +23 -21
  219. package/dist/plugins/organization/routes/crud-org.d.mts +63 -65
  220. package/dist/plugins/organization/routes/crud-org.mjs +4 -2
  221. package/dist/plugins/organization/routes/crud-team.d.mts +65 -66
  222. package/dist/plugins/organization/routes/crud-team.mjs +4 -2
  223. package/dist/plugins/organization/schema.d.mts +33 -33
  224. package/dist/plugins/organization/schema.mjs +1 -1
  225. package/dist/plugins/organization/types.d.mts +16 -17
  226. package/dist/plugins/phone-number/client.d.mts +14 -16
  227. package/dist/plugins/phone-number/client.mjs +1 -1
  228. package/dist/plugins/phone-number/error-codes.d.mts +14 -17
  229. package/dist/plugins/phone-number/index.d.mts +48 -54
  230. package/dist/plugins/phone-number/schema.d.mts +2 -3
  231. package/dist/plugins/phone-number/types.d.mts +4 -5
  232. package/dist/plugins/siwe/client.d.mts +2 -4
  233. package/dist/plugins/siwe/index.d.mts +7 -9
  234. package/dist/plugins/siwe/index.mjs +1 -1
  235. package/dist/plugins/siwe/parse-message.mjs +1 -3
  236. package/dist/plugins/siwe/schema.d.mts +3 -4
  237. package/dist/plugins/siwe/types.d.mts +4 -4
  238. package/dist/plugins/test-utils/auth-helpers.mjs +4 -2
  239. package/dist/plugins/test-utils/index.d.mts +3 -5
  240. package/dist/plugins/test-utils/types.d.mts +7 -7
  241. package/dist/plugins/two-factor/backup-codes/index.d.mts +11 -14
  242. package/dist/plugins/two-factor/backup-codes/index.mjs +12 -6
  243. package/dist/plugins/two-factor/client.d.mts +16 -19
  244. package/dist/plugins/two-factor/client.mjs +1 -1
  245. package/dist/plugins/two-factor/constant.mjs +1 -1
  246. package/dist/plugins/two-factor/error-code.d.mts +15 -18
  247. package/dist/plugins/two-factor/index.d.mts +31 -35
  248. package/dist/plugins/two-factor/index.mjs +6 -3
  249. package/dist/plugins/two-factor/otp/index.d.mts +5 -8
  250. package/dist/plugins/two-factor/otp/index.mjs +159 -154
  251. package/dist/plugins/two-factor/schema.d.mts +2 -3
  252. package/dist/plugins/two-factor/totp/index.d.mts +7 -10
  253. package/dist/plugins/two-factor/totp/index.mjs +164 -148
  254. package/dist/plugins/two-factor/types.d.mts +6 -7
  255. package/dist/plugins/username/client.d.mts +12 -14
  256. package/dist/plugins/username/client.mjs +1 -1
  257. package/dist/plugins/username/error-codes.d.mts +11 -14
  258. package/dist/plugins/username/index.d.mts +26 -31
  259. package/dist/plugins/username/index.mjs +5 -18
  260. package/dist/plugins/username/schema.d.mts +7 -10
  261. package/dist/state.d.mts +4 -5
  262. package/dist/test-utils/headers.d.mts +2 -3
  263. package/dist/test-utils/http-test-instance.d.mts +26 -29
  264. package/dist/test-utils/test-instance.d.mts +7 -6
  265. package/dist/test-utils/test-instance.mjs +4 -2
  266. package/dist/types/adapter.d.mts +1 -1
  267. package/dist/types/api.d.mts +4 -6
  268. package/dist/types/auth.d.mts +2 -4
  269. package/dist/types/helper.d.mts +11 -12
  270. package/dist/types/index.d.mts +2 -2
  271. package/dist/types/models.d.mts +4 -5
  272. package/dist/types/plugins.d.mts +7 -8
  273. package/dist/utils/hide-metadata.d.mts +2 -3
  274. package/dist/utils/index.d.mts +2 -1
  275. package/dist/utils/is-api-error.mjs +1 -2
  276. package/dist/utils/time.d.mts +4 -4
  277. package/dist/utils/url.d.mts +13 -15
  278. package/dist/utils/wildcard.mjs +5 -3
  279. package/package.json +12 -12
@@ -3,30 +3,23 @@ import { signJWT, symmetricDecodeJWT, symmetricEncodeJWT, verifyJWT } from "./jw
3
3
  import { hashPassword, verifyPassword } from "./password.mjs";
4
4
  import { generateRandomString } from "./random.mjs";
5
5
  import { SecretConfig } from "@better-auth/core";
6
-
7
6
  //#region src/crypto/index.d.ts
8
- declare function parseEnvelope(data: string): {
7
+ export declare function parseEnvelope(data: string): {
9
8
  version: number;
10
9
  ciphertext: string;
11
10
  } | null;
12
- declare function formatEnvelope(version: number, ciphertext: string): string;
13
- type SymmetricEncryptOptions = {
11
+ export declare function formatEnvelope(version: number, ciphertext: string): string;
12
+ export type SymmetricEncryptOptions = {
14
13
  key: string | SecretConfig;
15
14
  data: string;
16
15
  };
17
- declare const symmetricEncrypt: ({
18
- key,
19
- data
20
- }: SymmetricEncryptOptions) => Promise<string>;
21
- type SymmetricDecryptOptions = {
16
+ export declare const symmetricEncrypt: ({ key, data }: SymmetricEncryptOptions) => Promise<string>;
17
+ export type SymmetricDecryptOptions = {
22
18
  key: string | SecretConfig;
23
19
  data: string;
24
20
  };
25
- declare const symmetricDecrypt: ({
26
- key,
27
- data
28
- }: SymmetricDecryptOptions) => Promise<string>;
29
- declare const getCryptoKey: (secret: string | BufferSource) => Promise<CryptoKey>;
30
- declare const makeSignature: (value: string, secret: string | BufferSource) => Promise<string>;
21
+ export declare const symmetricDecrypt: ({ key, data }: SymmetricDecryptOptions) => Promise<string>;
22
+ export declare const getCryptoKey: (secret: string | BufferSource) => Promise<CryptoKey>;
23
+ export declare const makeSignature: (value: string, secret: string | BufferSource) => Promise<string>;
31
24
  //#endregion
32
- export { type SecretConfig, SymmetricDecryptOptions, SymmetricEncryptOptions, constantTimeEqual, formatEnvelope, generateRandomString, getCryptoKey, hashPassword, makeSignature, parseEnvelope, signJWT, symmetricDecodeJWT, symmetricDecrypt, symmetricEncodeJWT, symmetricEncrypt, verifyJWT, verifyPassword };
25
+ export { type SecretConfig, constantTimeEqual, generateRandomString, hashPassword, signJWT, symmetricDecodeJWT, symmetricEncodeJWT, verifyJWT, verifyPassword };
@@ -30,7 +30,8 @@ function formatEnvelope(version, ciphertext) {
30
30
  async function rawEncrypt(secret, data) {
31
31
  const keyAsBytes = await createHash("SHA-256").digest(secret);
32
32
  const dataAsBytes = utf8ToBytes(data);
33
- return bytesToHex(managedNonce(xchacha20poly1305)(new Uint8Array(keyAsBytes)).encrypt(dataAsBytes));
33
+ const chacha = managedNonce(xchacha20poly1305)(new Uint8Array(keyAsBytes));
34
+ return bytesToHex(chacha.encrypt(dataAsBytes));
34
35
  }
35
36
  async function rawDecrypt(secret, hex) {
36
37
  const keyAsBytes = await createHash("SHA-256").digest(secret);
@@ -1,9 +1,7 @@
1
1
  import { SecretConfig } from "./index.mjs";
2
-
3
2
  //#region src/crypto/jwt.d.ts
4
- declare function signJWT(payload: any, secret: string, expiresIn?: number): Promise<string>;
5
- declare function verifyJWT<T = any>(token: string, secret: string): Promise<T | null>;
6
- declare function symmetricEncodeJWT<T extends Record<string, any>>(payload: T, secret: string | SecretConfig, salt: string, expiresIn?: number): Promise<string>;
7
- declare function symmetricDecodeJWT<T = any>(token: string, secret: string | SecretConfig, salt: string): Promise<T | null>;
8
- //#endregion
9
- export { signJWT, symmetricDecodeJWT, symmetricEncodeJWT, verifyJWT };
3
+ export declare function signJWT(payload: any, secret: string, expiresIn?: number): Promise<string>;
4
+ export declare function verifyJWT<T = any>(token: string, secret: string): Promise<T | null>;
5
+ export declare function symmetricEncodeJWT<T extends Record<string, any>>(payload: T, secret: string | SecretConfig, salt: string, expiresIn?: number): Promise<string>;
6
+ export declare function symmetricDecodeJWT<T = any>(token: string, secret: string | SecretConfig, salt: string): Promise<T | null>;
7
+ //#endregion
@@ -129,7 +129,8 @@ async function symmetricDecodeJWT(token, secret, salt) {
129
129
  if (secrets.length <= 1) return null;
130
130
  for (let i = 1; i < secrets.length; i++) try {
131
131
  const s = secrets[i];
132
- const { payload } = await jwtDecrypt(token, deriveEncryptionSecret(s.value, salt), jwtDecryptOpts);
132
+ const encryptionSecret = deriveEncryptionSecret(s.value, salt);
133
+ const { payload } = await jwtDecrypt(token, encryptionSecret, jwtDecryptOpts);
133
134
  return payload;
134
135
  } catch {
135
136
  continue;
@@ -1,11 +1,7 @@
1
1
  import { hashPassword } from "@better-auth/utils/password";
2
-
3
2
  //#region src/crypto/password.d.ts
4
3
  declare const hashPassword$1: typeof hashPassword;
5
- declare const verifyPassword$1: ({
6
- hash,
7
- password
8
- }: {
4
+ declare const verifyPassword$1: ({ hash, password }: {
9
5
  hash: string;
10
6
  password: string;
11
7
  }) => Promise<boolean>;
@@ -1,4 +1,3 @@
1
1
  //#region src/crypto/random.d.ts
2
- declare const generateRandomString: <SubA extends "a-z" | "A-Z" | "0-9" | "-_">(length: number, ...alphabets: SubA[]) => string;
3
- //#endregion
4
- export { generateRandomString };
2
+ export declare const generateRandomString: <SubA extends "a-z" | "A-Z" | "0-9" | "-_">(length: number, ...alphabets: SubA[]) => string;
3
+ //#endregion
@@ -1,7 +1,5 @@
1
1
  import { BetterAuthOptions } from "@better-auth/core";
2
2
  import { DBAdapter } from "@better-auth/core/db/adapter";
3
-
4
3
  //#region src/db/adapter-base.d.ts
5
- declare function getBaseAdapter(options: BetterAuthOptions, handleDirectDatabase: (options: BetterAuthOptions) => Promise<DBAdapter<BetterAuthOptions>>): Promise<DBAdapter<BetterAuthOptions>>;
6
- //#endregion
7
- export { getBaseAdapter };
4
+ export declare function getBaseAdapter(options: BetterAuthOptions, handleDirectDatabase: (options: BetterAuthOptions) => Promise<DBAdapter<BetterAuthOptions>>): Promise<DBAdapter<BetterAuthOptions>>;
5
+ //#endregion
@@ -1,7 +1,5 @@
1
1
  import { BetterAuthOptions } from "@better-auth/core";
2
2
  import { DBAdapter } from "@better-auth/core/db/adapter";
3
-
4
3
  //#region src/db/adapter-kysely.d.ts
5
- declare function getAdapter(options: BetterAuthOptions): Promise<DBAdapter<BetterAuthOptions>>;
6
- //#endregion
7
- export { getAdapter };
4
+ export declare function getAdapter(options: BetterAuthOptions): Promise<DBAdapter<BetterAuthOptions>>;
5
+ //#endregion
@@ -1,7 +1,5 @@
1
1
  import { DBFieldAttribute } from "@better-auth/core/db";
2
-
3
2
  //#region src/db/field-converter.d.ts
4
- declare function convertToDB<T extends Record<string, any>>(fields: Record<string, DBFieldAttribute>, values: T): T;
5
- declare function convertFromDB<T extends Record<string, any>>(fields: Record<string, DBFieldAttribute>, values: T | null): T | null;
6
- //#endregion
7
- export { convertFromDB, convertToDB };
3
+ export declare function convertToDB<T extends Record<string, any>>(fields: Record<string, DBFieldAttribute>, values: T): T;
4
+ export declare function convertFromDB<T extends Record<string, any>>(fields: Record<string, DBFieldAttribute>, values: T | null): T | null;
5
+ //#endregion
@@ -1,22 +1,21 @@
1
1
  import { DBFieldAttribute, InferDBValueType } from "@better-auth/core/db";
2
-
3
2
  //#region src/db/field.d.ts
4
- type InferFieldsOutput<Fields extends Record<string, DBFieldAttribute>> = Fields extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? key : never : key]: InferFieldOutput<Fields[key]> } & { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? never : key : never]?: InferFieldOutput<Fields[key]> | null } : never;
3
+ export type InferFieldsOutput<Fields extends Record<string, DBFieldAttribute>> = Fields extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? key : never : key]: InferFieldOutput<Fields[key]>; } & { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? never : key : never]?: InferFieldOutput<Fields[key]> | null; } : never;
5
4
  /**
6
5
  * For client will add "?" on optional fields
7
6
  */
8
- type InferFieldsInputClient<Fields extends Record<string, DBFieldAttribute>> = Fields extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Fields[key]["required"] extends false ? never : Fields[key]["defaultValue"] extends string | number | boolean | Date ? never : Fields[key]["input"] extends false ? never : key]: InferFieldInput<Fields[key]> } & { [key in Key as Fields[key]["input"] extends false ? never : Fields[key]["required"] extends false ? key : Fields[key]["defaultValue"] extends string | number | boolean | Date ? key : never]?: InferFieldInput<Fields[key]> | undefined | null } : never;
7
+ export type InferFieldsInputClient<Fields extends Record<string, DBFieldAttribute>> = Fields extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Fields[key]["required"] extends false ? never : Fields[key]["defaultValue"] extends string | number | boolean | Date ? never : Fields[key]["input"] extends false ? never : key]: InferFieldInput<Fields[key]>; } & { [key in Key as Fields[key]["input"] extends false ? never : Fields[key]["required"] extends false ? key : Fields[key]["defaultValue"] extends string | number | boolean | Date ? key : never]?: InferFieldInput<Fields[key]> | undefined | null; } : never;
9
8
  type InferFieldOutput<T extends DBFieldAttribute> = T["returned"] extends false ? never : T["required"] extends false ? InferDBValueType<T["type"]> | undefined | null : InferDBValueType<T["type"]>;
10
9
  /**
11
10
  * Converts a Record<string, DBFieldAttribute> to an object type
12
11
  * with keys and value types inferred from DBFieldAttribute["type"].
13
12
  */
14
- type FieldAttributeToObject<Fields extends Record<string, DBFieldAttribute>> = AddOptionalFields<{ [K in keyof Fields]: InferDBValueType<Fields[K]["type"]> }, Fields>;
13
+ export type FieldAttributeToObject<Fields extends Record<string, DBFieldAttribute>> = AddOptionalFields<{ [K in keyof Fields]: InferDBValueType<Fields[K]["type"]>; }, Fields>;
15
14
  type AddOptionalFields<T extends Record<string, any>, Fields extends Record<keyof T, DBFieldAttribute>> = { [K in keyof T as Fields[K] extends {
16
15
  required: false;
17
- } ? never : K]: T[K] } & { [K in keyof T as Fields[K] extends {
16
+ } ? never : K]: T[K]; } & { [K in keyof T as Fields[K] extends {
18
17
  required: false;
19
- } ? K : never]?: T[K] };
18
+ } ? K : never]?: T[K]; };
20
19
  /**
21
20
  * Infer the additional fields from the plugin options.
22
21
  * For example, you can infer the additional fields of the org plugin's organization schema like this:
@@ -27,15 +26,15 @@ type AddOptionalFields<T extends Record<string, any>, Fields extends Record<keyo
27
26
  * @param isClientSide - When `true` (default), filters out `input: false` fields (clients can't send these).
28
27
  * When `false`, includes all fields (for internal/server-side use).
29
28
  */
30
- type InferAdditionalFieldsFromPluginOptions<SchemaName extends string, Options extends {
29
+ export type InferAdditionalFieldsFromPluginOptions<SchemaName extends string, Options extends {
31
30
  schema?: { [key in SchemaName]?: {
32
31
  additionalFields?: Record<string, DBFieldAttribute>;
33
- } } | undefined;
32
+ }; } | undefined;
34
33
  }, isClientSide extends boolean = true> = Options["schema"] extends { [key in SchemaName]?: {
35
34
  additionalFields: infer Field extends Record<string, DBFieldAttribute>;
36
- } } ? isClientSide extends true ? FieldAttributeToObject<RemoveFieldsWithInputFalse<Field>> : FieldAttributeToObject<Field> : {};
37
- type RemoveFieldsWithInputFalse<T extends Record<string, DBFieldAttribute>> = { [K in keyof T as T[K]["input"] extends false ? never : K]: T[K] };
38
- type RemoveFieldsWithReturnedFalse<T extends Record<string, DBFieldAttribute>> = { [K in keyof T as T[K]["returned"] extends false ? never : K]: T[K] };
35
+ }; } ? isClientSide extends true ? FieldAttributeToObject<RemoveFieldsWithInputFalse<Field>> : FieldAttributeToObject<Field> : {};
36
+ type RemoveFieldsWithInputFalse<T extends Record<string, DBFieldAttribute>> = { [K in keyof T as T[K]["input"] extends false ? never : K]: T[K]; };
37
+ export type RemoveFieldsWithReturnedFalse<T extends Record<string, DBFieldAttribute>> = { [K in keyof T as T[K]["returned"] extends false ? never : K]: T[K]; };
39
38
  type InferFieldInput<T extends DBFieldAttribute> = InferDBValueType<T["type"]>;
40
39
  //#endregion
41
- export { FieldAttributeToObject, InferAdditionalFieldsFromPluginOptions, InferFieldsInputClient, InferFieldsOutput, RemoveFieldsWithReturnedFalse };
40
+ export {};
@@ -3,7 +3,6 @@ import { DBFieldAttribute, DBFieldType } from "@better-auth/core/db";
3
3
  import { BetterAuthError } from "@better-auth/core/error";
4
4
  import { KyselyDatabaseType } from "@better-auth/kysely-adapter";
5
5
  import { ResolvedDBTableIndex } from "@better-auth/core/db/internal";
6
-
7
6
  //#region src/db/get-migration.d.ts
8
7
  /**
9
8
  * Thrown when {@link getMigrations} refuses to add a required column with no
@@ -11,8 +10,8 @@ import { ResolvedDBTableIndex } from "@better-auth/core/db/internal";
11
10
  * {@link BetterAuthError} thrown for index-definition conflicts, so callers
12
11
  * can tell the two apart without matching on message text.
13
12
  */
14
- declare class UnsafeMigrationError extends BetterAuthError {}
15
- declare function matchType(columnDataType: string, fieldType: DBFieldType, dbType: KyselyDatabaseType): boolean;
13
+ export declare class UnsafeMigrationError extends BetterAuthError {}
14
+ export declare function matchType(columnDataType: string, fieldType: DBFieldType, dbType: KyselyDatabaseType): boolean;
16
15
  /**
17
16
  * Build the migration plan that `auth migrate` executes and `auth generate`
18
17
  * prints for the Kysely adapter.
@@ -27,9 +26,7 @@ declare function matchType(columnDataType: string, fieldType: DBFieldType, dbTyp
27
26
  * @throws {BetterAuthError} when an index definition conflicts with an
28
27
  * existing or already-planned index.
29
28
  */
30
- declare function getMigrations(config: BetterAuthOptions, {
31
- throwOnUnsafe
32
- }?: {
29
+ export declare function getMigrations(config: BetterAuthOptions, { throwOnUnsafe }?: {
33
30
  throwOnUnsafe?: boolean;
34
31
  }): Promise<{
35
32
  toBeCreated: {
@@ -52,5 +49,4 @@ declare function getMigrations(config: BetterAuthOptions, {
52
49
  runMigrations: () => Promise<void>;
53
50
  compileMigrations: () => Promise<string>;
54
51
  }>;
55
- //#endregion
56
- export { UnsafeMigrationError, getMigrations, matchType };
52
+ //#endregion
@@ -176,8 +176,7 @@ async function getDatabaseIndexMap(db, target, tableNames, introspectIndexes) {
176
176
  WHERE table_schema = DATABASE()
177
177
  `.execute(db)).rows;
178
178
  break;
179
- case "mssql":
180
- rows = (await sql`
179
+ case "mssql": rows = (await sql`
181
180
  SELECT
182
181
  tables.name AS "tableName",
183
182
  indexes.name AS "indexName",
@@ -202,7 +201,6 @@ async function getDatabaseIndexMap(db, target, tableNames, introspectIndexes) {
202
201
  AND indexes.name IS NOT NULL
203
202
  AND index_columns.key_ordinal > 0
204
203
  `.execute(db)).rows;
205
- break;
206
204
  }
207
205
  const indexMetadata = /* @__PURE__ */ new Map();
208
206
  for (const row of rows) {
@@ -253,8 +251,7 @@ async function getDatabaseColumnBounds(db, target) {
253
251
  WHERE table_schema = DATABASE()
254
252
  `.execute(db)).rows;
255
253
  break;
256
- case "mssql":
257
- rows = (await sql`
254
+ case "mssql": rows = (await sql`
258
255
  SELECT
259
256
  tables.name AS "tableName",
260
257
  columns.name AS "columnName",
@@ -266,7 +263,6 @@ async function getDatabaseColumnBounds(db, target) {
266
263
  ON table_schemas.schema_id = tables.schema_id
267
264
  WHERE table_schemas.name = ${target.schema}
268
265
  `.execute(db)).rows;
269
- break;
270
266
  }
271
267
  const bounds = /* @__PURE__ */ new Map();
272
268
  for (const row of rows) {
@@ -370,8 +366,10 @@ async function getMigrations(config, { throwOnUnsafe = true } = {}) {
370
366
  };
371
367
  logger.debug(`PostgreSQL migration: Using schema '${schema}' (${schemaName ? "from database.schemaName" : "from search_path"})`);
372
368
  try {
373
- if (!(await db.introspection.getSchemas()).some(({ name }) => name === schema)) if (schemaName) logger.debug(`Schema '${schema}' does not exist yet. The migration creates it before creating tables.`);
374
- else logger.warn(`Schema '${schema}' does not exist. Create it before running migrations or check your database configuration.`);
369
+ if (!(await db.introspection.getSchemas()).some(({ name }) => name === schema)) {
370
+ if (schemaName) logger.debug(`Schema '${schema}' does not exist yet. The migration creates it before creating tables.`);
371
+ else logger.warn(`Schema '${schema}' does not exist. Create it before running migrations or check your database configuration.`);
372
+ }
375
373
  } catch (error) {
376
374
  logger.debug(`Could not verify schema existence: ${error instanceof Error ? error.message : String(error)}`);
377
375
  }
@@ -396,9 +394,7 @@ async function getMigrations(config, { throwOnUnsafe = true } = {}) {
396
394
  case "mysql":
397
395
  target = { type: "mysql" };
398
396
  break;
399
- case "sqlite":
400
- target = { type: "sqlite" };
401
- break;
397
+ case "sqlite": target = { type: "sqlite" };
402
398
  }
403
399
  const databaseIndexMap = await getDatabaseIndexMap(db, target, allTableMetadata.map((table) => table.name), introspectIndexes);
404
400
  const databaseColumnBounds = await getDatabaseColumnBounds(db, target);
@@ -457,12 +453,13 @@ async function getMigrations(config, { throwOnUnsafe = true } = {}) {
457
453
  order: value.order || Infinity
458
454
  };
459
455
  const insertIndex = toBeCreated.findIndex((t) => (t.order || Infinity) > tableData.order);
460
- if (insertIndex === -1) if (tIndex === -1) toBeCreated.push(tableData);
461
- else toBeCreated[tIndex].fields = {
462
- ...toBeCreated[tIndex].fields,
463
- ...value.fields
464
- };
465
- else toBeCreated.splice(insertIndex, 0, tableData);
456
+ if (insertIndex === -1) {
457
+ if (tIndex === -1) toBeCreated.push(tableData);
458
+ else toBeCreated[tIndex].fields = {
459
+ ...toBeCreated[tIndex].fields,
460
+ ...value.fields
461
+ };
462
+ } else toBeCreated.splice(insertIndex, 0, tableData);
466
463
  continue;
467
464
  }
468
465
  const toBeAddedFields = {};
@@ -618,9 +615,10 @@ async function getMigrations(config, { throwOnUnsafe = true } = {}) {
618
615
  const built = builder.addColumn(fieldName, type, (col) => {
619
616
  col = field.required !== false ? col.notNull() : col;
620
617
  if (field.references) col = col.references(getReferencePath(field)).onDelete(field.references.onDelete || "cascade");
621
- if (timestampDefault) if (dbType === "mysql") col = col.defaultTo(sql`CURRENT_TIMESTAMP(3)`);
622
- else col = col.defaultTo(sql`CURRENT_TIMESTAMP`);
623
- else if (staticDefault) col = col.defaultTo(typeof field.defaultValue === "boolean" && (dbType === "sqlite" || dbType === "mssql") ? field.defaultValue ? 1 : 0 : field.defaultValue);
618
+ if (timestampDefault) {
619
+ if (dbType === "mysql") col = col.defaultTo(sql`CURRENT_TIMESTAMP(3)`);
620
+ else col = col.defaultTo(sql`CURRENT_TIMESTAMP`);
621
+ } else if (staticDefault) col = col.defaultTo(typeof field.defaultValue === "boolean" && (dbType === "sqlite" || dbType === "mssql") ? field.defaultValue ? 1 : 0 : field.defaultValue);
624
622
  return col;
625
623
  });
626
624
  migrations.push(built);
@@ -647,8 +645,10 @@ async function getMigrations(config, { throwOnUnsafe = true } = {}) {
647
645
  col = field.required !== false ? col.notNull() : col;
648
646
  if (field.references) col = col.references(getReferencePath(field)).onDelete(field.references.onDelete || "cascade");
649
647
  if (field.unique) col = col.unique();
650
- if (field.type === "date" && typeof field.defaultValue === "function" && (dbType === "postgres" || dbType === "mysql" || dbType === "mssql")) if (dbType === "mysql") col = col.defaultTo(sql`CURRENT_TIMESTAMP(3)`);
651
- else col = col.defaultTo(sql`CURRENT_TIMESTAMP`);
648
+ if (field.type === "date" && typeof field.defaultValue === "function" && (dbType === "postgres" || dbType === "mysql" || dbType === "mssql")) {
649
+ if (dbType === "mysql") col = col.defaultTo(sql`CURRENT_TIMESTAMP(3)`);
650
+ else col = col.defaultTo(sql`CURRENT_TIMESTAMP`);
651
+ }
652
652
  return col;
653
653
  });
654
654
  if (field.index && !field.unique) {
@@ -1,13 +1,11 @@
1
1
  import { BetterAuthOptions } from "@better-auth/core";
2
2
  import { DBFieldAttribute } from "@better-auth/core/db";
3
3
  import { ResolvedDBTableIndex } from "@better-auth/core/db/internal";
4
-
5
4
  //#region src/db/get-schema.d.ts
6
- declare function getSchema(config: BetterAuthOptions): Record<string, {
5
+ export declare function getSchema(config: BetterAuthOptions): Record<string, {
7
6
  fields: Record<string, DBFieldAttribute>;
8
7
  indexes?: readonly ResolvedDBTableIndex[] | undefined;
9
8
  order: number;
10
9
  disableMigrations?: boolean | undefined;
11
10
  }>;
12
- //#endregion
13
- export { getSchema };
11
+ //#endregion
@@ -2,13 +2,11 @@ import { DatabaseHooksEntry } from "./with-hooks.mjs";
2
2
  import { AuthContext, BetterAuthOptions, InternalAdapter } from "@better-auth/core";
3
3
  import { InternalLogger } from "@better-auth/core/env";
4
4
  import { DBAdapter } from "@better-auth/core/db/adapter";
5
-
6
5
  //#region src/db/internal-adapter.d.ts
7
- declare const createInternalAdapter: (adapter: DBAdapter<BetterAuthOptions>, ctx: {
6
+ export declare const createInternalAdapter: (adapter: DBAdapter<BetterAuthOptions>, ctx: {
8
7
  options: Omit<BetterAuthOptions, "logger">;
9
8
  logger: InternalLogger;
10
9
  hooks: DatabaseHooksEntry[];
11
10
  generateId: AuthContext["generateId"];
12
11
  }) => InternalAdapter;
13
- //#endregion
14
- export { createInternalAdapter };
12
+ //#endregion
@@ -20,7 +20,7 @@ const createInternalAdapter = (adapter, ctx) => {
20
20
  const options = ctx.options;
21
21
  const secondaryStorage = options.secondaryStorage;
22
22
  const verificationConsumeLocks = /* @__PURE__ */ new Map();
23
- const sessionExpiration = options.session?.expiresIn || 3600 * 24 * 7;
23
+ const sessionExpiration = options.session?.expiresIn || 604800;
24
24
  const databaseSessionFallbackEnabled = !!secondaryStorage && options.session?.storeSessionInDatabase === true && options.session?.preserveSessionInDatabase !== true;
25
25
  const { createWithHooks, updateWithHooks, updateManyWithHooks, deleteWithHooks, deleteManyWithHooks, consumeOneWithHooks } = getWithHooks(adapter, ctx);
26
26
  /**
@@ -280,7 +280,7 @@ const createInternalAdapter = (adapter, ctx) => {
280
280
  * set the session to expire in 1 day.
281
281
  * The cookie will be set to expire at the end of the session
282
282
  */
283
- expiresAt: dontRememberMe ? getDate(3600 * 24, "sec") : getDate(sessionExpiration, "sec"),
283
+ expiresAt: dontRememberMe ? getDate(86400, "sec") : getDate(sessionExpiration, "sec"),
284
284
  userId,
285
285
  token: generateId(32),
286
286
  createdAt: /* @__PURE__ */ new Date(),
@@ -773,7 +773,8 @@ const createInternalAdapter = (adapter, ctx) => {
773
773
  return verification[0] || null;
774
774
  },
775
775
  deleteVerificationByIdentifier: async (identifier) => {
776
- const storedIdentifier = await processIdentifier(identifier, getStorageOption(identifier, options.verification?.storeIdentifier));
776
+ const storageOption = getStorageOption(identifier, options.verification?.storeIdentifier);
777
+ const storedIdentifier = await processIdentifier(identifier, storageOption);
777
778
  if (secondaryStorage) await secondaryStorage.delete(`verification:${storedIdentifier}`);
778
779
  if (!secondaryStorage || options.verification?.storeInDatabase) await deleteWithHooks([{
779
780
  field: "identifier",
@@ -938,7 +939,8 @@ const createInternalAdapter = (adapter, ctx) => {
938
939
  return true;
939
940
  },
940
941
  updateVerificationByIdentifier: async (identifier, data) => {
941
- const storedIdentifier = await processIdentifier(identifier, getStorageOption(identifier, options.verification?.storeIdentifier));
942
+ const storageOption = getStorageOption(identifier, options.verification?.storeIdentifier);
943
+ const storedIdentifier = await processIdentifier(identifier, storageOption);
942
944
  if (secondaryStorage) {
943
945
  const cached = await secondaryStorage.get(`verification:${storedIdentifier}`);
944
946
  if (cached) {
@@ -1,6 +1,6 @@
1
1
  import { User } from "../types/models.mjs";
2
+ import "../types/index.mjs";
2
3
  import { GenericEndpointContext } from "@better-auth/core";
3
-
4
4
  //#region src/db/revoke-unproven-account-access.d.ts
5
5
  /**
6
6
  * Strip every account link and session a pre-existing account accrued before
@@ -16,6 +16,5 @@ import { GenericEndpointContext } from "@better-auth/core";
16
16
  *
17
17
  * @param userId - The pre-existing, not-yet-verified user being promoted.
18
18
  */
19
- declare function revokeUnprovenAccountAccess(ctx: GenericEndpointContext, userId: string): Promise<User | null>;
20
- //#endregion
21
- export { revokeUnprovenAccountAccess };
19
+ export declare function revokeUnprovenAccountAccess(ctx: GenericEndpointContext, userId: string): Promise<User | null>;
20
+ //#endregion
@@ -1,9 +1,9 @@
1
1
  import { Account, Session as Session$1, User as User$1 } from "../types/models.mjs";
2
+ import "../types/index.mjs";
2
3
  import { BetterAuthOptions } from "@better-auth/core";
3
4
  import { BetterAuthPluginDBSchema, DBFieldAttribute } from "@better-auth/core/db";
4
-
5
5
  //#region src/db/schema.d.ts
6
- declare function parseUserOutput<T extends User$1>(options: BetterAuthOptions, user: T): T;
6
+ export declare function parseUserOutput<T extends User$1>(options: BetterAuthOptions, user: T): T;
7
7
  /**
8
8
  * Builds a synthetic user object that matches the shape of a real user
9
9
  * returned from the database. This ensures enumeration protection works
@@ -16,17 +16,17 @@ declare function parseUserOutput<T extends User$1>(options: BetterAuthOptions, u
16
16
  * - Applies default values where defined
17
17
  * - Always includes the 'id' field (not part of schema but always present)
18
18
  */
19
- declare function buildSyntheticUserOutput(options: BetterAuthOptions, data: Record<string, unknown>): Record<string, unknown>;
20
- declare function parseSessionOutput<T extends Session$1>(options: BetterAuthOptions, session: T): T;
21
- declare function parseAccountOutput<T extends Account>(options: BetterAuthOptions, account: T): Omit<T, "idToken" | "accessToken" | "refreshToken" | "accessTokenExpiresAt" | "refreshTokenExpiresAt" | "password">;
22
- declare function parseInputData<T extends Record<string, any>>(data: T, schema: {
19
+ export declare function buildSyntheticUserOutput(options: BetterAuthOptions, data: Record<string, unknown>): Record<string, unknown>;
20
+ export declare function parseSessionOutput<T extends Session$1>(options: BetterAuthOptions, session: T): T;
21
+ export declare function parseAccountOutput<T extends Account>(options: BetterAuthOptions, account: T): Omit<T, "idToken" | "accessToken" | "refreshToken" | "accessTokenExpiresAt" | "refreshTokenExpiresAt" | "password">;
22
+ export declare function parseInputData<T extends Record<string, any>>(data: T, schema: {
23
23
  fields: Record<string, DBFieldAttribute>;
24
24
  action?: ("create" | "update") | undefined;
25
25
  }): Partial<T>;
26
- declare function parseUserInput(options: BetterAuthOptions, user: Record<string, any> | undefined, action: "create" | "update"): Partial<Record<string, any>>;
27
- declare function parseAdditionalUserInputFromProviderProfile(options: BetterAuthOptions, profile: Record<string, unknown> | undefined, action: "create" | "update"): Partial<Record<string, unknown>>;
28
- declare function parseAdditionalUserInput(options: BetterAuthOptions, user?: Record<string, any> | undefined): Partial<Record<string, any>>;
29
- declare function parseAccountInput(options: BetterAuthOptions, account: Partial<Account>): Partial<Partial<{
26
+ export declare function parseUserInput(options: BetterAuthOptions, user: Record<string, any> | undefined, action: "create" | "update"): Partial<Record<string, any>>;
27
+ export declare function parseAdditionalUserInputFromProviderProfile(options: BetterAuthOptions, profile: Record<string, unknown> | undefined, action: "create" | "update"): Partial<Record<string, unknown>>;
28
+ export declare function parseAdditionalUserInput(options: BetterAuthOptions, user?: Record<string, any> | undefined): Partial<Record<string, any>>;
29
+ export declare function parseAccountInput(options: BetterAuthOptions, account: Partial<Account>): Partial<Partial<{
30
30
  id: string;
31
31
  createdAt: Date;
32
32
  updatedAt: Date;
@@ -41,7 +41,7 @@ declare function parseAccountInput(options: BetterAuthOptions, account: Partial<
41
41
  scope?: string | null | undefined;
42
42
  password?: string | null | undefined;
43
43
  }>>;
44
- declare function parseSessionInput(options: BetterAuthOptions, session: Partial<Session$1>, action?: "create" | "update"): Partial<Partial<{
44
+ export declare function parseSessionInput(options: BetterAuthOptions, session: Partial<Session$1>, action?: "create" | "update"): Partial<Partial<{
45
45
  id: string;
46
46
  createdAt: Date;
47
47
  updatedAt: Date;
@@ -51,12 +51,11 @@ declare function parseSessionInput(options: BetterAuthOptions, session: Partial<
51
51
  ipAddress?: string | null | undefined;
52
52
  userAgent?: string | null | undefined;
53
53
  }>>;
54
- declare function getSessionDefaultFields(options: BetterAuthOptions): Record<string, any>;
55
- declare function mergeSchema<S extends BetterAuthPluginDBSchema>(schema: S, newSchema?: { [K in keyof S]?: {
54
+ export declare function getSessionDefaultFields(options: BetterAuthOptions): Record<string, any>;
55
+ export declare function mergeSchema<S extends BetterAuthPluginDBSchema>(schema: S, newSchema?: { [K in keyof S]?: {
56
56
  modelName?: string | undefined;
57
57
  fields?: {
58
58
  [P: string]: string;
59
59
  } | undefined;
60
- } | undefined } | undefined): S;
61
- //#endregion
62
- export { buildSyntheticUserOutput, getSessionDefaultFields, mergeSchema, parseAccountInput, parseAccountOutput, parseAdditionalUserInput, parseAdditionalUserInputFromProviderProfile, parseInputData, parseSessionInput, parseSessionOutput, parseUserInput, parseUserOutput };
60
+ } | undefined; } | undefined): S;
61
+ //#endregion
@@ -22,7 +22,8 @@ function getFields(options, modelName, mode) {
22
22
  return schema;
23
23
  }
24
24
  function parseUserOutput(options, user) {
25
- return filterOutputFields(user, getFields(options, "user", "output"));
25
+ const schema = getFields(options, "user", "output");
26
+ return filterOutputFields(user, schema);
26
27
  }
27
28
  /**
28
29
  * Builds a synthetic user object that matches the shape of a real user
@@ -50,10 +51,12 @@ function buildSyntheticUserOutput(options, data) {
50
51
  return result;
51
52
  }
52
53
  function parseSessionOutput(options, session) {
53
- return filterOutputFields(session, getFields(options, "session", "output"));
54
+ const schema = getFields(options, "session", "output");
55
+ return filterOutputFields(session, schema);
54
56
  }
55
57
  function parseAccountOutput(options, account) {
56
- const { accessToken: _accessToken, refreshToken: _refreshToken, idToken: _idToken, accessTokenExpiresAt: _accessTokenExpiresAt, refreshTokenExpiresAt: _refreshTokenExpiresAt, password: _password, ...rest } = filterOutputFields(account, getFields(options, "account", "output"));
58
+ const schema = getFields(options, "account", "output");
59
+ const { accessToken: _accessToken, refreshToken: _refreshToken, idToken: _idToken, accessTokenExpiresAt: _accessTokenExpiresAt, refreshTokenExpiresAt: _refreshTokenExpiresAt, password: _password, ...rest } = filterOutputFields(account, schema);
57
60
  return rest;
58
61
  }
59
62
  function parseInputData(data, schema) {
@@ -1,11 +1,7 @@
1
1
  import { DBFieldAttribute } from "@better-auth/core/db";
2
2
  import * as z from "zod";
3
-
4
3
  //#region src/db/to-zod.d.ts
5
- declare function toZodSchema<Fields extends Record<string, DBFieldAttribute | never>, IsClientSide extends boolean>({
6
- fields,
7
- isClientSide
8
- }: {
4
+ export declare function toZodSchema<Fields extends Record<string, DBFieldAttribute | never>, IsClientSide extends boolean>({ fields, isClientSide }: {
9
5
  fields: Fields;
10
6
  /**
11
7
  * If true, then any fields that have `input: false` will be removed from the schema to prevent user input.
@@ -13,8 +9,8 @@ declare function toZodSchema<Fields extends Record<string, DBFieldAttribute | ne
13
9
  isClientSide: IsClientSide;
14
10
  }): ZodSchemaForSide<Fields, IsClientSide>;
15
11
  type ZodSchemaForSide<Fields extends Record<string, DBFieldAttribute | never>, IsClientSide extends boolean> = IsClientSide extends true ? z.ZodObject<SchemaShape<Fields, true>, z.core.$strip> : z.ZodObject<SchemaShape<Fields, false>, z.core.$strip>;
16
- type SchemaShape<Fields extends Record<string, DBFieldAttribute | never>, IsClientSide extends boolean> = RemoveNeverProps<{ [key in keyof Fields]: FieldAttributeToSchema<Fields[key], IsClientSide> }>;
17
- type FieldAttributeToSchema<Field extends DBFieldAttribute | Record<string, never>, isClientSide extends boolean = false> = Field extends DBFieldAttribute ? GetSchemaForSide<isClientSide, Field, GetRequired<Field, GetType<Field>>> : Record<string, never>;
12
+ type SchemaShape<Fields extends Record<string, DBFieldAttribute | never>, IsClientSide extends boolean> = RemoveNeverProps<{ [key in keyof Fields]: FieldAttributeToSchema<Fields[key], IsClientSide>; }>;
13
+ export type FieldAttributeToSchema<Field extends DBFieldAttribute | Record<string, never>, isClientSide extends boolean = false> = Field extends DBFieldAttribute ? GetSchemaForSide<isClientSide, Field, GetRequired<Field, GetType<Field>>> : Record<string, never>;
18
14
  type GetType<F extends DBFieldAttribute> = F extends {
19
15
  type: "string";
20
16
  } ? z.ZodString : F extends {
@@ -32,6 +28,6 @@ type GetSchemaForSide<isClientSide extends boolean, Field extends DBFieldAttribu
32
28
  } ? never : Schema : Field extends {
33
29
  returned: false;
34
30
  } ? never : Schema;
35
- type RemoveNeverProps<T> = { [K in keyof T as [T[K]] extends [never] ? never : K]: T[K] };
31
+ type RemoveNeverProps<T> = { [K in keyof T as [T[K]] extends [never] ? never : K]: T[K]; };
36
32
  //#endregion
37
- export { FieldAttributeToSchema, toZodSchema };
33
+ export {};
@@ -1,13 +1,12 @@
1
1
  import { BetterAuthOptions } from "@better-auth/core";
2
2
  import { BaseModelNames } from "@better-auth/core/db";
3
3
  import { DBAdapter, Where } from "@better-auth/core/db/adapter";
4
-
5
4
  //#region src/db/with-hooks.d.ts
6
- type DatabaseHooksEntry = {
5
+ export type DatabaseHooksEntry = {
7
6
  source: string;
8
7
  hooks: Exclude<BetterAuthOptions["databaseHooks"], undefined>;
9
8
  };
10
- declare function getWithHooks(adapter: DBAdapter<BetterAuthOptions>, ctx: {
9
+ export declare function getWithHooks(adapter: DBAdapter<BetterAuthOptions>, ctx: {
11
10
  options: BetterAuthOptions;
12
11
  hooks: DatabaseHooksEntry[];
13
12
  }): {
@@ -33,5 +32,4 @@ declare function getWithHooks(adapter: DBAdapter<BetterAuthOptions>, ctx: {
33
32
  } | undefined) => Promise<any>;
34
33
  consumeOneWithHooks: <T extends Record<string, any>>(model: BaseModelNames, hookWhere: Where[], consumeFn: () => Promise<T | null>, preSnapshot?: T | null) => Promise<T | null>;
35
34
  };
36
- //#endregion
37
- export { DatabaseHooksEntry, getWithHooks };
35
+ //#endregion
package/dist/index.d.mts CHANGED
@@ -11,6 +11,7 @@ import { GenerateStateOptions, generateIdTokenNonce, generateState, parseState }
11
11
  import { StateData, generateGenericState, parseGenericState } from "./state.mjs";
12
12
  import { HIDE_METADATA } from "./utils/hide-metadata.mjs";
13
13
  import { getBaseURL, getHost, getHostFromSource, getOrigin, getProtocol, getProtocolFromSource, isDynamicBaseURLConfig, isRequestLike, matchesHostPattern, resolveBaseURL, resolveDynamicBaseURL, trimTrailingSlashes } from "./utils/url.mjs";
14
+ import "./utils/index.mjs";
14
15
  import { APIError } from "./api/index.mjs";
15
16
  import { StandardSchemaV1 } from "@better-auth/core";
16
17
  import { getCurrentAdapter } from "@better-auth/core/context";
@@ -25,6 +26,6 @@ export * from "@better-auth/core/utils/error-codes";
25
26
  export * from "@better-auth/core/utils/id";
26
27
  export * from "@better-auth/core/utils/json";
27
28
  export * from "@better-auth/core/social-providers";
28
- export * from "better-call";
29
- export * from "zod";
30
- export { APIError, Account, AdditionalSessionFieldsInput, AdditionalUserFieldsInput, Auth, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookies, BetterAuthOptions, BetterAuthPlugin, BetterAuthRateLimitOptions, ClientAtomListener, ClientStore, DBAdapter, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, ExtractPluginField, FilteredAPI, GenerateStateOptions, HIDE_METADATA, HasRequiredKeys, InferAPI, InferActions, InferAdditionalFromClient, InferClientAPI, InferErrorCodes, InferOptionSchema, InferPluginContext, InferPluginErrorCodes, InferPluginFieldFromTuple, InferPluginIDs, InferPluginTypes, InferSessionAPI, InferSessionFromClient, InferUserFromClient, IsAny, IsSignal, type JSONWebKeySet, type JWTPayload, JoinConfig, JoinOption, OverrideMerge, Prettify, PrettifyDeep, RateLimit, RequiredKeysOf, Session, SessionQueryParams, type StandardSchemaV1, StateData, StoreIdentifierOption, StripEmptyObjects, type TelemetryEvent, UnionToIntersection, User, UserProvisioningSource, ValidateUserInfoAction, ValidateUserInfoMethod, ValidateUserInfoOAuthInfo, ValidateUserInfoResult, ValidateUserInfoSSOInfo, ValidateUserInfoSource, Verification, Where, betterAuth, createTelemetry, generateGenericState, generateIdTokenNonce, generateState, getBaseURL, getCurrentAdapter, getHost, getHostFromSource, getOrigin, getProtocol, getProtocolFromSource, getTelemetryAuthConfig, isDynamicBaseURLConfig, isRequestLike, matchesHostPattern, parseGenericState, parseState, resolveBaseURL, resolveDynamicBaseURL, trimTrailingSlashes };
29
+ export type * from "better-call";
30
+ export type * from "zod";
31
+ export { APIError, type Account, type AdditionalSessionFieldsInput, type AdditionalUserFieldsInput, type Auth, type BetterAuthAdvancedOptions, type BetterAuthClientOptions, type BetterAuthClientPlugin, type BetterAuthCookies, type BetterAuthOptions, type BetterAuthPlugin, type BetterAuthRateLimitOptions, type ClientAtomListener, type ClientStore, type DBAdapter, type DBAdapterInstance, type DBAdapterSchemaCreation, type DBTransactionAdapter, type ExtractPluginField, FilteredAPI, GenerateStateOptions, HIDE_METADATA, type HasRequiredKeys, InferAPI, InferActions, InferAdditionalFromClient, InferClientAPI, InferErrorCodes, type InferOptionSchema, type InferPluginContext, type InferPluginErrorCodes, type InferPluginFieldFromTuple, type InferPluginIDs, type InferPluginTypes, InferSessionAPI, InferSessionFromClient, InferUserFromClient, type IsAny, IsSignal, type JSONWebKeySet, type JWTPayload, type JoinConfig, type JoinOption, type OverrideMerge, type Prettify, type PrettifyDeep, type RateLimit, type RequiredKeysOf, type Session, SessionQueryParams, type StandardSchemaV1, type StateData, type StoreIdentifierOption, type StripEmptyObjects, type TelemetryEvent, type UnionToIntersection, type User, type UserProvisioningSource, type ValidateUserInfoAction, type ValidateUserInfoMethod, type ValidateUserInfoOAuthInfo, type ValidateUserInfoResult, type ValidateUserInfoSSOInfo, type ValidateUserInfoSource, type Verification, type Where, betterAuth, createTelemetry, generateGenericState, generateIdTokenNonce, generateState, getBaseURL, getCurrentAdapter, getHost, getHostFromSource, getOrigin, getProtocol, getProtocolFromSource, getTelemetryAuthConfig, isDynamicBaseURLConfig, isRequestLike, matchesHostPattern, parseGenericState, parseState, resolveBaseURL, resolveDynamicBaseURL, trimTrailingSlashes };