auth 1.7.5 → 1.7.6

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 +104 -20
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -12,13 +12,13 @@ import path, { join } from "node:path";
12
12
  import chalk from "chalk";
13
13
  import prompts from "prompts";
14
14
  import yoctoSpinner from "yocto-spinner";
15
- import { betterAuth } from "better-auth";
15
+ import fs$1, { stat } from "node:fs/promises";
16
16
  import * as z from "zod";
17
17
  import babelPresetReact from "@babel/preset-react";
18
18
  import babelPresetTypeScript from "@babel/preset-typescript";
19
19
  import { loadConfig } from "c12";
20
20
  import { createPathsMatcher, getTsconfig, parseTsconfig } from "get-tsconfig";
21
- import fs$1 from "node:fs/promises";
21
+ import { betterAuth } from "better-auth";
22
22
  import { createTelemetry, getTelemetryAuthConfig } from "@better-auth/telemetry";
23
23
  import { getAdapter } from "better-auth/db/adapter";
24
24
  import { diffSchema, formatSchemaFinding, getDatabaseFieldIndexName, getDatabaseIndexStringLength, getPortableDatabaseIdentifierKey, resolveDatabaseSchemaIndexes } from "@better-auth/core/db/internal";
@@ -45,7 +45,7 @@ function cancelled() {
45
45
  console.log(chalk.yellow("\n✋ Setup cancelled."));
46
46
  process.exit(0);
47
47
  }
48
- function check(value) {
48
+ function check$1(value) {
49
49
  if (value === void 0 || value === null) cancelled();
50
50
  return value;
51
51
  }
@@ -70,7 +70,7 @@ async function aiAction() {
70
70
  description: "expose capabilities from your service to AI agents"
71
71
  }]
72
72
  });
73
- check(setup);
73
+ check$1(setup);
74
74
  if (setup === "client") await setupClient();
75
75
  else await setupServerSelection();
76
76
  }
@@ -89,7 +89,7 @@ async function setupClient() {
89
89
  description: "command-line tool for agent workflows"
90
90
  }]
91
91
  });
92
- check(method);
92
+ check$1(method);
93
93
  if (method === "mcp") await setupMcp();
94
94
  else await setupCli();
95
95
  }
@@ -104,7 +104,7 @@ async function setupServerSelection() {
104
104
  description: "TypeScript"
105
105
  }]
106
106
  });
107
- check(implementation);
107
+ check$1(implementation);
108
108
  await setupServer();
109
109
  }
110
110
  async function setupMcp() {
@@ -143,7 +143,7 @@ async function setupMcp() {
143
143
  }
144
144
  ]
145
145
  });
146
- check(tool);
146
+ check$1(tool);
147
147
  let scope = "global";
148
148
  if (tool === "cursor" || tool === "vscode") {
149
149
  const { s } = await prompts({
@@ -160,7 +160,7 @@ async function setupMcp() {
160
160
  description: tool === "cursor" ? "~/.cursor/mcp.json" : "user settings"
161
161
  }]
162
162
  });
163
- check(s);
163
+ check$1(s);
164
164
  scope = s;
165
165
  }
166
166
  const { registryUrl } = await prompts({
@@ -196,7 +196,7 @@ async function setupClaudeCode(args) {
196
196
  description: "--scope user"
197
197
  }]
198
198
  });
199
- check(scope);
199
+ check$1(scope);
200
200
  const cmd = [
201
201
  "claude",
202
202
  "mcp",
@@ -353,14 +353,14 @@ async function setupServer() {
353
353
  }
354
354
  ]
355
355
  });
356
- check(source);
356
+ check$1(source);
357
357
  const { name } = await prompts({
358
358
  type: "text",
359
359
  name: "name",
360
360
  message: "What's your service called?",
361
361
  validate: (v) => v?.trim() ? true : "Name is required."
362
362
  });
