better-auth 1.7.22 → 1.7.23

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/package.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  // package.json
2
- var version = "1.7.22";
2
+ var version = "1.7.23";
3
3
  export { version };
@@ -11,13 +11,22 @@ import { createHash, randomUUID } from "node:crypto";
11
11
  import { afterAll } from "vitest";
12
12
  // src/test-utils/test-instance.ts
13
13
  const cleanupSet = /* @__PURE__ */ new Set();
14
+ const mongodbDatabase = `ba_test_${randomUUID().replaceAll("-", "_")}`;
14
15
  const currentUserContextStorage = new AsyncLocalStorage();
15
- afterAll(async () => {
16
+ /**
17
+ * Runs the cleanup of every instance this file created, such as dropping its
18
+ * database. Each cleanup runs once, even if it throws, since it also closes
19
+ * the connection a retry would need.
20
+ *
21
+ * @internal
22
+ */
23
+ async function cleanupTestInstances() {
16
24
  for (const cleanup of cleanupSet) {
17
- await cleanup();
18
25
  cleanupSet.delete(cleanup);
26
+ await cleanup();
19
27
  }
20
- });
28
+ }
29
+ afterAll(cleanupTestInstances);
21
30
  const TEST_PASSWORD_HASH_PREFIX = "$test$sha256$";
22
31
  /**
23
32
  * Intentionally fast for tests
@@ -60,18 +69,19 @@ async function getTestInstance(options, config) {
60
69
  }
61
70
  return new Kysely({ dialect: new MysqlDialect({ pool: createPool(`${mysqlServerURL}/${mysqlDatabase}`) }) });
62
71
  }
63
- async function mongodbClient() {
72
+ async function getMongodb() {
64
73
  const { MongoClient } = await import("mongodb");
65
- const dbClient = async (connectionString, dbName) => {
66
- const client = new MongoClient(connectionString, {
67
- serverSelectionTimeoutMS: 2e3,
68
- connectTimeoutMS: 2e3
69
- });
70
- await client.connect();
71
- return client.db(dbName);
74
+ const client = new MongoClient("mongodb://127.0.0.1:27017", {
75
+ serverSelectionTimeoutMS: 2e3,
76
+ connectTimeoutMS: 2e3
77
+ });
78
+ await client.connect();
79
+ return {
80
+ client,
81
+ db: client.db(mongodbDatabase)
72
82
  };
73
- return await dbClient("mongodb://127.0.0.1:27017", "better-auth");
74
83
  }
84
+ const mongodb = testWith === "mongodb" ? await getMongodb() : void 0;
75
85
  const postgres = testWith === "postgres" ? await getPostgres() : void 0;
76
86
  const mysql = testWith === "mysql" ? await getMysql() : void 0;
77
87
  const sqlite = testWith === "sqlite" ? await getSqlite() : void 0;
@@ -91,7 +101,7 @@ async function getTestInstance(options, config) {
91
101
  db: postgres,
92
102
  type: "postgres",
93
103
  transaction: config?.transaction
94
- } : testWith === "mongodb" ? await Promise.all([mongodbClient(), await import("../adapters/mongodb-adapter/index.mjs")]).then(([db, { mongodbAdapter }]) => mongodbAdapter(db)) : mysql ? {
104
+ } : mongodb ? await import("../adapters/mongodb-adapter/index.mjs").then(({ mongodbAdapter }) => mongodbAdapter(mongodb.db)) : mysql ? {
95
105
  db: mysql,
96
106
  type: "mysql",
97
107
  transaction: config?.transaction
@@ -102,8 +112,12 @@ async function getTestInstance(options, config) {
102
112
  logger: { level: "debug" }
103
113
  };
104
114
  const cleanup = async () => {
105
- if (testWith === "mongodb") {
106
- await (await mongodbClient()).dropDatabase();
115
+ if (mongodb) {
116
+ try {
117
+ await mongodb.db.dropDatabase();
118
+ } finally {
119
+ await mongodb.client.close();
120
+ }
107
121
  return;
108
122
  }
109
123
  if (postgres) {
@@ -250,4 +264,4 @@ async function getTestInstance(options, config) {
250
264
  }
251
265
  };
252
266
  }
253
- export { getTestInstance };
267
+ export { cleanupTestInstances, getTestInstance };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-auth",
3
- "version": "1.7.22",
3
+ "version": "1.7.23",
4
4
  "description": "The most comprehensive authentication framework for TypeScript.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -493,13 +493,13 @@
493
493
  }
494
494
  },
495
495
  "dependencies": {
496
- "@better-auth/core": "1.7.22",
497
- "@better-auth/drizzle-adapter": "1.7.22",
498
- "@better-auth/kysely-adapter": "1.7.22",
499
- "@better-auth/memory-adapter": "1.7.22",
500
- "@better-auth/mongo-adapter": "1.7.22",
501
- "@better-auth/prisma-adapter": "1.7.22",
502
- "@better-auth/telemetry": "1.7.22",
496
+ "@better-auth/core": "1.7.23",
497
+ "@better-auth/drizzle-adapter": "1.7.23",
498
+ "@better-auth/kysely-adapter": "1.7.23",
499
+ "@better-auth/memory-adapter": "1.7.23",
500
+ "@better-auth/mongo-adapter": "1.7.23",
501
+ "@better-auth/prisma-adapter": "1.7.23",
502
+ "@better-auth/telemetry": "1.7.23",
503
503
  "@better-auth/utils": "0.5.1",
504
504
  "@better-fetch/fetch": "1.3.3",
505
505
  "@noble/ciphers": "^2.2.0",