auth 1.5.6 → 1.5.7-beta.1

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/index.mjs CHANGED
@@ -32,7 +32,6 @@ import { log } from "@clack/prompts";
32
32
  import { base64 } from "@better-auth/utils/base64";
33
33
  import * as semver from "semver";
34
34
  import "dotenv/config";
35
-
36
35
  //#region src/commands/ai.ts
37
36
  const PROTOCOL_URL = "https://agent-auth-protocol.com";
38
37
  const AGENT_CLI_PKG = "@auth/agent-cli";
@@ -577,7 +576,6 @@ function showNextSteps(lines) {
577
576
  for (const line of lines) console.log(` ${line}`);
578
577
  }
579
578
  const ai = new Command("ai").description("Interactive setup for Agent Auth — AI agent authentication").action(aiAction);
580
-
581
579
  //#endregion
582
580
  //#region src/generators/drizzle.ts
583
581
  function convertToSnakeCase(str, camelCase) {
@@ -710,7 +708,7 @@ const generateDrizzleSchema = async ({ options, file, adapter }) => {
710
708
  if (attr.onUpdate && attr.type === "date") {
711
709
  if (typeof attr.onUpdate === "function") type += `.$onUpdate(${attr.onUpdate})`;
712
710
  }
713
- return `${fieldName}: ${type}${attr.required ? ".notNull()" : ""}${attr.unique ? ".unique()" : ""}${attr.references ? `.references(()=> ${getModelName(attr.references.model)}.${getFieldName({
711
+ return `${fieldName}: ${type}${attr.required !== false ? ".notNull()" : ""}${attr.unique ? ".unique()" : ""}${attr.references ? `.references(()=> ${getModelName(attr.references.model)}.${getFieldName({
714
712
  model: attr.references.model,
715
713
  field: attr.references.field
716
714
  })}, { onDelete: '${attr.references.onDelete || "cascade"}' })` : ""}`;
@@ -867,7 +865,6 @@ function generateImport({ databaseType, tables, options }) {
867
865
  if (hasUniqueIndexes) coreImports.push("uniqueIndex");
868
866
  return `${rootImports.length > 0 ? `import { ${rootImports.join(", ")} } from "drizzle-orm";\n` : ""}import { ${coreImports.map((x) => x.trim()).filter((x) => x !== "").join(", ")} } from "drizzle-orm/${databaseType}-core";\n`;
869
867
  }
870
-
871
868
  //#endregion
872
869
  //#region src/generators/kysely.ts
873
870
  const generateKyselySchema = async ({ options, file }) => {
@@ -878,7 +875,6 @@ const generateKyselySchema = async ({ options, file }) => {
878
875
  fileName: file || `./better-auth_migrations/${(/* @__PURE__ */ new Date()).toISOString().replace(/:/g, "-")}.sql`
879
876
  };
880
877
  };
881
-
882
878
  //#endregion
883
879
  //#region src/utils/helper.ts
884
880
  async function tryCatch(promise) {
@@ -910,7 +906,6 @@ const spawnCommand = (cmd, cwd = process.cwd()) => new Promise((resolve, reject)
910
906
  });
911
907
  child.on("error", reject);
912
908
  });
913
-
914
909
  //#endregion
915
910
  //#region src/utils/get-package-info.ts
916
911
  function getPackageInfo(cwd) {
@@ -982,7 +977,6 @@ async function findMonorepoRoot(startDir) {
982
977
  }
983
978
  return null;
984
979
  }
985
-
986
980
  //#endregion
987
981
  //#region src/generators/prisma.ts
988
982
  const generatePrismaSchema = async ({ adapter, options, file }) => {
@@ -1092,7 +1086,7 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
1092
1086
  type: "number"
1093
1087
  }) : getType({
1094
1088
  isBigint: attr?.bigint || false,
1095
- isOptional: !attr?.required,
1089
+ isOptional: attr?.required === false,
1096
1090
  type: attr.references?.field === "id" ? useNumberId ? "number" : "string" : attr.type
1097
1091
  }));
1098
1092
  if (field === "id") {
@@ -1154,7 +1148,7 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
1154
1148
  model: attr.references.model,
1155
1149
  field: attr.references.field
1156
1150
  })}], onDelete: ${action})`;
1157
- builder.model(modelName).field(referencedCustomModelName.toLowerCase(), `${capitalizeFirstLetter(referencedCustomModelName)}${!attr.required ? "?" : ""}`).attribute(relationField);
1151
+ builder.model(modelName).field(referencedCustomModelName.toLowerCase(), `${capitalizeFirstLetter(referencedCustomModelName)}${attr.required === false ? "?" : ""}`).attribute(relationField);
1158
1152
  }
1159
1153
  if (!attr.unique && !attr.references && provider === "mysql" && attr.type === "string") builder.model(modelName).field(fieldName).attribute("db.Text");
1160
1154
  }
@@ -1219,7 +1213,6 @@ const getNewPrisma = (provider, cwd) => {
1219
1213
  url = ${provider === "sqlite" ? `"file:./dev.db"` : `env("DATABASE_URL")`}
1220
1214
  }`;
