@better-auth/cli 1.4.12-beta.2 → 1.4.13

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 +111 -69
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -131,10 +131,10 @@ const generateDrizzleSchema = async ({ options, file, adapter }) => {
131
131
  else if (databaseType === "mysql") id = `varchar('id', { length: 36 }).primaryKey()`;
132
132
  else if (databaseType === "pg") id = `text('id').primaryKey()`;
133
133
  else id = `text('id').primaryKey()`;
134
- let indexes = [];
134
+ const indexes = [];
135
135
  const assignIndexes = (indexes$1) => {
136
136
  if (!indexes$1.length) return "";
137
- let code$1 = [`, (table) => [`];
137
+ const code$1 = [`, (table) => [`];
138
138
  for (const index of indexes$1) code$1.push(` ${index.type}("${index.name}").on(table.${index.on}),`);
139
139
  code$1.push(`]`);
140
140
  return code$1.join("\n");
@@ -469,7 +469,7 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
469
469
  fieldBuilder.attribute(`default("${JSON.stringify(attr.defaultValue).replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}")`);
470
470
  continue;
471
471
  }
472
- let jsonArray = [];
472
+ const jsonArray = [];
473
473
  for (const value of attr.defaultValue) jsonArray.push(value);
474
474
  fieldBuilder.attribute(`default("${JSON.stringify(jsonArray).replace(/"/g, "\\\"")}")`);
475
475
  continue;
@@ -478,11 +478,11 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
478
478
  fieldBuilder.attribute(`default([])`);
479
479
  continue;
480
480
  } else if (typeof attr.defaultValue[0] === "string" && attr.type === "string[]") {
481
- let valueArray = [];
481
+ const valueArray = [];
482
482
  for (const value of attr.defaultValue) valueArray.push(JSON.stringify(value));
483
483
  fieldBuilder.attribute(`default([${valueArray}])`);
484
484
  } else if (typeof attr.defaultValue[0] === "number") {
485
- let valueArray = [];
485
+ const valueArray = [];
486
486
  for (const value of attr.defaultValue) valueArray.push(`${value}`);
487
487
  fieldBuilder.attribute(`default([${valueArray}])`);
488
488
  }
