auth 1.7.0-beta.2 → 1.7.0-beta.3

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 (2) hide show
  1. package/dist/index.mjs +46 -62
  2. package/package.json +7 -7
package/dist/index.mjs CHANGED
@@ -1648,66 +1648,56 @@ const jitiOptions = (cwd) => {
1648
1648
  alias: getVirtualModuleAliases()
1649
1649
  };
1650
1650
  };
1651
- const isDefaultExport = (object) => {
1652
- return typeof object === "object" && object !== null && !Array.isArray(object) && Object.keys(object).length > 0 && "options" in object;
1651
+ /**
1652
+ * Picks the auth instance from the loaded module, supporting `export const auth`,
1653
+ * `export default auth`, and `export default { auth }`. Falls back to the raw
1654
+ * module as a defensive default.
1655
+ */
1656
+ const resolveAuthModule = (mod) => {
1657
+ const m = mod;
1658
+ return m?.auth ?? m?.default?.auth ?? m?.default ?? mod;
1653
1659
  };
1660
+ const isServerOnlyError = (e) => typeof e === "object" && e !== null && "message" in e && typeof e.message === "string" && e.message.includes("This module cannot be imported from a Client Component module");
1661
+ const SERVER_ONLY_HINT = `Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`;
1654
1662
  async function getConfig({ cwd, configPath, shouldThrowOnError = false }) {
1663
+ const fail = (message, error) => {
1664
+ if (shouldThrowOnError) throw error instanceof Error ? error : new Error(message);
1665
+ const log = `[#better-auth]: ${message}`;
1666
+ if (error) console.error(log, error);
1667
+ else console.error(log);
1668
+ process.exit(1);
1669
+ };
1670
+ const load = (configFile) => loadConfig({
1671
+ configFile,
1672
+ dotenv: { fileName: [".env", ".env.local"] },
1673
+ jitiOptions: jitiOptions(cwd),
1674
+ resolveModule: resolveAuthModule,
1675
+ cwd
1676
+ });
1655
1677
  try {
1656
- let configFile = null;
1657
1678
  if (configPath) {
1658
- let resolvedPath = path.join(cwd, configPath);
1659
- if (existsSync(configPath)) resolvedPath = configPath;
1660
- const { config } = await loadConfig({
1661
- configFile: resolvedPath,
1662
- dotenv: { fileName: [".env", ".env.local"] },
1663
- jitiOptions: jitiOptions(cwd),
1664
- cwd
1665
- });
1666
- if (!("auth" in config) && !isDefaultExport(config)) {
1667
- if (shouldThrowOnError) throw new Error(`Couldn't read your auth config in ${resolvedPath}. Make sure to default export your auth instance or to export as a variable named auth.`);
1668
- console.error(`[#better-auth]: Couldn't read your auth config in ${resolvedPath}. Make sure to default export your auth instance or to export as a variable named auth.`);
1669
- process.exit(1);
1670
- }
1671
- configFile = "auth" in config ? config.auth?.options : config.options;
1679
+ const resolvedPath = existsSync(configPath) ? configPath : path.join(cwd, configPath);
1680
+ const { config } = await load(resolvedPath);
1681
+ const options = config?.options;
1682
+ if (!options) return fail(`Couldn't read your auth config in ${resolvedPath}. Make sure to default export your auth instance or to export as a variable named auth.`);
1683
+ return options;
1672
1684
  }
1673
- if (!configFile) for (const possiblePath of possiblePaths$1) try {
1674
- const { config } = await loadConfig({
1675
- configFile: possiblePath,
1676
- dotenv: { fileName: [".env", ".env.local"] },
1677
- jitiOptions: jitiOptions(cwd),
1678
- cwd
1679
- });
1680
- if (Object.keys(config).length > 0) {
1681
- configFile = config.auth?.options || config.default?.options || null;
1682
- if (!configFile) {
1683
- if (shouldThrowOnError) throw new Error("Couldn't read your auth config. Make sure to default export your auth instance or to export as a variable named auth.");
1684
- console.error("[#better-auth]: Couldn't read your auth config.");
1685
- console.log("");
1686
- console.log("[#better-auth]: Make sure to default export your auth instance or to export as a variable named auth.");
1687
- process.exit(1);
1688
- }
1689
- break;
1690
- }
1691
- } catch (e) {
1692
- if (typeof e === "object" && e && "message" in e && typeof e.message === "string" && e.message.includes("This module cannot be imported from a Client Component module")) {
1693
- if (shouldThrowOnError) throw new Error(`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`);
1694
- console.error(`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`);
1695
- process.exit(1);
1685
+ for (const possiblePath of possiblePaths$1) {
1686
+ let config;
1687
+ try {
1688
+ ({config} = await load(possiblePath));
1689
+ } catch (e) {
1690
+ if (isServerOnlyError(e)) return fail(SERVER_ONLY_HINT);
1691
+ return fail("Couldn't read your auth config.", e);
1696
1692
  }
1697
- if (shouldThrowOnError) throw e;
1698
- console.error("[#better-auth]: Couldn't read your auth config.", e);
1699
- process.exit(1);
1693
+ if (Object.keys(config).length === 0) continue;
1694
+ if (!config.options) return fail("Couldn't read your auth config. Make sure to default export your auth instance or to export as a variable named auth.");
1695
+ return config.options;
1700
1696
  }
1701
- return configFile;
1697
+ return null;
1702
1698
  } catch (e) {
1703
- if (typeof e === "object" && e && "message" in e && typeof e.message === "string" && e.message.includes("This module cannot be imported from a Client Component module")) {
1704
- if (shouldThrowOnError) throw new Error(`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`);
1705
- console.error(`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`);
1706
- process.exit(1);
1707
- }
1708
- if (shouldThrowOnError) throw e;
1709
- console.error("Couldn't read your auth config.", e);
1710
- process.exit(1);
1699
+ if (isServerOnlyError(e)) return fail(SERVER_ONLY_HINT);
1700
+ return fail("Couldn't read your auth config.", e);
1711
1701
  }
1712
1702
  }
1713
1703
  //#endregion
@@ -5277,12 +5267,9 @@ const databasesConfig = [
5277
5267
  imports: [createImport({ name: "createPool" })],
5278
5268
  isNamedImport: false
5279
5269
  }],
5280
- preCode: `const dialect = createPool({ host: "localhost", user: "root", password: "password", database: "database", timezone: "Z" })`,
5270
+ preCode: `const database = createPool({ host: "localhost", user: "root", password: "password", database: "database", timezone: "Z" })`,
5281
5271
  code({ additionalOptions }) {
5282
- return kyselyCode({
5283
- provider: "mysql",
5284
- additionalOptions
5285
- });
5272
+ return `database`;
5286
5273
  },
5287
5274
  dependencies: ["mysql2"]
5288
5275
  },
@@ -5293,12 +5280,9 @@ const databasesConfig = [
5293
5280
  imports: [createImport({ name: "Pool" })],
5294
5281
  isNamedImport: false
5295
5282
  }],