363
- check(name);
363
+ check$1(name);
364
364
  const { description } = await prompts({
365
365
  type: "text",
366
366
  name: "description",
@@ -375,7 +375,7 @@ async function setupServer() {
375
375
  message: `OpenAPI spec URL ${chalk.dim("(e.g. https://api.example.com/openapi.json)")}`,
376
376
  validate: (v) => v?.trim() ? true : "URL is required."
377
377
  });
378
- check(url);
378
+ check$1(url);
379
379
  sourceUrl = url.trim();
380
380
  } else if (source === "mcp") {
381
381
  const { url } = await prompts({
@@ -384,7 +384,7 @@ async function setupServer() {
384
384
  message: `MCP server URL ${chalk.dim("(e.g. https://api.example.com/mcp)")}`,
385
385
  validate: (v) => v?.trim() ? true : "URL is required."
386
386
  });
387
- check(url);
387
+ check$1(url);
388
388
  sourceUrl = url.trim();
389
389
  }
390
390
  const code = generateServerCode(name.trim(), desc, source, sourceUrl);
@@ -1188,7 +1188,7 @@ function resolvesMissingOutputModule(error, configFilePath, resolvedOutputPath)
1188
1188
  const importedFrom = typeof requireStack[0] === "string" ? requireStack[0] : configFilePath;
1189
1189
  return withoutSourceExtension(path.resolve(path.dirname(importedFrom), specifier)) === withoutSourceExtension(resolvedOutputPath);
1190
1190
  }
