@better-auth/cli 1.4.5 → 1.4.6-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.
- package/dist/index.mjs +41 -39
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import fs, { existsSync, readFileSync } from "node:fs";
|
|
|
5
5
|
import fs$1 from "node:fs/promises";
|
|
6
6
|
import * as path$1 from "node:path";
|
|
7
7
|
import path from "node:path";
|
|
8
|
-
import {
|
|
8
|
+
import { createTelemetry, getTelemetryAuthConfig } from "@better-auth/telemetry";
|
|
9
9
|
import { getAdapter, getAuthTables, getMigrations } from "better-auth/db";
|
|
10
10
|
import chalk from "chalk";
|
|
11
11
|
import prompts from "prompts";
|
|
@@ -13,9 +13,11 @@ import yoctoSpinner from "yocto-spinner";
|
|
|
13
13
|
import * as z from "zod/v4";
|
|
14
14
|
import { initGetFieldName, initGetModelName } from "better-auth/adapters";
|
|
15
15
|
import prettier, { format } from "prettier";
|
|
16
|
+
import { capitalizeFirstLetter } from "@better-auth/core/utils";
|
|
16
17
|
import { produceSchema } from "@mrleebo/prisma-ast";
|
|
17
18
|
import babelPresetReact from "@babel/preset-react";
|
|
18
19
|
import babelPresetTypeScript from "@babel/preset-typescript";
|
|
20
|
+
import { BetterAuthError } from "@better-auth/core/error";
|
|
19
21
|
import { loadConfig } from "c12";
|
|
20
22
|
import { exec, execSync } from "node:child_process";
|
|
21
23
|
import * as os$1 from "node:os";
|
|
@@ -524,7 +526,7 @@ const generateSchema = (opts) => {
|
|
|
524
526
|
fileName,
|
|
525
527
|
overwrite
|
|
526
528
|
}));
|
|
527
|
-
|
|
529
|
+
console.error(`${adapter.id} is not supported. If it is a custom adapter, please request the maintainer to implement createSchema`);
|
|
528
530
|
process.exit(1);
|
|
529
531
|
};
|
|
530
532
|
|
|
@@ -813,7 +815,7 @@ function getPathAliasesRecursive(tsconfigPath, visited = /* @__PURE__ */ new Set
|
|
|
813
815
|
if (visited.has(tsconfigPath)) return {};
|
|
814
816
|
visited.add(tsconfigPath);
|
|
815
817
|
if (!fs.existsSync(tsconfigPath)) {
|
|
816
|
-
|
|
818
|
+
console.warn(`Referenced tsconfig not found: ${tsconfigPath}`);
|
|
817
819
|
return {};
|
|
818
820
|
}
|
|
819
821
|
try {
|
|
@@ -834,7 +836,7 @@ function getPathAliasesRecursive(tsconfigPath, visited = /* @__PURE__ */ new Set
|
|
|
834
836
|
}
|
|
835
837
|
return result;
|
|
836
838
|
} catch (error) {
|
|
837
|
-
|
|
839
|
+
console.warn(`Error parsing tsconfig at ${tsconfigPath}: ${error}`);
|
|
838
840
|
return {};
|
|
839
841
|
}
|
|
840
842
|
}
|
|
@@ -886,7 +888,7 @@ async function getConfig({ cwd, configPath, shouldThrowOnError = false }) {
|
|
|
886
888
|
});
|
|
887
889
|
if (!("auth" in config) && !isDefaultExport(config)) {
|
|
888
890
|
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.`);
|
|
889
|
-
|
|
891
|
+
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.`);
|
|
890
892
|
process.exit(1);
|
|
891
893
|
}
|
|
892
894
|
configFile = "auth" in config ? config.auth?.options : config.options;
|
|
@@ -900,9 +902,9 @@ async function getConfig({ cwd, configPath, shouldThrowOnError = false }) {
|
|
|
900
902
|
configFile = config.auth?.options || config.default?.options || null;
|
|
901
903
|
if (!configFile) {
|
|
902
904
|
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.");
|
|
903
|
-
|
|
905
|
+
console.error("[#better-auth]: Couldn't read your auth config.");
|
|
904
906
|
console.log("");
|
|
905
|
-
|
|
907
|
+
console.log("[#better-auth]: Make sure to default export your auth instance or to export as a variable named auth.");
|
|
906
908
|
process.exit(1);
|
|
907
909
|
}
|
|
908
910
|
break;
|
|
@@ -910,22 +912,22 @@ async function getConfig({ cwd, configPath, shouldThrowOnError = false }) {
|
|
|
910
912
|
} catch (e) {
|
|
911
913
|
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")) {
|
|
912
914
|
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.`);
|
|
913
|
-
|
|
915
|
+
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.`);
|
|
914
916
|
process.exit(1);
|
|
915
917
|
}
|
|
916
918
|
if (shouldThrowOnError) throw e;
|
|
917
|
-
|
|
919
|
+
console.error("[#better-auth]: Couldn't read your auth config.", e);
|
|
918
920
|
process.exit(1);
|
|
919
921
|
}
|
|
920
922
|
return configFile;
|
|
921
923
|
} catch (e) {
|
|
922
924
|
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")) {
|
|
923
925
|
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.`);
|
|
924
|
-
|
|
926
|
+
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.`);
|
|
925
927
|
process.exit(1);
|
|
926
928
|
}
|
|
927
929
|
if (shouldThrowOnError) throw e;
|
|
928
|
-
|
|
930
|
+
console.error("Couldn't read your auth config.", e);
|
|
929
931
|
process.exit(1);
|
|
930
932
|
}
|
|
931
933
|
}
|
|
@@ -942,7 +944,7 @@ async function generateAction(opts) {
|
|
|
942
944
|
}).parse(opts);
|
|
943
945
|
const cwd = path.resolve(options.cwd);
|
|
944
946
|
if (!existsSync(cwd)) {
|
|
945
|
-
|
|
947
|
+
console.error(`The directory "${cwd}" does not exist.`);
|
|
946
948
|
process.exit(1);
|
|
947
949
|
}
|
|
948
950
|
const config = await getConfig({
|
|
@@ -950,11 +952,11 @@ async function generateAction(opts) {
|
|
|
950
952
|
configPath: options.config
|
|
951
953
|
});
|
|
952
954
|
if (!config) {
|
|
953
|
-
|
|
955
|
+
console.error("No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag.");
|
|
954
956
|
return;
|
|
955
957
|
}
|
|
956
958
|
const adapter = await getAdapter(config).catch((e) => {
|
|
957
|
-
|
|
959
|
+
console.error(e.message);
|
|
958
960
|
process.exit(1);
|
|
959
961
|
});
|
|
960
962
|
const spinner$1 = yoctoSpinner({ text: "preparing schema..." }).start();
|
|
@@ -965,7 +967,7 @@ async function generateAction(opts) {
|
|
|
965
967
|
});
|
|
966
968
|
spinner$1.stop();
|
|
967
969
|
if (!schema.code) {
|
|
968
|
-
|
|
970
|
+
console.log("Your schema is already up to date.");
|
|
969
971
|
try {
|
|
970
972
|
await (await createTelemetry(config)).publish({
|
|
971
973
|
type: "cli_generate",
|
|
@@ -991,7 +993,7 @@ async function generateAction(opts) {
|
|
|
991
993
|
if (!existsSync(path.join(cwd, schema.fileName))) await fs$1.mkdir(path.dirname(path.join(cwd, schema.fileName)), { recursive: true });
|
|
992
994
|
if (schema.overwrite) await fs$1.writeFile(path.join(cwd, schema.fileName), schema.code);
|
|
993
995
|
else await fs$1.appendFile(path.join(cwd, schema.fileName), schema.code);
|
|
994
|
-
|
|
996
|
+
console.log(`🚀 Schema was ${schema.overwrite ? "overwritten" : "appended"} successfully!`);
|
|
995
997
|
try {
|
|
996
998
|
await (await createTelemetry(config)).publish({
|
|
997
999
|
type: "cli_generate",
|
|
@@ -1003,7 +1005,7 @@ async function generateAction(opts) {
|
|
|
1003
1005
|
} catch {}
|
|
1004
1006
|
process.exit(0);
|
|
1005
1007
|
} else {
|
|
1006
|
-
|
|
1008
|
+
console.error("Schema generation aborted.");
|
|
1007
1009
|
try {
|
|
1008
1010
|
await (await createTelemetry(config)).publish({
|
|
1009
1011
|
type: "cli_generate",
|
|
@@ -1027,7 +1029,7 @@ async function generateAction(opts) {
|
|
|
1027
1029
|
message: `Do you want to generate the schema to ${chalk.yellow(schema.fileName)}?`
|
|
1028
1030
|
})).confirm;
|
|
1029
1031
|
if (!confirm$1) {
|
|
1030
|
-
|
|
1032
|
+
console.error("Schema generation aborted.");
|
|
1031
1033
|
try {
|
|
1032
1034
|
await (await createTelemetry(config)).publish({
|
|
1033
1035
|
type: "cli_generate",
|
|
@@ -1043,7 +1045,7 @@ async function generateAction(opts) {
|
|
|
1043
1045
|
if (!existsSync(path.dirname(path.join(cwd, schema.fileName)))) await fs$1.mkdir(path.dirname(path.join(cwd, schema.fileName)), { recursive: true });
|
|
1044
1046
|
}
|
|
1045
1047
|
await fs$1.writeFile(options.output || path.join(cwd, schema.fileName), schema.code);
|
|
1046
|
-
|
|
1048
|
+
console.log(`🚀 Schema was generated successfully!`);
|
|
1047
1049
|
try {
|
|
1048
1050
|
await (await createTelemetry(config)).publish({
|
|
1049
1051
|
type: "cli_generate",
|
|
@@ -1719,7 +1721,7 @@ async function generateAuthConfig({ format: format$1, current_user_config, spinn
|
|
|
1719
1721
|
total_dependencies.push(...dependencies);
|
|
1720
1722
|
} catch (error) {
|
|
1721
1723
|
spinner$1.stop(`Something went wrong while generating/updating your new auth config file.`, 1);
|
|
1722
|
-
|
|
1724
|
+
console.error(error.message);
|
|
1723
1725
|
process.exit(1);
|
|
1724
1726
|
}
|
|
1725
1727
|
if (database) try {
|
|
@@ -1732,7 +1734,7 @@ async function generateAuthConfig({ format: format$1, current_user_config, spinn
|
|
|
1732
1734
|
total_envs.push(...envs);
|
|
1733
1735
|
} catch (error) {
|
|
1734
1736
|
spinner$1.stop(`Something went wrong while generating/updating your new auth config file.`, 1);
|
|
1735
|
-
|
|
1737
|
+
console.error(error.message);
|
|
1736
1738
|
process.exit(1);
|
|
1737
1739
|
}
|
|
1738
1740
|
return {
|
|
@@ -1892,7 +1894,7 @@ function installDependencies({ dependencies, packageManager, cwd }) {
|
|
|
1892
1894
|
//#region src/commands/secret.ts
|
|
1893
1895
|
const generateSecret = new Command("secret").action(() => {
|
|
1894
1896
|
const secret = generateSecretHash();
|
|
1895
|
-
|
|
1897
|
+
console.log(`\nAdd the following to your .env file:
|
|
1896
1898
|
${chalk.gray("# Auth Secret") + chalk.green(`\nBETTER_AUTH_SECRET=${secret}`)}`);
|
|
1897
1899
|
});
|
|
1898
1900
|
const generateSecretHash = () => {
|
|
@@ -2722,7 +2724,7 @@ async function loginAction(opts) {
|
|
|
2722
2724
|
});
|
|
2723
2725
|
spinner$1.stop();
|
|
2724
2726
|
if (error || !data) {
|
|
2725
|
-
|
|
2727
|
+
console.error(`Failed to request device authorization: ${error?.error_description || "Unknown error"}`);
|
|
2726
2728
|
process.exit(1);
|
|
2727
2729
|
}
|
|
2728
2730
|
const { device_code, user_code, verification_uri, verification_uri_complete, interval = 5, expires_in } = data;
|
|
@@ -2748,7 +2750,7 @@ async function loginAction(opts) {
|
|
|
2748
2750
|
}
|
|
2749
2751
|
} catch (err) {
|
|
2750
2752
|
spinner$1.stop();
|
|
2751
|
-
|
|
2753
|
+
console.error(`Login failed: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
2752
2754
|
process.exit(1);
|
|
2753
2755
|
}
|
|
2754
2756
|
}
|
|
@@ -2783,22 +2785,22 @@ async function pollForToken(authClient, deviceCode, clientId, initialInterval) {
|
|
|
2783
2785
|
break;
|
|
2784
2786
|
case "access_denied":
|
|
2785
2787
|
spinner$1.stop();
|
|
2786
|
-
|
|
2788
|
+
console.error("Access was denied by the user");
|
|
2787
2789
|
process.exit(1);
|
|
2788
2790
|
break;
|
|
2789
2791
|
case "expired_token":
|
|
2790
2792
|
spinner$1.stop();
|
|
2791
|
-
|
|
2793
|
+
console.error("The device code has expired. Please try again.");
|
|
2792
2794
|
process.exit(1);
|
|
2793
2795
|
break;
|
|
2794
2796
|
default:
|
|
2795
2797
|
spinner$1.stop();
|
|
2796
|
-
|
|
2798
|
+
console.error(`Error: ${error.error_description}`);
|
|
2797
2799
|
process.exit(1);
|
|
2798
2800
|
}
|
|
2799
2801
|
} catch (err) {
|
|
2800
2802
|
spinner$1.stop();
|
|
2801
|
-
|
|
2803
|
+
console.error(`Network error: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
2802
2804
|
process.exit(1);
|
|
2803
2805
|
}
|
|
2804
2806
|
setTimeout(poll, pollingInterval * 1e3);
|
|
@@ -2817,7 +2819,7 @@ async function storeToken(token) {
|
|
|
2817
2819
|
};
|
|
2818
2820
|
await fs$1.writeFile(TOKEN_FILE, JSON.stringify(tokenData, null, 2), "utf-8");
|
|
2819
2821
|
} catch (error) {
|
|
2820
|
-
|
|
2822
|
+
console.warn("Failed to store authentication token locally");
|
|
2821
2823
|
}
|
|
2822
2824
|
}
|
|
2823
2825
|
async function getStoredToken() {
|
|
@@ -2971,7 +2973,7 @@ async function migrateAction(opts) {
|
|
|
2971
2973
|
}).parse(opts);
|
|
2972
2974
|
const cwd = path.resolve(options.cwd);
|
|
2973
2975
|
if (!existsSync(cwd)) {
|
|
2974
|
-
|
|
2976
|
+
console.error(`The directory "${cwd}" does not exist.`);
|
|
2975
2977
|
process.exit(1);
|
|
2976
2978
|
}
|
|
2977
2979
|
const config = await getConfig({
|
|
@@ -2979,17 +2981,17 @@ async function migrateAction(opts) {
|
|
|
2979
2981
|
configPath: options.config
|
|
2980
2982
|
});
|
|
2981
2983
|
if (!config) {
|
|
2982
|
-
|
|
2984
|
+
console.error("No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag.");
|
|
2983
2985
|
return;
|
|
2984
2986
|
}
|
|
2985
2987
|
const db = await getAdapter(config);
|
|
2986
2988
|
if (!db) {
|
|
2987
|
-
|
|
2989
|
+
console.error("Invalid database configuration. Make sure you're not using adapters. Migrate command only works with built-in Kysely adapter.");
|
|
2988
2990
|
process.exit(1);
|
|
2989
2991
|
}
|
|
2990
2992
|
if (db.id !== "kysely") {
|
|
2991
2993
|
if (db.id === "prisma") {
|
|
2992
|
-
|
|
2994
|
+
console.error("The migrate command only works with the built-in Kysely adapter. For Prisma, run `npx @better-auth/cli generate` to create the schema, then use Prisma's migrate or push to apply it.");
|
|
2993
2995
|
try {
|
|
2994
2996
|
await (await createTelemetry(config)).publish({
|
|
2995
2997
|
type: "cli_migrate",
|
|
@@ -3003,7 +3005,7 @@ async function migrateAction(opts) {
|
|
|
3003
3005
|
process.exit(0);
|
|
3004
3006
|
}
|
|
3005
3007
|
if (db.id === "drizzle") {
|
|
3006
|
-
|
|
3008
|
+
console.error("The migrate command only works with the built-in Kysely adapter. For Drizzle, run `npx @better-auth/cli generate` to create the schema, then use Drizzle's migrate or push to apply it.");
|
|
3007
3009
|
try {
|
|
3008
3010
|
await (await createTelemetry(config)).publish({
|
|
3009
3011
|
type: "cli_migrate",
|
|
@@ -3016,7 +3018,7 @@ async function migrateAction(opts) {
|
|
|
3016
3018
|
} catch {}
|
|
3017
3019
|
process.exit(0);
|
|
3018
3020
|
}
|
|
3019
|
-
|
|
3021
|
+
console.error("Migrate command isn't supported for this adapter.");
|
|
3020
3022
|
try {
|
|
3021
3023
|
await (await createTelemetry(config)).publish({
|
|
3022
3024
|
type: "cli_migrate",
|
|
@@ -3033,7 +3035,7 @@ async function migrateAction(opts) {
|
|
|
3033
3035
|
const { toBeAdded, toBeCreated, runMigrations } = await getMigrations(config);
|
|
3034
3036
|
if (!toBeAdded.length && !toBeCreated.length) {
|
|
3035
3037
|
spinner$1.stop();
|
|
3036
|
-
|
|
3038
|
+
console.log("🚀 No migrations needed.");
|
|
3037
3039
|
try {
|
|
3038
3040
|
await (await createTelemetry(config)).publish({
|
|
3039
3041
|
type: "cli_migrate",
|
|
@@ -3046,7 +3048,7 @@ async function migrateAction(opts) {
|
|
|
3046
3048
|
process.exit(0);
|
|
3047
3049
|
}
|
|
3048
3050
|
spinner$1.stop();
|
|
3049
|
-
|
|
3051
|
+
console.log(`🔑 The migration will affect the following:`);
|
|
3050
3052
|
for (const table of [...toBeCreated, ...toBeAdded]) console.log("->", chalk.magenta(Object.keys(table.fields).join(", ")), chalk.white("fields on"), chalk.yellow(`${table.table}`), chalk.white("table."));
|
|
3051
3053
|
if (options.y) {
|
|
3052
3054
|
console.warn("WARNING: --y is deprecated. Consider -y or --yes");
|
|
@@ -3060,7 +3062,7 @@ async function migrateAction(opts) {
|
|
|
3060
3062
|
initial: false
|
|
3061
3063
|
})).migrate;
|
|
3062
3064
|
if (!migrate$1) {
|
|
3063
|
-
|
|
3065
|
+
console.log("Migration cancelled.");
|
|
3064
3066
|
try {
|
|
3065
3067
|
await (await createTelemetry(config)).publish({
|
|
3066
3068
|
type: "cli_migrate",
|
|
@@ -3075,7 +3077,7 @@ async function migrateAction(opts) {
|
|
|
3075
3077
|
spinner$1?.start("migrating...");
|
|
3076
3078
|
await runMigrations();
|
|
3077
3079
|
spinner$1.stop();
|
|
3078
|
-
|
|
3080
|
+
console.log("🚀 migration was completed successfully!");
|
|
3079
3081
|
try {
|
|
3080
3082
|
await (await createTelemetry(config)).publish({
|
|
3081
3083
|
type: "cli_migrate",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/cli",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.6-beta.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The CLI for Better Auth",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"@types/prompts": "^2.4.9",
|
|
34
34
|
"@types/semver": "^7.7.1",
|
|
35
35
|
"jiti": "^2.6.0",
|
|
36
|
-
"tsdown": "^0.
|
|
36
|
+
"tsdown": "^0.17.0",
|
|
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.
|
|
40
|
+
"@better-auth/passkey": "1.4.6-beta.3"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@babel/core": "^7.28.4",
|
|
@@ -57,13 +57,13 @@
|
|
|
57
57
|
"open": "^10.2.0",
|
|
58
58
|
"pg": "^8.16.3",
|
|
59
59
|
"prettier": "^3.6.2",
|
|
60
|
-
"prisma": "^5.22.0",
|
|
61
60
|
"prompts": "^2.4.2",
|
|
62
61
|
"semver": "^7.7.2",
|
|
63
62
|
"yocto-spinner": "^0.2.3",
|
|
64
63
|
"zod": "^4.1.12",
|
|
65
|
-
"better-auth": "1.4.
|
|
66
|
-
"@better-auth/
|
|
64
|
+
"@better-auth/core": "1.4.6-beta.3",
|
|
65
|
+
"@better-auth/telemetry": "1.4.6-beta.3",
|
|
66
|
+
"better-auth": "^1.4.6-beta.3"
|
|
67
67
|
},
|
|
68
68
|
"files": [
|
|
69
69
|
"dist"
|