5296
- preCode: `const dialect = new Pool({ connectionString: "postgresql://postgres:password@localhost:5432/database" })`,
5283
+ preCode: `const database = new Pool({ connectionString: "postgresql://postgres:password@localhost:5432/database" })`,
5297
5284
  code({ additionalOptions }) {
5298
- return kyselyCode({
5299
- provider: "postgresql",
5300
- additionalOptions
5301
- });
5285
+ return `database`;
5302
5286
  },
5303
5287
  dependencies: ["pg"],
5304
5288
  devDependencies: ["@types/pg"]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auth",
3
- "version": "1.7.0-beta.2",
3
+ "version": "1.7.0-beta.3",
4
4
  "description": "The CLI for Better Auth",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -49,33 +49,33 @@
49
49
  "@better-auth/utils": "0.4.0",
50
50
  "@clack/prompts": "^0.11.0",
51
51
  "@mrleebo/prisma-ast": "^0.13.1",
52
- "c12": "^3.3.3",
52
+ "c12": "^4.0.0-beta.5",
53
53
  "chalk": "^5.6.2",
54
54
  "commander": "^12.1.0",
55
55
  "dotenv": "^17.3.1",
56
56
  "get-tsconfig": "^4.13.6",
57
+ "jiti": "^2.7.0",
57
58
  "open": "^10.2.0",
58
59
  "prettier": "^3.8.1",
59
60
  "prompts": "^2.4.2",
60
61
  "semver": "^7.7.4",
61
62
  "yocto-spinner": "^0.2.3",
62
63
  "zod": "^4.3.6",
63
- "@better-auth/core": "1.7.0-beta.2",
64
- "@better-auth/telemetry": "1.7.0-beta.2",
65
- "better-auth": "1.7.0-beta.2"
64
+ "@better-auth/core": "1.7.0-beta.3",
65
+ "@better-auth/telemetry": "1.7.0-beta.3",
66
+ "better-auth": "1.7.0-beta.3"
66
67
  },
67
68
  "devDependencies": {
68
69
  "@types/better-sqlite3": "^7.6.13",
69
70
  "@types/prompts": "^2.4.9",
70
71
  "@types/semver": "^7.7.1",
71
72
  "better-sqlite3": "^12.6.2",
72
- "jiti": "^2.6.1",
73
73
  "memfs": "^4.56.10",
74
74
  "tsdown": "0.21.1",
75
75
  "tsx": "^4.21.0",
76
76
  "type-fest": "^5.4.4",
77
77
  "typescript": "^5.9.3",
78
- "@better-auth/passkey": "1.7.0-beta.2"
78
+ "@better-auth/passkey": "1.7.0-beta.3"
79
79
  },
80
80
  "scripts": {
81
81
  "build": "tsdown",