1191
- async function getConfig({ cwd, configPath, outputPath, shouldThrowOnError = false }) {
1191
+ async function getLoadedConfig({ cwd, configPath, outputPath, shouldThrowOnError = false }) {
1192
1192
  const fail = (message, error) => {
1193
1193
  if (shouldThrowOnError) throw error instanceof Error ? error : new Error(message);
1194
1194
  const log = `[#better-auth]: ${message}`;
@@ -1224,9 +1224,8 @@ async function getConfig({ cwd, configPath, outputPath, shouldThrowOnError = fal
1224
1224
  if (configPath) {
1225
1225
  const resolvedPath = existsSync(configPath) ? configPath : path.join(cwd, configPath);
1226
1226
  const { config } = await load(resolvedPath);
1227
- const options = config?.options;
1228
- 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.`);
1229
- return options;
1227
+ if (!config?.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.`);
1228
+ return config;
1230
1229
  }
1231
1230
  for (const possiblePath of possiblePaths$1) {
1232
1231
  let config;
@@ -1238,7 +1237,7 @@ async function getConfig({ cwd, configPath, outputPath, shouldThrowOnError = fal
1238
1237
  }
1239
1238
  if (Object.keys(config).length === 0) continue;
1240
1239
  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.");
1241
- return config.options;
1240
+ return config;
1242
1241
  }
1243
1242
  return null;
1244
1243
  } catch (e) {
@@ -1246,6 +1245,91 @@ async function getConfig({ cwd, configPath, outputPath, shouldThrowOnError = fal
1246
1245
  return fail("Couldn't read your auth config.", e);
1247
1246
  }
1248
1247
  }
1248
+ async function getConfig(input) {
1249
+ return (await getLoadedConfig(input))?.options ?? null;
1250
+ }
1251
+ async function getAuth(input) {
1252
+ const auth = await getLoadedConfig(input);
1253
+ if (!auth) return null;
1254
+ if (!auth.$context) throw new Error("The auth config must export a Better Auth instance.");
1255
+ return {
1256
+ options: auth.options,
1257
+ $context: auth.$context
1258
+ };
1259
+ }
1260
+ //#endregion
1261
+ //#region src/commands/check.ts
1262
+ const sourceLabels = {
1263
+ database: "the live database",
1264
+ drizzle: "the configured Drizzle schema",
1265
+ prisma: "the generated Prisma client model"
1266
+ };
1267
+ async function checkSchemaAction(input) {
1268
+ const options = z.object({
1269
+ cwd: z.string(),
1270
+ config: z.string().optional()
1271
+ }).parse(input);
1272
+ const cwd = path.resolve(options.cwd);
1273
+ let cwdStat;
1274
+ try {
1275
+ cwdStat = await stat(cwd);
1276
+ } catch (error) {
1277
+ const { code } = error;
1278
+ if (code === "ENOENT") console.error(`The directory "${cwd}" does not exist.`);
1279
+ else console.error(`Could not access the directory "${cwd}"${code ? ` (${code}).` : "."}`);
1280
+ process.exitCode = 2;
1281
+ return;
1282
+ }
1283
+ if (!cwdStat.isDirectory()) {
1284
+ console.error(`The path "${cwd}" is not a directory.`);
1285
+ process.exitCode = 2;
1286
+ return;
1287
+ }
1288
+ let auth;
1289
+ try {
1290
+ auth = await getAuth({
1291
+ cwd,
1292
+ configPath: options.config,
1293
+ shouldThrowOnError: true
1294
+ });
1295
+ } catch {
1296
+ console.error("Could not load the Better Auth configuration.");
1297
+ process.exitCode = 2;
1298
+ return;
1299
+ }
1300
+ if (!auth) {
1301
+ console.error("No Better Auth configuration found. Pass --config to select one.");
1302
+ process.exitCode = 2;
1303
+ return;
1304
+ }
1305
+ try {
1306
+ const context = await auth.$context;
1307
+ const check = context.explicitSchemaCheck;
1308
+ if (!check) {
1309
+ console.error(`Schema validation is not available for adapter "${context.adapter.id}".`);
1310
+ process.exitCode = 2;
1311
+ return;
1312
+ }
1313
+ await check();
1314
+ const source = check.source ? sourceLabels[check.source] : `adapter "${context.adapter.id}"`;
1315
+ console.log(`Schema check passed against ${source}.`);
1316
+ process.exitCode = 0;
1317
+ } catch (error) {
1318
+ if (error instanceof Error && "code" in error && error.code === "SCHEMA_MISMATCH") {
1319
+ console.error(error.message);
1320
+ process.exitCode = 1;
1321
+ return;
1322
+ }
1323
+ console.error("Could not validate the schema. Check the auth configuration and database connection.");
1324
+ process.exitCode = 2;
1325
+ }
1326
+ }
1327
+ async function runSchemaCheck(options) {
1328
+ await checkSchemaAction(options);
1329
+ process.exit(typeof process.exitCode === "number" ? process.exitCode : 0);
1330
+ }
1331
+ const check = new Command("check").description("Run all available Better Auth checks").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("--config <config>", "the path to the Better Auth configuration file.").action(runSchemaCheck);
1332
+ check.command("schema").description("Check that the configured schema can hold what Better Auth writes").configureHelp({ showGlobalOptions: true }).action((_options, command) => runSchemaCheck(command.optsWithGlobals()));
1249
1333
  //#endregion
1250
1334
  //#region src/commands/create-admin.ts
1251
1335
  function exitWithError(message) {
@@ -3135,7 +3219,7 @@ function installDependencies({ dependencies, packageManager, cwd, type = "prod",
3135
3219
  }
3136
3220
  //#endregion
3137
3221
  //#region src/version.ts
3138
- const cliVersion = "1.7.5";
3222
+ const cliVersion = "1.7.6";
3139
3223
  //#endregion
3140
3224
  //#region src/commands/init/configs/frameworks.config.ts
3141
3225
  const FRAMEWORKS = [
@@ -7778,7 +7862,7 @@ process.on("SIGINT", () => process.exit(0));
7778
7862
  process.on("SIGTERM", () => process.exit(0));
7779
7863
  async function main() {
7780
7864
  const program = new Command("better-auth");
7781
- program.addCommand(ai).addCommand(createAdmin).addCommand(init).addCommand(migrate).addCommand(generate).addCommand(generateSecret).addCommand(info).addCommand(login).addCommand(logout).addCommand(mcp).addCommand(upgrade).version(cliVersion).description("Better Auth CLI").action(() => program.help());
7865
+ program.addCommand(ai).addCommand(createAdmin).addCommand(check).addCommand(init).addCommand(migrate).addCommand(generate).addCommand(generateSecret).addCommand(info).addCommand(login).addCommand(logout).addCommand(mcp).addCommand(upgrade).version(cliVersion).description("Better Auth CLI").action(() => program.help());
7782
7866
  await program.parseAsync();
7783
7867
  }
7784
7868
  main().catch((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auth",
3
- "version": "1.7.5",
3
+ "version": "1.7.6",
4
4
  "description": "The CLI for Better Auth",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -64,9 +64,9 @@
64
64
  "semver": "^7.8.4",
65
65
  "yocto-spinner": "^1.2.0",
66
66
  "zod": "^4.5.4",
67
- "@better-auth/core": "1.7.5",
68
- "@better-auth/telemetry": "1.7.5",
69
- "better-auth": "1.7.5"
67
+ "@better-auth/core": "1.7.6",
68
+ "@better-auth/telemetry": "1.7.6",
69
+ "better-auth": "1.7.6"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@types/better-sqlite3": "^7.6.13",
@@ -78,7 +78,7 @@
78
78
  "tsx": "^4.21.0",
79
79
  "type-fest": "^5.7.0",
80
80
  "typescript": "^6.0.3",
81
- "@better-auth/passkey": "1.7.5"
81
+ "@better-auth/passkey": "1.7.6"
82
82
  },
83
83
  "scripts": {
84
84
  "build": "tsdown",