better-auth 1.2.0-beta.1 → 1.2.0-beta.11

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 (205) hide show
  1. package/dist/adapters/drizzle.cjs +12 -5
  2. package/dist/adapters/drizzle.d.cts +6 -2
  3. package/dist/adapters/drizzle.d.ts +6 -2
  4. package/dist/adapters/drizzle.js +11 -4
  5. package/dist/adapters/kysely.cjs +5 -5
  6. package/dist/adapters/kysely.d.cts +6 -2
  7. package/dist/adapters/kysely.d.ts +6 -2
  8. package/dist/adapters/kysely.js +3 -3
  9. package/dist/adapters/memory.cjs +4 -4
  10. package/dist/adapters/memory.d.cts +6 -2
  11. package/dist/adapters/memory.d.ts +6 -2
  12. package/dist/adapters/memory.js +3 -3
  13. package/dist/adapters/mongodb.cjs +26 -8
  14. package/dist/adapters/mongodb.d.cts +6 -2
  15. package/dist/adapters/mongodb.d.ts +6 -2
  16. package/dist/adapters/mongodb.js +24 -6
  17. package/dist/adapters/prisma.cjs +18 -5
  18. package/dist/adapters/prisma.d.cts +6 -2
  19. package/dist/adapters/prisma.d.ts +6 -2
  20. package/dist/adapters/prisma.js +16 -3
  21. package/dist/adapters/test.cjs +1 -1
  22. package/dist/adapters/test.d.cts +2 -2
  23. package/dist/adapters/test.d.ts +2 -2
  24. package/dist/adapters/test.js +1 -1
  25. package/dist/api.cjs +48 -44
  26. package/dist/api.d.cts +3 -3
  27. package/dist/api.d.ts +3 -3
  28. package/dist/api.js +5 -5
  29. package/dist/{auth-DcMc3BIq.d.ts → auth-C-uLTIcY.d.ts} +12002 -7646
  30. package/dist/{auth-D4rdpxtI.d.cts → auth-lDfjrjVd.d.cts} +12002 -7646
  31. package/dist/{chunk-MGJLVQOV.js → chunk-2OAHQPLI.js} +100 -38
  32. package/dist/{chunk-5E75URIA.cjs → chunk-2Z6CVQHH.cjs} +0 -4
  33. package/dist/{chunk-WVLPJXQR.cjs → chunk-3FWLBBDV.cjs} +109 -51
  34. package/dist/{chunk-WDOY7YUW.cjs → chunk-6P33VPUY.cjs} +106 -44
  35. package/dist/{chunk-ADGXBH3Y.js → chunk-6XMAWIGH.js} +29 -26
  36. package/dist/{chunk-G7HOSQ5N.cjs → chunk-75MYIQ34.cjs} +15 -18
  37. package/dist/{chunk-YW3B2ST3.js → chunk-BY25AMN4.js} +116 -5
  38. package/dist/{chunk-LZ5DEQVH.cjs → chunk-C4T7TNDG.cjs} +3 -3
  39. package/dist/{chunk-PJ4KWXLQ.cjs → chunk-DH5E7574.cjs} +8 -8
  40. package/dist/{chunk-5RY45WFV.js → chunk-DIIVSN3J.js} +36 -13
  41. package/dist/{chunk-OSBTXYDD.cjs → chunk-GQKBG2VQ.cjs} +125 -14
  42. package/dist/{chunk-BKFMDM3P.js → chunk-HRI7BYTU.js} +115 -16
  43. package/dist/{chunk-6O2GLU2U.cjs → chunk-ICONG5HP.cjs} +18 -13
  44. package/dist/{chunk-3EY3LSQR.js → chunk-IVS5VS3V.js} +75 -36
  45. package/dist/{chunk-YRUDZRY3.cjs → chunk-IYCSNEDU.cjs} +79 -56
  46. package/dist/{chunk-NU4SXYJ5.cjs → chunk-JDAHD767.cjs} +198 -42
  47. package/dist/{chunk-UP6VJQDB.js → chunk-JHLVXVME.js} +17 -10
  48. package/dist/{chunk-WLXFBYQ6.cjs → chunk-JU56U5MW.cjs} +79 -9
  49. package/dist/{chunk-QFYRLTM5.cjs → chunk-JYPC7ZAL.cjs} +52 -49
  50. package/dist/{chunk-UHGAA4GH.cjs → chunk-KNVDJ4WK.cjs} +5 -5
  51. package/dist/{chunk-CVDYU5OC.js → chunk-M6SPJGF4.js} +5 -8
  52. package/dist/{chunk-BAPXDO3E.cjs → chunk-MKNA7SED.cjs} +125 -26
  53. package/dist/{chunk-GTM45OYP.cjs → chunk-NQFRXDEY.cjs} +3 -3
  54. package/dist/{chunk-FXNG3YQA.js → chunk-NXQP77NI.js} +146 -79
  55. package/dist/{chunk-FA6UYV37.js → chunk-PR54V2QL.js} +29 -10
  56. package/dist/{chunk-JLATHUM5.cjs → chunk-QBYD37C7.cjs} +21 -14
  57. package/dist/{chunk-E6LJZ5ME.js → chunk-QFIG4XKQ.js} +1 -1
  58. package/dist/{chunk-764RYNTE.cjs → chunk-QS2XIJC4.cjs} +63 -29
  59. package/dist/{chunk-GTQM7JU7.js → chunk-R42K7GPF.js} +3 -1
  60. package/dist/{chunk-3BWJXTLC.cjs → chunk-RHWADEUT.cjs} +81 -58
  61. package/dist/{chunk-JNZYTS3B.js → chunk-RS2A52JD.js} +1 -1
  62. package/dist/{chunk-5OBRFII2.js → chunk-SIAKIOPW.js} +81 -23
  63. package/dist/{chunk-V6RGXSG4.cjs → chunk-SVC7H7K4.cjs} +3 -1
  64. package/dist/{chunk-EM73ZZSP.cjs → chunk-TID6AR5K.cjs} +49 -30
  65. package/dist/{chunk-VXDYNCOX.js → chunk-TODG5RSV.js} +172 -19
  66. package/dist/{chunk-VPCROEJW.cjs → chunk-TZ2VLKIG.cjs} +170 -103
  67. package/dist/{chunk-WGCTQNSQ.js → chunk-UHBMFLSF.js} +1 -1
  68. package/dist/{chunk-PIWBUHRB.cjs → chunk-UPQLFVFU.cjs} +83 -43
  69. package/dist/{chunk-B5UCLTPZ.cjs → chunk-UQC2FUXC.cjs} +2 -1
  70. package/dist/{chunk-RGG6OEA3.js → chunk-VUXQHI6K.js} +60 -26
  71. package/dist/{chunk-2LQ7T2GE.js → chunk-WUUDJ3TF.js} +3 -3
  72. package/dist/{chunk-HZBNUY7E.js → chunk-WZ6OIVJK.js} +2 -1
  73. package/dist/{chunk-5XAVWKUN.js → chunk-X4X6WCXH.js} +74 -4
  74. package/dist/{chunk-NPO64SVN.js → chunk-ZFUBVSZD.js} +0 -4
  75. package/dist/{chunk-S6MI7ZLE.js → chunk-ZKNBNGHR.js} +12 -7
  76. package/dist/{chunk-5KMF6HGF.js → chunk-ZUGWIOG4.js} +75 -52
  77. package/dist/client/plugins.cjs +215 -21
  78. package/dist/client/plugins.d.cts +176 -10
  79. package/dist/client/plugins.d.ts +176 -10
  80. package/dist/client/plugins.js +214 -14
  81. package/dist/client.d.cts +6 -7
  82. package/dist/client.d.ts +6 -7
  83. package/dist/cookies.d.cts +2 -2
  84. package/dist/cookies.d.ts +2 -2
  85. package/dist/db.cjs +29 -29
  86. package/dist/db.d.cts +6 -6
  87. package/dist/db.d.ts +6 -6
  88. package/dist/db.js +3 -3
  89. package/dist/index-BX_H-j6k.d.cts +7755 -0
  90. package/dist/{index-Ba5bMY6A.d.cts → index-BuRgaJZR.d.cts} +194 -2
  91. package/dist/index-D5zWKzf9.d.ts +7755 -0
  92. package/dist/{index-XrJz4AYF.d.ts → index-moQjyfmm.d.ts} +194 -2
  93. package/dist/index.cjs +19 -19
  94. package/dist/index.d.cts +3 -3
  95. package/dist/index.d.ts +3 -3
  96. package/dist/index.js +9 -9
  97. package/dist/next-js.cjs +24 -24
  98. package/dist/next-js.d.cts +2 -2
  99. package/dist/next-js.d.ts +2 -2
  100. package/dist/next-js.js +23 -23
  101. package/dist/node.d.cts +2 -2
  102. package/dist/node.d.ts +2 -2
  103. package/dist/oauth2.cjs +9 -9
  104. package/dist/oauth2.d.cts +6 -5
  105. package/dist/oauth2.d.ts +6 -5
  106. package/dist/oauth2.js +2 -2
  107. package/dist/plugins/admin.cjs +7 -7
  108. package/dist/plugins/admin.d.cts +163 -32
  109. package/dist/plugins/admin.d.ts +163 -32
  110. package/dist/plugins/admin.js +6 -6
  111. package/dist/plugins/anonymous.cjs +7 -7
  112. package/dist/plugins/anonymous.d.cts +8 -4
  113. package/dist/plugins/anonymous.d.ts +8 -4
  114. package/dist/plugins/anonymous.js +6 -6
  115. package/dist/plugins/bearer.cjs +7 -7
  116. package/dist/plugins/bearer.d.cts +2 -2
  117. package/dist/plugins/bearer.d.ts +2 -2
  118. package/dist/plugins/bearer.js +6 -6
  119. package/dist/{plugin → plugins}/custom-session.cjs +7 -7
  120. package/dist/{plugin → plugins}/custom-session.d.cts +8 -4
  121. package/dist/{plugin → plugins}/custom-session.d.ts +8 -4
  122. package/dist/{plugin → plugins}/custom-session.js +6 -6
  123. package/dist/plugins/email-otp.cjs +7 -7
  124. package/dist/plugins/email-otp.d.cts +44 -16
  125. package/dist/plugins/email-otp.d.ts +44 -16
  126. package/dist/plugins/email-otp.js +6 -6
  127. package/dist/plugins/generic-oauth.cjs +7 -7
  128. package/dist/plugins/generic-oauth.d.cts +95 -6
  129. package/dist/plugins/generic-oauth.d.ts +95 -6
  130. package/dist/plugins/generic-oauth.js +6 -6
  131. package/dist/plugins/jwt.cjs +7 -7
  132. package/dist/plugins/jwt.d.cts +28 -6
  133. package/dist/plugins/jwt.d.ts +28 -6
  134. package/dist/plugins/jwt.js +6 -6
  135. package/dist/plugins/magic-link.cjs +7 -7
  136. package/dist/plugins/magic-link.d.cts +16 -4
  137. package/dist/plugins/magic-link.d.ts +16 -4
  138. package/dist/plugins/magic-link.js +6 -6
  139. package/dist/plugins/multi-session.cjs +7 -7
  140. package/dist/plugins/multi-session.d.cts +20 -8
  141. package/dist/plugins/multi-session.d.ts +20 -8
  142. package/dist/plugins/multi-session.js +6 -6
  143. package/dist/plugins/oidc-provider.cjs +7 -7
  144. package/dist/plugins/oidc-provider.d.cts +58 -15
  145. package/dist/plugins/oidc-provider.d.ts +58 -15
  146. package/dist/plugins/oidc-provider.js +6 -6
  147. package/dist/plugins/one-tap.cjs +7 -7
  148. package/dist/plugins/one-tap.d.cts +13 -2
  149. package/dist/plugins/one-tap.d.ts +13 -2
  150. package/dist/plugins/one-tap.js +6 -6
  151. package/dist/plugins/open-api.cjs +8 -8
  152. package/dist/plugins/open-api.d.cts +14 -6
  153. package/dist/plugins/open-api.d.ts +14 -6
  154. package/dist/plugins/open-api.js +7 -7
  155. package/dist/plugins/organization.cjs +7 -7
  156. package/dist/plugins/organization.d.cts +3 -3
  157. package/dist/plugins/organization.d.ts +3 -3
  158. package/dist/plugins/organization.js +6 -6
  159. package/dist/plugins/passkey.cjs +19 -31
  160. package/dist/plugins/passkey.d.cts +45 -148
  161. package/dist/plugins/passkey.d.ts +45 -148
  162. package/dist/plugins/passkey.js +5 -9
  163. package/dist/plugins/phone-number.cjs +7 -7
  164. package/dist/plugins/phone-number.d.cts +122 -9
  165. package/dist/plugins/phone-number.d.ts +122 -9
  166. package/dist/plugins/phone-number.js +6 -6
  167. package/dist/plugins/sso.cjs +27 -19
  168. package/dist/plugins/sso.d.cts +24 -8
  169. package/dist/plugins/sso.d.ts +24 -8
  170. package/dist/plugins/sso.js +14 -6
  171. package/dist/plugins/two-factor.cjs +7 -7
  172. package/dist/plugins/two-factor.d.cts +62 -22
  173. package/dist/plugins/two-factor.d.ts +62 -22
  174. package/dist/plugins/two-factor.js +6 -6
  175. package/dist/plugins/username.cjs +7 -7
  176. package/dist/plugins/username.d.cts +36 -4
  177. package/dist/plugins/username.d.ts +36 -4
  178. package/dist/plugins/username.js +6 -6
  179. package/dist/plugins.cjs +43 -43
  180. package/dist/plugins.d.cts +11 -7
  181. package/dist/plugins.d.ts +11 -7
  182. package/dist/plugins.js +23 -23
  183. package/dist/react.d.cts +7 -9
  184. package/dist/react.d.ts +7 -9
  185. package/dist/social.cjs +32 -20
  186. package/dist/social.d.cts +1 -1
  187. package/dist/social.d.ts +1 -1
  188. package/dist/social.js +3 -3
  189. package/dist/solid.d.cts +7 -7
  190. package/dist/solid.d.ts +7 -7
  191. package/dist/{state-Cm8el5M1.d.ts → state-CLmFUxz3.d.ts} +1 -1
  192. package/dist/{state-DcraY2_H.d.cts → state-CZgzjtR5.d.cts} +1 -1
  193. package/dist/svelte-kit.d.cts +2 -2
  194. package/dist/svelte-kit.d.ts +2 -2
  195. package/dist/svelte.d.cts +7 -7
  196. package/dist/svelte.d.ts +7 -7
  197. package/dist/types.d.cts +4 -4
  198. package/dist/types.d.ts +4 -4
  199. package/dist/vue.d.cts +7 -7
  200. package/dist/vue.d.ts +7 -7
  201. package/package.json +4 -4
  202. package/dist/chunk-4WCY4Y5J.js +0 -173
  203. package/dist/chunk-5AZFOKWY.cjs +0 -176
  204. package/dist/index-CvlKSqnF.d.cts +0 -4023
  205. package/dist/index-Ivs2EsUL.d.ts +0 -4023
