Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/cli/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const DEFAULT_CONFIG_BASE = {
frontend: ["tanstack-router"],
database: "sqlite",
orm: "drizzle",
auth: true,
auth: "better-auth",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Good switch to discriminated union default for auth; verify there are no boolean remnants.

Setting auth: "better-auth" with the enclosing as const is correct. Please ensure all CLI types, prompts, and templates no longer treat auth as boolean.

Run to catch leftovers:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Any stale boolean defaults?
rg -nP --glob '!**/node_modules/**' '\bauth\s*:\s*(true|false)\b' -C2

# 2) Any lingering zod boolean schema?
rg -nP --glob '!**/node_modules/**' 'z\.boolean\(\)' apps/cli/src -C2

# 3) Conditionals still treating `auth` as truthy/falsey checks
rg -nP --glob '!**/node_modules/**' '(if\s*\(|\?\s*).*?\.auth\b(?!\s*===|\s*!==)' apps/cli/src -n -C2

# 4) Confirm new allowed values appear
rg -nP --glob '!**/node_modules/**' '"better-auth"|"clerk"|"none"' -n -C1

Length of output: 164051


Update CLI docs to use string-based auth instead of boolean
In apps/web/content/docs/cli/programmatic-api.mdx (around lines 36, 272, 289), replace all auth: true examples with the appropriate union values ("better-auth" | "clerk" | "none") and update the auth?: boolean declaration to reflect the new Auth enum (auth?: "better-auth" | "clerk" | "none").

🤖 Prompt for AI Agents
In apps/cli/src/constants.ts around line 16, the auth constant is currently set
as a string but the codebase and docs expect an explicit Auth union type; update
the exported type/constant defs and any related declarations so that auth is
typed as the union "better-auth" | "clerk" | "none" (instead of boolean) and
ensure exports and usages reflect that enum; then update the CLI docs examples
in apps/web/content/docs/cli/programmatic-api.mdx (around lines 36, 272, 289) to
replace all occurrences of auth: true with an appropriate string literal from
the union ("better-auth" | "clerk" | "none") and change any type declarations of
auth?: boolean to auth?: "better-auth" | "clerk" | "none".

addons: ["turborepo"],
examples: [],
git: true,
Expand Down Expand Up @@ -43,6 +43,11 @@ export const dependencyVersionMap = {
"better-auth": "^1.3.7",
"@better-auth/expo": "^1.3.7",

"@clerk/nextjs": "^6.31.5",
"@clerk/clerk-react": "^5.45.0",
"@clerk/tanstack-react-start": "^0.23.1",
"@clerk/clerk-expo": "^2.14.25",

"drizzle-orm": "^0.44.2",
"drizzle-kit": "^0.31.2",

Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/helpers/core/add-addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function addAddonsToProject(
frontend: detectedConfig.frontend || [],
addons: input.addons,
examples: detectedConfig.examples || [],
auth: detectedConfig.auth || false,
auth: detectedConfig.auth || "none",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Normalize legacy boolean auth to the new string enum to avoid downstream mismatches

If detectedConfig.auth is true, this currently propagates a boolean into ProjectConfig.auth, breaking string comparisons elsewhere. Map booleans to "better-auth"/"none" and pass through valid strings.

-      auth: detectedConfig.auth || "none",
+      auth:
+        detectedConfig.auth === true
+          ? "better-auth"
+          : detectedConfig.auth === false || detectedConfig.auth == null
+            ? "none"
+            : detectedConfig.auth,

Run to spot any remaining boolean usages or boolean fallbacks for auth:


🏁 Script executed:

#!/bin/bash
# Boolean comparisons against auth (should be none)
rg -nP -C2 '\bauth\s*===?\s*(true|false)\b' --type=ts --type=tsx

# Old-style fallbacks like `|| false` when assigning auth
rg -nP -C2 'auth\s*:\s*[^,]*\|\|\s*false' --type=ts --type=tsx

# Types that still declare auth as boolean
rg -nP -C2 '\bauth\s*:\s*boolean\b' --type=ts --type=tsx

# Configs that still store boolean auth
rg -nP -C2 '"auth"\s*:\s*(true|false)'

Length of output: 613


Normalize legacy boolean auth to the new string enum and update docs

  • In apps/cli/src/helpers/core/add-addons.ts, replace the simple fallback with explicit mapping:
-      auth: detectedConfig.auth || "none",
+      auth:
+        detectedConfig.auth === true
+          ? "better-auth"
+          : detectedConfig.auth === false || detectedConfig.auth == null
+            ? "none"
+            : detectedConfig.auth,
  • In apps/web/content/docs/bts-config.mdx, update the example to use the string enum:
-  "auth": true,
+  "auth": "better-auth",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
auth: detectedConfig.auth || "none",
auth:
detectedConfig.auth === true
? "better-auth"
: detectedConfig.auth === false || detectedConfig.auth == null
? "none"
: detectedConfig.auth,

git: false,
packageManager:
input.packageManager || detectedConfig.packageManager || "npm",
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/helpers/core/add-deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function addDeploymentToProject(
frontend: detectedConfig.frontend || [],
addons: detectedConfig.addons || [],
examples: detectedConfig.examples || [],
auth: detectedConfig.auth || false,
auth: detectedConfig.auth || "none",
git: false,
packageManager:
input.packageManager || detectedConfig.packageManager || "npm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { addPackageDependency } from "../../utils/add-package-deps";

export async function setupAuth(config: ProjectConfig) {
const { auth, frontend, backend, projectDir } = config;
if (backend === "convex" || !auth) {
if (!auth || auth === "none") {
return;
}

Expand All @@ -20,7 +20,48 @@ export async function setupAuth(config: ProjectConfig) {
const serverDirExists = await fs.pathExists(serverDir);

try {
if (serverDirExists) {
if (backend === "convex") {
if (auth === "clerk" && clientDirExists) {
const hasNextJs = frontend.includes("next");
const hasTanStackStart = frontend.includes("tanstack-start");
const hasViteReactOther = frontend.some((f) =>
["tanstack-router", "react-router"].includes(f),
);

if (hasNextJs) {
await addPackageDependency({
dependencies: ["@clerk/nextjs"],
projectDir: clientDir,
});
} else if (hasTanStackStart) {
await addPackageDependency({
dependencies: ["@clerk/tanstack-react-start"],
projectDir: clientDir,
});
} else if (hasViteReactOther) {
await addPackageDependency({
dependencies: ["@clerk/clerk-react"],
projectDir: clientDir,
});
}
}

const hasNativeWind = frontend.includes("native-nativewind");
const hasUnistyles = frontend.includes("native-unistyles");
if (
auth === "clerk" &&
nativeDirExists &&
(hasNativeWind || hasUnistyles)
) {
await addPackageDependency({
dependencies: ["@clerk/clerk-expo"],
projectDir: nativeDir,
});
}
return;
}

if (serverDirExists && auth === "better-auth") {
await addPackageDependency({
dependencies: ["better-auth"],
projectDir: serverDir,
Expand All @@ -40,26 +81,30 @@ export async function setupAuth(config: ProjectConfig) {
);

if (hasWebFrontend && clientDirExists) {
await addPackageDependency({
dependencies: ["better-auth"],
projectDir: clientDir,
});
if (auth === "better-auth") {
await addPackageDependency({
dependencies: ["better-auth"],
projectDir: clientDir,
});
}
}

if (
(frontend.includes("native-nativewind") ||
frontend.includes("native-unistyles")) &&
nativeDirExists
) {
await addPackageDependency({
dependencies: ["better-auth", "@better-auth/expo"],
projectDir: nativeDir,
});
if (serverDirExists) {
if (auth === "better-auth") {
await addPackageDependency({
dependencies: ["@better-auth/expo"],
projectDir: serverDir,
dependencies: ["better-auth", "@better-auth/expo"],
projectDir: nativeDir,
});
if (serverDirExists) {
await addPackageDependency({
dependencies: ["@better-auth/expo"],
projectDir: serverDir,
});
}
}
}
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions apps/cli/src/helpers/core/command-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export async function createProjectHandler(
frontend: [],
addons: [],
examples: [],
auth: false,
auth: "none",
git: false,
packageManager: "npm",
install: false,
Expand Down Expand Up @@ -154,11 +154,11 @@ export async function createProjectHandler(

if (config.backend === "convex") {
log.info(
"Due to '--backend convex' flag, the following options have been automatically set: auth=false, database=none, orm=none, api=none, runtime=none, dbSetup=none, examples=todo",
`Due to '--backend convex' flag, the following options have been automatically set: database=none, orm=none, api=none, runtime=none, dbSetup=none, examples=todo`,
);
} else if (config.backend === "none") {
log.info(
"Due to '--backend none', the following options have been automatically set: --auth=false, --database=none, --orm=none, --api=none, --runtime=none, --db-setup=none, --examples=none",
"Due to '--backend none', the following options have been automatically set: --auth none, --database=none, --orm=none, --api=none, --runtime=none, --db-setup=none, --examples=none",
);
}

Expand Down
6 changes: 3 additions & 3 deletions apps/cli/src/helpers/core/create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { writeBtsConfig } from "../../utils/bts-config";
import { exitWithError } from "../../utils/errors";
import { formatProjectWithBiome } from "../../utils/format-with-biome";
import { setupAddons } from "../addons/addons-setup";
import { setupAuth } from "../addons/auth-setup";
import { setupExamples } from "../addons/examples-setup";
import { setupApi } from "../core/api-setup";
import { setupBackendDependencies } from "../core/backend-setup";
import { setupDatabase } from "../core/db-setup";
import { setupRuntime } from "../core/runtime-setup";
import { setupServerDeploy } from "../deployment/server-deploy-setup";
import { setupWebDeploy } from "../deployment/web-deploy-setup";
import { setupAuth } from "./auth-setup";
import { runConvexCodegen } from "./convex-codegen";
import { createReadme } from "./create-readme";
import { setupEnvironmentVariables } from "./env-setup";
Expand Down Expand Up @@ -46,8 +46,8 @@ export async function createProject(options: ProjectConfig) {
if (!isConvex) {
await setupDbOrmTemplates(projectDir, options);
await setupDockerComposeTemplates(projectDir, options);
await setupAuthTemplate(projectDir, options);
}
await setupAuthTemplate(projectDir, options);
if (options.examples.length > 0 && options.examples[0] !== "none") {
await setupExamplesTemplate(projectDir, options);
}
Expand All @@ -70,7 +70,7 @@ export async function createProject(options: ProjectConfig) {
await setupAddons(options);
}

if (!isConvex && options.auth) {
if (options.auth && options.auth !== "none") {
await setupAuth(options);
}

Expand Down
28 changes: 20 additions & 8 deletions apps/cli/src/helpers/core/create-readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs from "fs-extra";
import type {
Addons,
API,
Auth,
Database,
DatabaseSetup,
Frontend,
Expand Down Expand Up @@ -98,7 +99,11 @@ This project uses Convex as a backend. You'll need to set up Convex before runni
${packageManagerRunCmd} dev:setup
\`\`\`

Follow the prompts to create a new Convex project and connect it to your application.`
Follow the prompts to create a new Convex project and connect it to your application.${
auth === "clerk"
? " See [Convex + Clerk guide](https://docs.convex.dev/auth/clerk) for auth setup."
: ""
}`
: generateDatabaseSetup(
database,
auth,
Expand Down Expand Up @@ -135,6 +140,7 @@ ${generateProjectStructure(
addons,
isConvex,
api,
auth,
)}
\`\`\`

Expand Down Expand Up @@ -258,6 +264,7 @@ function generateProjectStructure(
addons: Addons[],
isConvex: boolean,
api: API,
auth: Auth,
): string {
const structure: string[] = [`${projectName}/`, "├── apps/"];

Expand Down Expand Up @@ -317,6 +324,12 @@ function generateProjectStructure(
structure.push(
"│ └── backend/ # Convex backend functions and schema",
);
if (auth === "clerk") {
structure.push(
"│ ├── convex/ # Convex functions and schema",
"│ └── .env.local # Convex environment variables",
);
}
Comment on lines +327 to +332

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Always show convex/ dir; gate .env.local by Clerk; fix tree connectors.
Currently the convex/ folder is only shown when Clerk is selected, which is confusing because it exists for Convex regardless of auth. Also, connectors (├──/└──) should adapt based on whether .env.local is added.

Apply this diff:

-    if (auth === "clerk") {
-      structure.push(
-        "│       ├── convex/    # Convex functions and schema",
-        "│       └── .env.local # Convex environment variables",
-      );
-    }
+    {
+      const hasClerkEnv = auth === "clerk";
+      structure.push(
+        `│       ${hasClerkEnv ? "├──" : "└──"} convex/    # Convex functions and schema`,
+      );
+      if (hasClerkEnv) {
+        structure.push("│       └── .env.local # Convex environment variables");
+      }
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (auth === "clerk") {
structure.push(
"│ ├── convex/ # Convex functions and schema",
"│ └── .env.local # Convex environment variables",
);
}
{
const hasClerkEnv = auth === "clerk";
structure.push(
`│ ${hasClerkEnv ? "├──" : "└──"} convex/ # Convex functions and schema`,
);
if (hasClerkEnv) {
structure.push("│ └── .env.local # Convex environment variables");
}
}
🤖 Prompt for AI Agents
In apps/cli/src/helpers/core/create-readme.ts around lines 327 to 332, always
include the "convex/" tree entry (it exists regardless of auth) and only include
the ".env.local" entry when auth === "clerk"; ensure the tree connector
characters adapt so that if .env.local is added it uses "├──" for convex and
"└──" for .env.local, otherwise convex uses "└──". Update the logic that builds
the structure array to unconditionally push the convex line and conditionally
push the .env.local line with the appropriate connector based on whether auth is
"clerk".

} else if (!isBackendNone) {
const backendName = backend[0].toUpperCase() + backend.slice(1);
const apiName = api !== "none" ? api.toUpperCase() : "";
Expand All @@ -329,7 +342,7 @@ function generateProjectStructure(

function generateFeaturesList(
database: Database,
auth: boolean,
auth: Auth,
addons: Addons[],
orm: ORM,
runtime: Runtime,
Expand Down Expand Up @@ -449,10 +462,9 @@ function generateFeaturesList(
);
}

if (auth && !isConvex) {
addonsList.push(
"- **Authentication** - Email & password authentication with Better Auth",
);
if (auth !== "none") {
const authLabel = auth === "clerk" ? "Clerk" : "Better-Auth";
addonsList.push(`- **Authentication** - ${authLabel}`);
}

for (const addon of addons) {
Expand All @@ -476,7 +488,7 @@ function generateFeaturesList(

function generateDatabaseSetup(
database: Database,
_auth: boolean,
_auth: Auth,
packageManagerRunCmd: string,
orm: ORM,
dbSetup: DatabaseSetup,
Expand Down Expand Up @@ -575,7 +587,7 @@ function generateScriptsList(
packageManagerRunCmd: string,
database: Database,
orm: ORM,
_auth: boolean,
_auth: Auth,
hasNative: boolean,
addons: Addons[],
backend: string,
Expand Down
46 changes: 45 additions & 1 deletion apps/cli/src/helpers/core/env-setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "node:path";
import fs from "fs-extra";
import type { ProjectConfig } from "../../types";
import { generateAuthSecret } from "../addons/auth-setup";
import { generateAuthSecret } from "./auth-setup";

export interface EnvVariable {
key: string;
Expand Down Expand Up @@ -143,6 +143,42 @@ export async function setupEnvironmentVariables(config: ProjectConfig) {
condition: true,
},
];

if (backend === "convex" && auth === "clerk") {
if (hasNextJs) {
clientVars.push(
{
key: "NEXT_PUBLIC_CLERK_FRONTEND_API_URL",
value: "",
condition: true,
},
{
key: "NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY",
value: "",
condition: true,
},
{
key: "CLERK_SECRET_KEY",
value: "",
condition: true,
},
);
} else if (hasReactRouter || hasTanStackRouter || hasTanStackStart) {
clientVars.push({
key: "VITE_CLERK_PUBLISHABLE_KEY",
value: "",
condition: true,
});
if (hasTanStackStart) {
clientVars.push({
key: "CLERK_SECRET_KEY",
value: "",
condition: true,
});
}
}
}

await addEnvVariablesToFile(path.join(clientDir, ".env"), clientVars);
}
}
Expand All @@ -168,6 +204,14 @@ export async function setupEnvironmentVariables(config: ProjectConfig) {
condition: true,
},
];

if (backend === "convex" && auth === "clerk") {
nativeVars.push({
key: "EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY",
value: "",
condition: true,
});
}
await addEnvVariablesToFile(path.join(nativeDir, ".env"), nativeVars);
}
}
Expand Down
Loading