1221
1215
  };
1222
-
1223
1216
  //#endregion
1224
1217
  //#region src/generators/index.ts
1225
1218
  const adapters = {
@@ -1238,7 +1231,6 @@ const generateSchema = (opts) => {
1238
1231
  }));
1239
1232
  throw new Error(`${adapter.id} is not supported. If it is a custom adapter, please request the maintainer to implement createSchema`);
1240
1233
  };
1241
-
1242
1234
  //#endregion
1243
1235
  //#region src/utils/add-cloudflare-modules.ts
1244
1236
  const createModule = () => {
@@ -1313,7 +1305,6 @@ function addCloudflareModules(aliases, _cwd) {
1313
1305
  if (!aliases["cloudflare:workers"]) aliases["cloudflare:workers"] = CLOUDFLARE_STUB_MODULE;
1314
1306
  if (!aliases["cloudflare:test"]) aliases["cloudflare:test"] = CLOUDFLARE_STUB_MODULE;
1315
1307
  }
1316
-
1317
1308
  //#endregion
1318
1309
  //#region src/utils/add-svelte-kit-env-modules.ts
1319
1310
  /**
@@ -1464,7 +1455,6 @@ const reserved = new Set([
1464
1455
  "implements",
1465
1456
  "instanceof"
1466
1457
  ]);
1467
-
1468
1458
  //#endregion
1469
1459
  //#region src/utils/get-config.ts
1470
1460
  let possiblePaths$1 = [
@@ -1641,7 +1631,6 @@ async function getConfig({ cwd, configPath, shouldThrowOnError = false }) {
1641
1631
  process.exit(1);
1642
1632
  }
1643
1633
  }
1644
-
1645
1634
  //#endregion
1646
1635
  //#region src/commands/generate.ts
1647
1636
  function createMockAdapter$1(adapterId, dialect) {
@@ -1815,7 +1804,6 @@ async function generateAction(opts) {
1815
1804
  process.exit(0);
1816
1805
  }
1817
1806
  const generate = new Command("generate").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("--config <config>", "the path to the configuration file. defaults to the first configuration file found.").option("--output <output>", "the file to output to the generated schema").option("--adapter <adapter>", "specify the adapter type (e.g., prisma, drizzle, kysely) without requiring a configured adapter").option("--dialect <dialect>", "specify the database dialect/provider (e.g., postgresql, mysql, sqlite). For drizzle, postgresql maps to 'pg'").option("-y, --yes", "automatically answer yes to all prompts", false).option("--y", "(deprecated) same as --yes", false).action(generateAction);
1818
-
1819
1807
  //#endregion
1820
1808
  //#region src/commands/info.ts
1821
1809
  function getSystemInfo() {
@@ -2178,7 +2166,6 @@ ${JSON.stringify(betterAuthInfo, null, 2)}
2178
2166
  }
2179
2167
  }
2180
2168
  });
2181
-
2182
2169
  //#endregion
2183
2170
  //#region src/utils/check-package-managers.ts
2184
2171
  async function checkPackageManagers() {
@@ -2268,7 +2255,6 @@ async function getVersion(pkgManager) {
2268
2255
  });
2269
2256
  });
2270
2257
  }
2271
-
2272
2258
  //#endregion
2273
2259
  //#region src/utils/config-paths.ts
2274
2260
  let possiblePaths = [
@@ -2329,7 +2315,6 @@ _possibleClientConfigPaths = [
2329
2315
  ..._possibleClientConfigPaths.map((it) => `app/${it}`)
2330
2316
  ];
2331
2317
  const possibleClientConfigPaths = _possibleClientConfigPaths;
2332
-
2333
2318
  //#endregion
2334
2319
  //#region src/utils/install-dependencies.ts
2335
2320
  const flagsMap = {
@@ -2396,7 +2381,6 @@ function installDependencies({ dependencies, packageManager, cwd, type = "prod",
2396
2381
  });
2397
2382
  });
2398
2383
  }
2399
-
2400
2384
  //#endregion
2401
2385
  //#region src/commands/init/configs/frameworks.config.ts
2402
2386
  const FRAMEWORKS = [
@@ -2601,7 +2585,6 @@ export const Route = createFileRoute('/api/auth/$')({
2601
2585
  configPaths: ["nitro.config.ts"]
2602
2586
  }
2603
2587
  ];
2604
-
2605
2588
  //#endregion
2606
2589
  //#region src/commands/init/configs/social-providers.config.ts
2607
2590
  const SOCIAL_PROVIDERS = [
@@ -2886,13 +2869,11 @@ const SOCIAL_PROVIDER_CONFIGS = {
2886
2869
  envVar: "ZOOM_CLIENT_SECRET"
2887
2870
  }] }
2888
2871
  };
2889
-
2890
2872
  //#endregion
2891
2873
  //#region src/commands/init/utility/format.ts
2892
2874
  const formatCode = async (code) => {
2893
2875
  return await format(code, { parser: "typescript" });
2894
2876
  };
2895
-
2896
2877
  //#endregion
2897
2878
  //#region src/commands/init/utility/imports.ts
2898
2879
  /**
@@ -2948,7 +2929,6 @@ const groupImports = (imports) => {
2948
2929
  return a.path.localeCompare(b.path);
2949
2930
  });
2950
2931
  };
2951
-
2952
2932
  //#endregion
2953
2933
  //#region src/commands/init/configs/temp-plugins.config.ts
2954
2934
  const tempPluginsConfig = {
@@ -4619,7 +4599,6 @@ const tempPluginsConfig = {
4619
4599
  }
4620
4600
  }
4621
4601
  };
4622
-
4623
4602
  //#endregion
4624
4603
  //#region src/commands/init/utility/prompt.ts
4625
4604
  const getFlagVariable = (flag) => {
@@ -4726,7 +4705,6 @@ const getArgumentsPrompt = async (options, plugins, target) => {
4726
4705
  return arg.isRequired && arg.defaultValue !== void 0 ? arg.defaultValue : void 0;
4727
4706
  };
4728
4707
  };
4729
-
4730
4708
  //#endregion
4731
4709
  //#region src/commands/init/utility/plugin.ts
4732
4710
  const getPluginConfigs = (plugins) => {
@@ -4899,7 +4877,6 @@ const getAuthClientPluginsCode = async ({ plugins, options = {}, installDependen
4899
4877
  }
4900
4878
  return (await formatCode(`[${pluginsCode.join(", ")}]`)).trim().slice(0, -1);
4901
4879
  };
4902
-
4903
4880
  //#endregion
4904
4881
  //#region src/commands/init/utility/auth-config.ts
4905
4882
  const generateInnerAuthConfigCode = async ({ database, plugins, appName, baseURL, emailAndPassword, socialProviders, options, installDependency }) => {
@@ -4962,7 +4939,6 @@ const getDatabaseCode$1 = (database) => {
4962
4939
  if (!database) return void 0;
4963
4940
  return database.code({});
4964
4941
  };
4965
-
4966
4942
  //#endregion
4967
4943
  //#region src/commands/init/configs/databases.config.ts
4968
4944
  const prismaCode = ({ provider, additionalOptions }) => {
@@ -5353,7 +5329,6 @@ const databasesConfig = [
5353
5329
  dependencies: ["mongodb"]
5354
5330
  }
5355
5331
  ];
5356
-
5357
5332
  //#endregion
5358
5333
  //#region src/commands/init/utility/database.ts
5359
5334
  const getDatabaseCode = (adapter) => {
@@ -5483,7 +5458,6 @@ const getDialectsForORM = (orm) => {
5483
5458
  }
5484
5459
  return dialects.sort((a, b) => a.value.localeCompare(b.value));
5485
5460
  };
5486
-
5487
5461
  //#endregion
5488
5462
  //#region src/commands/init/generate-auth.ts
5489
5463
  const generateAuthConfigCode = async ({ plugins: pluginsConfig, database: databaseConfig, appName, baseURL, emailAndPassword, socialProviders, installDependency, options }) => {
@@ -5529,7 +5503,6 @@ const generateAuthConfigCode = async ({ plugins: pluginsConfig, database: databa
5529
5503
  segmentedCode.exports
5530
5504
  ].join("\n"));
5531
5505
  };
5532
-
5533
5506
  //#endregion
5534
5507
  //#region src/commands/init/utility/auth-client-config.ts
5535
5508
  const generateInnerAuthClientConfigCode = async ({ plugins, options, installDependency }) => {
@@ -5545,7 +5518,6 @@ const generateInnerAuthClientConfigCode = async ({ plugins, options, installDepe
5545
5518
  }
5546
5519
  return stringCode;
5547
5520
  };
5548
-
5549
5521
  //#endregion
5550
5522
  //#region src/commands/init/generate-auth-client.ts
5551
5523
  const generateAuthClientConfigCode = async ({ plugins: pluginsConfig, database: databaseConfig, framework, options, installDependency }) => {
@@ -5585,7 +5557,6 @@ const generateAuthClientConfigCode = async ({ plugins: pluginsConfig, database:
5585
5557
  segmentedCode.exports
5586
5558
  ].join("\n"));
5587
5559
  };
5588
-
5589
5560
  //#endregion
5590
5561
  //#region src/commands/init/utility/env.ts
5591
5562
  const getEnvFiles = async (cwd) => {
@@ -5631,7 +5602,6 @@ const createEnvFile = async (cwd, envVariables) => {
5631
5602
  const envFile = path.join(cwd, ".env");
5632
5603
  await fs$1.writeFile(envFile, envVariables.join("\n"), "utf-8");
5633
5604
  };
5634
-
5635
5605
  //#endregion
5636
5606
  //#region src/commands/init/utility/framework.ts
5637
5607
  async function detectFramework(cwd, packageJson) {
@@ -5656,7 +5626,6 @@ const fileStrategy = ({ cwd }) => {
5656
5626
  }
5657
5627
  return null;
5658
5628
  };
5659
-
5660
5629
  //#endregion
5661
5630
  //#region src/commands/init/index.ts
5662
5631
  const confirm = async (options) => {
@@ -6631,7 +6600,6 @@ const initActionOptionsSchema = z.object({
6631
6600
  packageManager: z.enum(PACKAGE_MANAGER).optional(),
6632
6601
  ...pluginArgumentOptionsSchema
6633
6602
  });
6634
-
6635
6603
  //#endregion
6636
6604
  //#region src/commands/login.ts
6637
6605
  async function loginAction() {
@@ -6654,7 +6622,6 @@ async function logoutAction() {
6654
6622
  process.exit(0);
6655
6623
  }
6656
6624
  const logout = new Command("logout").description("Logout from Better Auth Infrastructure").action(logoutAction);
6657
-
6658
6625
  //#endregion
6659
6626
  //#region src/commands/mcp.ts
6660
6627
  const REMOTE_MCP_URL = "https://mcp.inkeep.com/better-auth/mcp";
@@ -6785,7 +6752,6 @@ function showAllOptions() {
6785
6752
  console.log();
6786
6753
  }
6787
6754
  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);
6788
-
6789
6755
  //#endregion
6790
6756
  //#region src/commands/migrate.ts
6791
6757
  /** @internal */
@@ -6915,7 +6881,6 @@ async function migrateAction(opts) {
6915
6881
  process.exit(0);
6916
6882
  }
6917
6883
  const migrate = new Command("migrate").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("--config <config>", "the path to the configuration file. defaults to the first configuration file found.").option("-y, --yes", "automatically accept and run migrations without prompting", false).option("--y", "(deprecated) same as --yes", false).action(migrateAction);
6918
-
6919
6884
  //#endregion
6920
6885
  //#region src/commands/secret.ts
6921
6886
  const generateSecret = new Command("secret").action(() => {
@@ -6926,7 +6891,6 @@ ${chalk.gray("# Auth Secret") + chalk.green(`\nBETTER_AUTH_SECRET=${secret}`)}`)
6926
6891
  const generateSecretHash = () => {
6927
6892
  return Crypto.randomBytes(32).toString("hex");
6928
6893
  };
6929
-
6930
6894
  //#endregion
6931
6895
  //#region src/utils/fetch-latest-version.ts
6932
6896
  async function fetchLatestVersion(packageName) {
@@ -6939,7 +6903,6 @@ async function fetchLatestVersion(packageName) {
6939
6903
  return null;
6940
6904
  }
6941
6905
  }
6942
-
6943
6906
  //#endregion
6944
6907
  //#region src/commands/upgrade.ts
6945
6908
  function isBetterAuthPackage(name) {
@@ -7044,7 +7007,6 @@ async function upgradeAction(opts) {
7044
7007
  }
7045
7008
  }
7046
7009
  const upgrade = new Command("upgrade").description("Upgrade better-auth packages to their latest versions").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("-y, --yes", "automatically accept and upgrade without prompting", false).action(upgradeAction);
7047
-
7048
7010
  //#endregion
7049
7011
  //#region src/index.ts
7050
7012
  process.on("SIGINT", () => process.exit(0));
@@ -7064,7 +7026,7 @@ main().catch((error) => {
7064
7026
  console.error("Error running Better Auth CLI:", error);
7065
7027
  process.exit(1);
7066
7028
  });
7067
-
7068
7029
  //#endregion
7069
7030
  export { cliVersion };
7031
+
7070
7032
  //# sourceMappingURL=index.mjs.map