@@ -1514,9 +1514,9 @@ async function generateAuthConfig({ format: format$1, current_user_config, spinn
1514
1514
  };
1515
1515
  const config_generation = {
1516
1516
  add_plugin: async (opts) => {
1517
- let start_of_plugins = getGroupInfo(opts.config, common_indexes.START_OF_PLUGINS, {});
1517
+ const start_of_plugins = getGroupInfo(opts.config, common_indexes.START_OF_PLUGINS, {});
1518
1518
  if (!start_of_plugins) throw new Error("Couldn't find start of your plugins array in your auth config file.");
1519
- let end_of_plugins = getGroupInfo(opts.config, common_indexes.END_OF_PLUGINS, { start_of_plugins: start_of_plugins.index });
1519
+ const end_of_plugins = getGroupInfo(opts.config, common_indexes.END_OF_PLUGINS, { start_of_plugins: start_of_plugins.index });
1520
1520
  if (!end_of_plugins) throw new Error("Couldn't find end of your plugins array in your auth config file.");
1521
1521
  let new_content;
1522
1522
  if (opts.direction_in_plugins_array === "prepend") new_content = insertContent({
@@ -1570,7 +1570,7 @@ async function generateAuthConfig({ format: format$1, current_user_config, spinn
1570
1570
  let database_code_str = "";
1571
1571
  async function add_db({ db_code, dependencies, envs, imports, code_before_betterAuth }) {
1572
1572
  if (code_before_betterAuth) {
1573
- let start_of_betterauth$1 = getGroupInfo(opts.config, common_indexes.START_OF_BETTERAUTH, {});
1573
+ const start_of_betterauth$1 = getGroupInfo(opts.config, common_indexes.START_OF_BETTERAUTH, {});
1574
1574
  if (!start_of_betterauth$1) throw new Error("Couldn't find start of betterAuth() function.");
1575
1575
  opts.config = insertContent({
1576
1576
  line: start_of_betterauth$1.line - 1,
@@ -1718,7 +1718,7 @@ async function generateAuthConfig({ format: format$1, current_user_config, spinn
1718
1718
  variables: [{ name: "MongoClient" }]
1719
1719
  }]
1720
1720
  });
1721
- let start_of_betterauth = getGroupInfo(opts.config, common_indexes.START_OF_BETTERAUTH, {});
1721
+ const start_of_betterauth = getGroupInfo(opts.config, common_indexes.START_OF_BETTERAUTH, {});
1722
1722
  if (!start_of_betterauth) throw new Error("Couldn't find start of betterAuth() function.");
1723
1723
  let new_content;
1724
1724
  new_content = insertContent({
@@ -1741,8 +1741,8 @@ async function generateAuthConfig({ format: format$1, current_user_config, spinn
1741
1741
  }
1742
1742
  };
1743
1743
  let new_user_config = await format$1(current_user_config);
1744
- let total_dependencies = [];
1745
- let total_envs = [];
1744
+ const total_dependencies = [];
1745
+ const total_envs = [];
1746
1746
  if (plugins.length !== 0) {
1747
1747
  const imports = [];
1748
1748
  for await (const plugin of plugins) {
@@ -2186,7 +2186,7 @@ const getDefaultAuthClientConfig = async ({ auth_config_path, framework, clientP
2186
2186
  }
2187
2187
  return result;
2188
2188
  }
2189
- let imports = groupImportVariables();
2189
+ const imports = groupImportVariables();
2190
2190
  let importString = "";
2191
2191
  for (const import_ of imports) if (Array.isArray(import_.variables)) importString += `import { ${import_.variables.map((x) => `${x.asType ? "type " : ""}${x.name}${x.as ? ` as ${x.as}` : ""}`).join(", ")} } from "${import_.path}";\n`;
2192
2192
  else importString += `import ${import_.variables.asType ? "type " : ""}${import_.variables.name}${import_.variables.as ? ` as ${import_.variables.as}` : ""} from "${import_.path}";\n`;
@@ -2584,7 +2584,7 @@ async function initAction(opts) {
2584
2584
  authClientConfigPath = path.join(cwd, "auth-client.ts");
2585
2585
  log.info(`Creating auth client config file: ${authClientConfigPath}`);
2586
2586
  try {
2587
- let contents = await getDefaultAuthClientConfig({
2587
+ const contents = await getDefaultAuthClientConfig({
2588
2588
  auth_config_path: ("./" + path.join(config_path.replace(cwd, ""))).replace(".//", "./"),
2589
2589
  clientPlugins: add_plugins.filter((x) => x.clientName).map((plugin) => {
2590
2590
  let contents$1 = "";
@@ -2643,7 +2643,7 @@ async function initAction(opts) {
2643
2643
  cancel(`āœ‹ Operation cancelled.`);
2644
2644
  process.exit(0);
2645
2645
  }
2646
- let envs = [];
2646
+ const envs = [];
2647
2647
  if (isMissingSecret) envs.push("BETTER_AUTH_SECRET");
2648
2648
  if (isMissingUrl) envs.push("BETTER_AUTH_URL");
2649
2649
  if (shouldAdd === "yes") {
@@ -2727,7 +2727,7 @@ async function getPackageManager() {
2727
2727
  value: "npm",
2728
2728
  hint: "not recommended"
2729
2729
  });
2730
- let packageManager = await select({
2730
+ const packageManager = await select({
2731
2731
  message: "Choose a package manager",
2732
2732
  options: packageManagerOptions
2733
2733
  });
@@ -2913,69 +2913,100 @@ const login = new Command("login").description("Demo: Test device authorization
2913
2913
 
2914
2914
  //#endregion
2915
2915
  //#region src/commands/mcp.ts
2916
+ const REMOTE_MCP_URL = "https://mcp.chonkie.ai/better-auth/better-auth-builder/mcp";
2917
+ const LOCAL_MCP_COMMAND = "npx @better-auth/mcp";
2916
2918
  async function mcpAction(options) {
2917
- const mcpUrl = "https://mcp.chonkie.ai/better-auth/better-auth-builder/mcp";
2918
- const mcpName = "better-auth";
2919
- if (options.cursor) await handleCursorAction(mcpUrl, mcpName);
2920
- else if (options.claudeCode) handleClaudeCodeAction(mcpUrl);
2921
- else if (options.openCode) handleOpenCodeAction(mcpUrl);
2922
- else if (options.manual) handleManualAction(mcpUrl, mcpName);
2923
- else showAllOptions(mcpUrl, mcpName);
2919
+ const installLocal = !options.remoteOnly;
2920
+ const installRemote = !options.localOnly;
2921
+ if (options.cursor) await handleCursorAction(installLocal, installRemote);
2922
+ else if (options.claudeCode) handleClaudeCodeAction(installLocal, installRemote);
2923
+ else if (options.openCode) handleOpenCodeAction(installLocal, installRemote);
2924
+ else if (options.manual) handleManualAction(installLocal, installRemote);
2925
+ else showAllOptions();
2924
2926
  }
2925
- async function handleCursorAction(mcpUrl, mcpName) {
2926
- const mcpConfig = { url: mcpUrl };
2927
- const encodedConfig = base64.encode(new TextEncoder().encode(JSON.stringify(mcpConfig)));
2928
- const deeplinkUrl = `cursor://anysphere.cursor-deeplink/mcp/install?name=${encodeURIComponent(mcpName)}&config=${encodedConfig}`;
2927
+ async function handleCursorAction(installLocal, installRemote) {
2929
2928
  console.log(chalk.bold.blue("šŸš€ Adding Better Auth MCP to Cursor..."));
2930
- try {
2931
- const platform = os$1.platform();
2932
- let command;
2933
- switch (platform) {
2934
- case "darwin":
2935
- command = `open "${deeplinkUrl}"`;
2936
- break;
2937
- case "win32":
2938
- command = `start "" "${deeplinkUrl}"`;
2939
- break;
2940
- case "linux":
2941
- command = `xdg-open "${deeplinkUrl}"`;
2942
- break;
2943
- default: throw new Error(`Unsupported platform: ${platform}`);
2929
+ const platform = os$1.platform();
2930
+ let openCommand;
2931
+ switch (platform) {
2932
+ case "darwin":
2933
+ openCommand = "open";
2934
+ break;
2935
+ case "win32":
2936
+ openCommand = "start";
2937
+ break;
2938
+ case "linux":
2939
+ openCommand = "xdg-open";
2940
+ break;
2941
+ default: throw new Error(`Unsupported platform: ${platform}`);
2942
+ }
2943
+ const installed = [];
2944
+ if (installRemote) {
2945
+ const remoteConfig = { url: REMOTE_MCP_URL };
2946
+ const encodedRemote = base64.encode(new TextEncoder().encode(JSON.stringify(remoteConfig)));
2947
+ const remoteDeeplink = `cursor://anysphere.cursor-deeplink/mcp/install?name=${encodeURIComponent("better-auth-docs")}&config=${encodedRemote}`;
2948
+ try {
2949
+ execSync(platform === "win32" ? `start "" "${remoteDeeplink}"` : `${openCommand} "${remoteDeeplink}"`, { stdio: "inherit" });
2950
+ installed.push("better-auth-docs (remote - documentation & search)");
2951
+ } catch {
2952
+ console.log(chalk.yellow("\n⚠ Could not automatically open Cursor for remote MCP."));
2944
2953
  }
2945
- execSync(command, { stdio: "inherit" });
2946
- console.log(chalk.green("\nāœ“ Cursor MCP installed successfully!"));
2947
- } catch {
2948
- console.log(chalk.yellow("\n⚠ Could not automatically open Cursor. Please copy the deeplink URL above and open it manually."));
2949
- console.log(chalk.gray("\nYou can also manually add this configuration to your Cursor MCP settings:"));
2950
- console.log(chalk.gray(JSON.stringify(mcpConfig, null, 2)));
2954
+ }
2955
+ if (installLocal) {
2956
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
2957
+ const localConfig = { command: LOCAL_MCP_COMMAND };
2958
+ const encodedLocal = base64.encode(new TextEncoder().encode(JSON.stringify(localConfig)));
2959
+ const localDeeplink = `cursor://anysphere.cursor-deeplink/mcp/install?name=${encodeURIComponent("better-auth")}&config=${encodedLocal}`;
2960
+ try {
2961
+ execSync(platform === "win32" ? `start "" "${localDeeplink}"` : `${openCommand} "${localDeeplink}"`, { stdio: "inherit" });
2962
+ installed.push("better-auth (local - setup & diagnostics)");
2963
+ } catch {
2964
+ console.log(chalk.yellow("\n⚠ Could not automatically open Cursor for local MCP."));
2965
+ }
2966
+ }
2967
+ if (installed.length > 0) {
2968
+ console.log(chalk.green("\nāœ“ Cursor MCP servers installed:"));
2969
+ for (const name of installed) console.log(chalk.green(` • ${name}`));
2951
2970
  }
2952
2971
  console.log(chalk.bold.white("\n✨ Next Steps:"));
2953
- console.log(chalk.gray("• The MCP server will be added to your Cursor configuration"));
2972
+ console.log(chalk.gray("• The MCP servers will be added to your Cursor configuration"));
2954
2973
  console.log(chalk.gray("• You can now use Better Auth features directly in Cursor"));
2974
+ console.log(chalk.gray("• Try: \"Set up Better Auth with Google login\" or \"Help me debug my auth\""));
2955
2975
  }
2956
- function handleClaudeCodeAction(mcpUrl) {
2976
+ function handleClaudeCodeAction(installLocal, installRemote) {
2957
2977
  console.log(chalk.bold.blue("šŸ¤– Adding Better Auth MCP to Claude Code..."));
2958
- const command = `claude mcp add --transport http better-auth ${mcpUrl}`;
2959
- try {
2978
+ const commands = [];
2979
+ if (installRemote) commands.push(`claude mcp add --transport http better-auth-docs ${REMOTE_MCP_URL}`);
2980
+ if (installLocal) commands.push(`claude mcp add better-auth -- ${LOCAL_MCP_COMMAND}`);
2981
+ let anySucceeded = false;
2982
+ for (const command of commands) try {
2960
2983
  execSync(command, { stdio: "inherit" });
2961
- console.log(chalk.green("\nāœ“ Claude Code MCP installed successfully!"));
2984
+ anySucceeded = true;
2962
2985
  } catch {
2963
2986
  console.log(chalk.yellow("\n⚠ Could not automatically add to Claude Code. Please run this command manually:"));
2964
2987
  console.log(chalk.cyan(command));
2965
2988
  }
2989
+ if (anySucceeded) console.log(chalk.green("\nāœ“ Claude Code MCP configured!"));
2966
2990
  console.log(chalk.bold.white("\n✨ Next Steps:"));
2967
- console.log(chalk.gray("• The MCP server will be added to your Claude Code configuration"));
2991
+ console.log(chalk.gray("• The MCP servers will be added to your Claude Code configuration"));
2968
2992
  console.log(chalk.gray("• You can now use Better Auth features directly in Claude Code"));
2969
2993
  }
2970
- function handleOpenCodeAction(mcpUrl) {
2994
+ function handleOpenCodeAction(installLocal, installRemote) {
2971
2995
  console.log(chalk.bold.blue("šŸ”§ Adding Better Auth MCP to Open Code..."));
2996
+ const mcpConfig = {};
2997
+ if (installRemote) mcpConfig["better-auth-docs"] = {
2998
+ type: "remote",
2999
+ url: REMOTE_MCP_URL,
3000
+ enabled: true
3001
+ };
3002
+ if (installLocal) mcpConfig["better-auth"] = {
3003
+ type: "stdio",
3004
+ command: LOCAL_MCP_COMMAND,
3005
+ enabled: true
3006
+ };
2972
3007
  const openCodeConfig = {
2973
3008
  $schema: "https://opencode.ai/config.json",
2974
- mcp: { "better-auth": {
2975
- type: "remote",
2976
- url: mcpUrl,
2977
- enabled: true
2978
- } }
3009
+ mcp: mcpConfig
2979
3010
  };
2980
3011
  const configPath = path$1.join(process.cwd(), "opencode.json");
2981
3012
  try {
@@ -2994,18 +3025,20 @@ function handleOpenCodeAction(mcpUrl) {
2994
3025
  };
2995
3026
  fs$2.writeFileSync(configPath, JSON.stringify(mergedConfig, null, 2));
2996
3027
  console.log(chalk.green(`\nāœ“ Open Code configuration written to ${configPath}`));
2997
- console.log(chalk.green("āœ“ Better Auth MCP added successfully!"));
3028
+ console.log(chalk.green("āœ“ Better Auth MCP servers added successfully!"));
2998
3029
  } catch {
2999
3030
  console.log(chalk.yellow("\n⚠ Could not automatically write opencode.json. Please add this configuration manually:"));
3000
3031
  console.log(chalk.cyan(JSON.stringify(openCodeConfig, null, 2)));
3001
3032
  }
3002
3033
  console.log(chalk.bold.white("\n✨ Next Steps:"));
3003
- console.log(chalk.gray("• Restart Open Code to load the new MCP server"));
3034
+ console.log(chalk.gray("• Restart Open Code to load the new MCP servers"));
3004
3035
  console.log(chalk.gray("• You can now use Better Auth features directly in Open Code"));
3005
3036
  }
3006
- function handleManualAction(mcpUrl, mcpName) {
3007
- console.log(chalk.bold.blue("šŸ“ Adding Better Auth MCP Configuration..."));
3008
- const manualConfig = { [mcpName]: { url: mcpUrl } };
3037
+ function handleManualAction(installLocal, installRemote) {
3038
+ console.log(chalk.bold.blue("šŸ“ Better Auth MCP Configuration..."));
3039
+ const manualConfig = {};
3040
+ if (installRemote) manualConfig["better-auth-docs"] = { url: REMOTE_MCP_URL };
3041
+ if (installLocal) manualConfig["better-auth"] = { command: LOCAL_MCP_COMMAND };
3009
3042
  const configPath = path$1.join(process.cwd(), "mcp.json");
3010
3043
  try {
3011
3044
  let existingConfig = {};
@@ -3019,27 +3052,36 @@ function handleManualAction(mcpUrl, mcpName) {
3019
3052
  };
3020
3053
  fs$2.writeFileSync(configPath, JSON.stringify(mergedConfig, null, 2));
3021
3054
  console.log(chalk.green(`\nāœ“ MCP configuration written to ${configPath}`));
3022
- console.log(chalk.green("āœ“ Better Auth MCP added successfully!"));
3055
+ console.log(chalk.green("āœ“ Better Auth MCP servers added successfully!"));
3023
3056
  } catch {
3024
3057
  console.log(chalk.yellow("\n⚠ Could not automatically write mcp.json. Please add this configuration manually:"));
3025
3058
  console.log(chalk.cyan(JSON.stringify(manualConfig, null, 2)));
3026
3059
  }
3027
3060
  console.log(chalk.bold.white("\n✨ Next Steps:"));
3028
- console.log(chalk.gray("• Restart your MCP client to load the new server"));
3061
+ console.log(chalk.gray("• Restart your MCP client to load the new servers"));
3029
3062
  console.log(chalk.gray("• You can now use Better Auth features directly in your MCP client"));
3030
3063
  }
3031
- function showAllOptions(mcpUrl, mcpName) {
3032
- console.log(chalk.bold.blue("šŸ”Œ Better Auth MCP Server"));
3064
+ function showAllOptions() {
3065
+ console.log(chalk.bold.blue("šŸ”Œ Better Auth MCP Servers"));
3033
3066
  console.log(chalk.gray("Choose your MCP client to get started:"));
3034
3067
  console.log();
3035
- console.log(chalk.bold.white("Available Commands:"));
3068
+ console.log(chalk.bold.white("MCP Clients:"));
3036
3069
  console.log(chalk.cyan(" --cursor ") + chalk.gray("Add to Cursor"));
3037
3070
  console.log(chalk.cyan(" --claude-code ") + chalk.gray("Add to Claude Code"));
3038
3071
  console.log(chalk.cyan(" --open-code ") + chalk.gray("Add to Open Code"));
3039
3072
  console.log(chalk.cyan(" --manual ") + chalk.gray("Manual configuration"));
3040
3073
  console.log();
3074
+ console.log(chalk.bold.white("Server Selection:"));
3075
+ console.log(chalk.cyan(" --local-only ") + chalk.gray("Install only local MCP (setup & diagnostics)"));
3076
+ console.log(chalk.cyan(" --remote-only ") + chalk.gray("Install only remote MCP (documentation & search)"));
3077
+ console.log(chalk.gray(" (default: install both servers)"));
3078
+ console.log();
3079
+ console.log(chalk.bold.white("Servers:"));
3080
+ console.log(chalk.gray(" • ") + chalk.white("better-auth") + chalk.gray(" (local) - Setup auth, diagnose issues, validate config"));
3081
+ console.log(chalk.gray(" • ") + chalk.white("better-auth-docs") + chalk.gray(" (remote) - Search documentation, code examples"));
3082
+ console.log();
3041
3083
  }
3042
- const mcp = new Command("mcp").description("Add Better Auth MCP server to MCP Clients").option("--cursor", "Automatically open Cursor with the MCP configuration").option("--claude-code", "Show Claude Code MCP configuration command").option("--open-code", "Show Open Code MCP configuration").option("--manual", "Show manual MCP configuration for mcp.json").action(mcpAction);
3084
+ const mcp = new Command("mcp").description("Add Better Auth MCP servers to MCP Clients").option("--cursor", "Automatically open Cursor with the MCP configuration").option("--claude-code", "Show Claude Code MCP configuration command").option("--open-code", "Show Open Code MCP configuration").option("--manual", "Show manual MCP configuration for mcp.json").option("--local-only", "Install only local MCP server (setup & diagnostics)").option("--remote-only", "Install only remote MCP server (documentation & search)").action(mcpAction);
3043
3085
 
3044
3086
  //#endregion
3045
3087
  //#region src/commands/migrate.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/cli",
3
- "version": "1.4.12-beta.2",
3
+ "version": "1.4.13",
4
4
  "type": "module",
5
5
  "description": "The CLI for Better Auth",
6
6
  "module": "dist/index.mjs",
@@ -37,7 +37,7 @@
37
37
  "tsx": "^4.20.6",
38
38
  "type-fest": "^5.2.0",
39
39
  "typescript": "^5.9.3",
40
- "@better-auth/passkey": "1.4.12-beta.2"
40
+ "@better-auth/passkey": "1.4.13"
41
41
  },
42
42
  "dependencies": {
43
43
  "@babel/core": "^7.28.4",
@@ -61,9 +61,9 @@
61
61
  "semver": "^7.7.2",
62
62
  "yocto-spinner": "^0.2.3",
63
63
  "zod": "^4.1.12",
64
- "@better-auth/core": "1.4.12-beta.2",
65
- "@better-auth/telemetry": "1.4.12-beta.2",
66
- "better-auth": "^1.4.12-beta.2"
64
+ "@better-auth/core": "1.4.13",
65
+ "better-auth": "^1.4.13",
66
+ "@better-auth/telemetry": "1.4.13"
67
67
  },
68
68
  "files": [
69
69
  "dist"