@@ -1,4 +1,4 @@
1
- import { parseSessionOutput, getIp, parseUserOutput } from './chunk-HZBNUY7E.js';
1
+ import { parseSessionOutput, getIp, parseUserOutput } from './chunk-WZ6OIVJK.js';
2
2
  import { generateId, logger, createLogger } from './chunk-KLDFBLYL.js';
3
3
  import { safeJSONParse } from './chunk-53IPO2PJ.js';
4
4
  import { getDate } from './chunk-FURNA6HY.js';
@@ -85,18 +85,21 @@ var createKyselyAdapter = async (config) => {
85
85
  // src/db/with-hooks.ts
86
86
  function getWithHooks(adapter, ctx) {
87
87
  const hooks = ctx.hooks;
88
- async function createWithHooks(data, model, customCreateFn) {
88
+ async function createWithHooks(data, model, customCreateFn, context) {
89
89
  let actualData = data;
90
90
  for (const hook of hooks || []) {
91
91
  const toRun = hook[model]?.create?.before;
92
92
  if (toRun) {
93
- const result = await toRun(data);
93
+ const result = await toRun(actualData, context);
94
94
  if (result === false) {
95
95
  return null;
96
96
  }
97
97
  const isObject = typeof result === "object" && "data" in result;
98
98
  if (isObject) {
99
- actualData = result.data;
99
+ actualData = {
100
+ ...actualData,
101
+ ...result.data
102
+ };
100
103
  }
101
104
  }
102
105
  }
@@ -108,17 +111,17 @@ function getWithHooks(adapter, ctx) {
108
111
  for (const hook of hooks || []) {
109
112
  const toRun = hook[model]?.create?.after;
110
113
  if (toRun) {
111
- await toRun(created);
114
+ await toRun(created, context);
112
115
  }
113
116
  }
114
117
  return created;
115
118
  }
116
- async function updateWithHooks(data, where, model, customUpdateFn) {
119
+ async function updateWithHooks(data, where, model, customUpdateFn, context) {
117
120
  let actualData = data;
118
121
  for (const hook of hooks || []) {
119
122
  const toRun = hook[model]?.update?.before;
120
123
  if (toRun) {
121
- const result = await toRun(data);
124
+ const result = await toRun(data, context);
122
125
  if (result === false) {
123
126
  return null;
124
127
  }
@@ -135,17 +138,17 @@ function getWithHooks(adapter, ctx) {
135
138
  for (const hook of hooks || []) {
136
139
  const toRun = hook[model]?.update?.after;
137
140
  if (toRun) {
138
- await toRun(updated);
141
+ await toRun(updated, context);
139
142
  }
140
143
  }
141
144
  return updated;
142
145
  }
143
- async function updateManyWithHooks(data, where, model, customUpdateFn) {
146
+ async function updateManyWithHooks(data, where, model, customUpdateFn, context) {
144
147
  let actualData = data;
145
148
  for (const hook of hooks || []) {
146
149
  const toRun = hook[model]?.update?.before;
147
150
  if (toRun) {
148
- const result = await toRun(data);
151
+ const result = await toRun(data, context);
149
152
  if (result === false) {
150
153
  return null;
151
154
  }
@@ -162,7 +165,7 @@ function getWithHooks(adapter, ctx) {
162
165
  for (const hook of hooks || []) {
163
166
  const toRun = hook[model]?.update?.after;
164
167
  if (toRun) {
165
- await toRun(updated);
168
+ await toRun(updated, context);
166
169
  }
167
170
  }
168
171
  return updated;
@@ -181,14 +184,16 @@ var createInternalAdapter = (adapter, ctx) => {
181
184
  const sessionExpiration = options.session?.expiresIn || 60 * 60 * 24 * 7;
182
185
  const { createWithHooks, updateWithHooks, updateManyWithHooks } = getWithHooks(adapter, ctx);
183
186
  return {
184
- createOAuthUser: async (user, account) => {
187
+ createOAuthUser: async (user, account, context) => {
185
188
  const createdUser = await createWithHooks(
186
189
  {
187
190
  createdAt: /* @__PURE__ */ new Date(),
188
191
  updatedAt: /* @__PURE__ */ new Date(),
189
192
  ...user
190
193
  },
191
- "user"
194
+ "user",
195
+ void 0,
196
+ context
192
197
  );
193
198
  const createdAccount = await createWithHooks(
194
199
  {
@@ -197,14 +202,16 @@ var createInternalAdapter = (adapter, ctx) => {
197
202
  createdAt: /* @__PURE__ */ new Date(),
198
203
  updatedAt: /* @__PURE__ */ new Date()
199
204
  },
200
- "account"
205
+ "account",
206
+ void 0,
207
+ context
201
208
  );
202
209
  return {
203
210
  user: createdUser,
204
211
  account: createdAccount
205
212
  };
206
213
  },
207
- createUser: async (user) => {
214
+ createUser: async (user, context) => {
208
215
  const createdUser = await createWithHooks(
209
216
  {
210
217
  createdAt: /* @__PURE__ */ new Date(),
@@ -213,18 +220,22 @@ var createInternalAdapter = (adapter, ctx) => {
213
220
  ...user,
214
221
  email: user.email.toLowerCase()
215
222
  },
216
- "user"
223
+ "user",
224
+ void 0,
225
+ context
217
226
  );
218
227
  return createdUser;
219
228
  },
220
- createAccount: async (account) => {
229
+ createAccount: async (account, context) => {
221
230
  const createdAccount = await createWithHooks(
222
231
  {
223
232
  createdAt: /* @__PURE__ */ new Date(),
224
233
  updatedAt: /* @__PURE__ */ new Date(),
225
234
  ...account
226
235
  },
227
- "account"
236
+ "account",
237
+ void 0,
238
+ context
228
239
  );
229
240
  return createdAccount;
230
241
  },
@@ -272,6 +283,12 @@ var createInternalAdapter = (adapter, ctx) => {
272
283
  });
273
284
  return users;
274
285
  },
286
+ countTotalUsers: async () => {
287
+ const total = await adapter.count({
288
+ model: "user"
289
+ });
290
+ return total;
291
+ },
275
292
  deleteUser: async (userId) => {
276
293
  if (secondaryStorage) {
277
294
  await secondaryStorage.delete(`active-sessions-${userId}`);
@@ -306,7 +323,7 @@ var createInternalAdapter = (adapter, ctx) => {
306
323
  ]
307
324
  });
308
325
  },
309
- createSession: async (userId, request, dontRememberMe, override) => {
326
+ createSession: async (userId, request, dontRememberMe, override, context, overrideAll) => {
310
327
  const headers = request instanceof Request ? request.headers : request;
311
328
  const { id: _, ...rest } = override || {};
312
329
  const data = {
@@ -322,7 +339,8 @@ var createInternalAdapter = (adapter, ctx) => {
322
339
  userId,
323
340
  token: generateId(32),
324
341
  createdAt: /* @__PURE__ */ new Date(),
325
- updatedAt: /* @__PURE__ */ new Date()
342
+ updatedAt: /* @__PURE__ */ new Date(),
343
+ ...overrideAll ? rest : {}
326
344
  };
327
345
  const res = await createWithHooks(
328
346
  data,
@@ -350,7 +368,8 @@ var createInternalAdapter = (adapter, ctx) => {
350
368
  return sessionData;
351
369
  },
352
370
  executeMainFn: options.session?.storeSessionInDatabase
353
- } : void 0
371
+ } : void 0,
372
+ context
354
373
  );
355
374
  return res;
356
375
  },
@@ -464,7 +483,7 @@ var createInternalAdapter = (adapter, ctx) => {
464
483
  };
465
484
  });
466
485
  },
467
- updateSession: async (sessionToken, session) => {
486
+ updateSession: async (sessionToken, session, context) => {
468
487
  const updatedSession = await updateWithHooks(
469
488
  session,
470
489
  [{ field: "token", value: sessionToken }],
@@ -485,7 +504,8 @@ var createInternalAdapter = (adapter, ctx) => {
485
504
  }
486
505
  },
487
506
  executeMainFn: options.session?.storeSessionInDatabase
488
- } : void 0
507
+ } : void 0,
508
+ context
489
509
  );
490
510
  return updatedSession;
491
511
  },
@@ -670,18 +690,20 @@ var createInternalAdapter = (adapter, ctx) => {
670
690
  });
671
691
  return user;
672
692
  },
673
- linkAccount: async (account) => {
693
+ linkAccount: async (account, context) => {
674
694
  const _account = await createWithHooks(
675
695
  {
676
696
  ...account,
677
697
  createdAt: /* @__PURE__ */ new Date(),
678
698
  updatedAt: /* @__PURE__ */ new Date()
679
699
  },
680
- "account"
700
+ "account",
701
+ void 0,
702
+ context
681
703
  );
682
704
  return _account;
683
705
  },
684
- updateUser: async (userId, data) => {
706
+ updateUser: async (userId, data, context) => {
685
707
  const user = await updateWithHooks(
686
708
  data,
687
709
  [
@@ -690,24 +712,28 @@ var createInternalAdapter = (adapter, ctx) => {
690
712
  value: userId
691
713
  }
692
714
  ],
693
- "user"
715
+ "user",
716
+ void 0,
717
+ context
694
718
  );
695
719
  return user;
696
720
  },
697
- updateUserByEmail: async (email, data) => {
721
+ updateUserByEmail: async (email, data, context) => {
698
722
  const user = await updateWithHooks(
699
723
  data,
700
724
  [
701
725
  {
702
726
  field: "email",
703
- value: email
727
+ value: email.toLowerCase()
704
728
  }
705
729
  ],
706
- "user"
730
+ "user",
731
+ void 0,
732
+ context
707
733
  );
708
734
  return user;
709
735
  },
710
- updatePassword: async (userId, password) => {
736
+ updatePassword: async (userId, password, context) => {
711
737
  await updateManyWithHooks(
712
738
  {
713
739
  password
@@ -722,7 +748,9 @@ var createInternalAdapter = (adapter, ctx) => {
722
748
  value: "credential"
723
749
  }
724
750
  ],
725
- "account"
751
+ "account",
752
+ void 0,
753
+ context
726
754
  );
727
755
  },
728
756
  findAccounts: async (userId) => {
@@ -761,22 +789,26 @@ var createInternalAdapter = (adapter, ctx) => {
761
789
  });
762
790
  return account;
763
791
  },
764
- updateAccount: async (accountId, data) => {
792
+ updateAccount: async (accountId, data, context) => {
765
793
  const account = await updateWithHooks(
766
794
  data,
767
795
  [{ field: "id", value: accountId }],
768
- "account"
796
+ "account",
797
+ void 0,
798
+ context
769
799
  );
770
800
  return account;
771
801
  },
772
- createVerificationValue: async (data) => {
802
+ createVerificationValue: async (data, context) => {
773
803
  const verification = await createWithHooks(
774
804
  {
775
805
  createdAt: /* @__PURE__ */ new Date(),
776
806
  updatedAt: /* @__PURE__ */ new Date(),
777
807
  ...data
778
808
  },
779
- "verification"
809
+ "verification",
810
+ void 0,
811
+ context
780
812
  );
781
813
  return verification;
782
814
  },
@@ -795,6 +827,18 @@ var createInternalAdapter = (adapter, ctx) => {
795
827
  },
796
828
  limit: 1
797
829
  });
830
+ if (!options.verification?.disableCleanup) {
831
+ await adapter.deleteMany({
832
+ model: "verification",
833
+ where: [
834
+ {
835
+ field: "expiresAt",
836
+ value: (/* @__PURE__ */ new Date()).toISOString(),
837
+ operator: "lt"
838
+ }
839
+ ]
840
+ });
841
+ }
798
842
  const lastVerification = verification[0];
799
843
  return lastVerification;
800
844
  },
@@ -820,11 +864,13 @@ var createInternalAdapter = (adapter, ctx) => {
820
864
  ]
821
865
  });
822
866
  },
823
- updateVerificationValue: async (id, data) => {
867
+ updateVerificationValue: async (id, data, context) => {
824
868
  const verification = await updateWithHooks(
825
869
  data,
826
870
  [{ field: "id", value: id }],
827
- "verification"
871
+ "verification",
872
+ void 0,
873
+ context
828
874
  );
829
875
  return verification;
830
876
  }
@@ -1249,6 +1295,9 @@ var memoryAdapter = (db) => (options) => {
1249
1295
  }
1250
1296
  return table.map((record) => transformOutput(record, model));
1251
1297
  },
1298
+ count: async ({ model }) => {
1299
+ return db[model].length;
1300
+ },
1252
1301
  update: async ({ model, where, update }) => {
1253
1302
  const table = db[model];
1254
1303
  const res = convertWhereClause(where, table, model);
@@ -1858,6 +1907,19 @@ var kyselyAdapter = (db, config) => (opts) => {
1858
1907
  const res = await query.execute();
1859
1908
  return res.length;
1860
1909
  },
1910
+ async count(data) {
1911
+ const { model, where } = data;
1912
+ const { and, or } = convertWhereClause(model, where);
1913
+ let query = db.selectFrom(getModelName(model)).select(db.fn.count("id").as("count"));
1914
+ if (and) {
1915
+ query = query.where((eb) => eb.and(and.map((expr) => expr(eb))));
1916
+ }
1917
+ if (or) {
1918
+ query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
1919
+ }
1920
+ const res = await query.execute();
1921
+ return res[0].count;
1922
+ },
1861
1923
  async delete(data) {
1862
1924
  const { model, where } = data;
1863
1925
  const { and, or } = convertWhereClause(model, where);
@@ -70,10 +70,6 @@ async function parseState(c) {
70
70
  parsedData.errorURL = `${c.context.baseURL}/error`;
71
71
  }
72
72
  if (parsedData.expiresAt < Date.now()) {
73
- await c.context.internalAdapter.deleteVerificationValue(data.id);
74
- c.context.logger.error("State expired.", {
75
- state
76
- });
77
73
  throw c.redirect(
78
74
  `${c.context.baseURL}/error?error=please_restart_the_process`
79
75
  );