feat: add clerk auth support with convex (#548)

This commit is contained in:
Aman Varshney
2025-08-29 00:21:08 +05:30
committed by GitHub
parent 8d48ae0359
commit 54bcdf1cbc
153 changed files with 1954 additions and 771 deletions

View File

@@ -135,7 +135,6 @@ export function validateWorkersCompatibility(
export function coerceBackendPresets(config: Partial<ProjectConfig>) {
if (config.backend === "convex") {
config.auth = false;
config.database = "none";
config.orm = "none";
config.api = "none";
@@ -144,7 +143,7 @@ export function coerceBackendPresets(config: Partial<ProjectConfig>) {
config.examples = ["todo"] as ProjectConfig["examples"];
}
if (config.backend === "none") {
config.auth = false;
config.auth = "none" as ProjectConfig["auth"];
config.database = "none";
config.orm = "none";
config.api = "none";
@@ -161,7 +160,13 @@ export function incompatibleFlagsForBackend(
): string[] {
const list: string[] = [];
if (backend === "convex") {
if (providedFlags.has("auth") && options.auth === true) list.push("--auth");
if (
providedFlags.has("auth") &&
options.auth &&
options.auth !== "none" &&
options.auth !== "clerk"
)
list.push(`--auth ${options.auth}`);
if (providedFlags.has("database") && options.database !== "none")
list.push(`--database ${options.database}`);
if (providedFlags.has("orm") && options.orm !== "none")
@@ -174,7 +179,8 @@ export function incompatibleFlagsForBackend(
list.push(`--db-setup ${options.dbSetup}`);
}
if (backend === "none") {
if (providedFlags.has("auth") && options.auth === true) list.push("--auth");
if (providedFlags.has("auth") && options.auth && options.auth !== "none")
list.push(`--auth ${options.auth}`);
if (providedFlags.has("database") && options.database !== "none")
list.push(`--database ${options.database}`);
if (providedFlags.has("orm") && options.orm !== "none")
@@ -210,8 +216,15 @@ export function validateApiFrontendCompatibility(
export function isFrontendAllowedWithBackend(
frontend: Frontend,
backend?: ProjectConfig["backend"],
auth?: string,
) {
if (backend === "convex" && frontend === "solid") return false;
if (auth === "clerk" && backend === "convex") {
const incompatibleFrontends = ["nuxt", "svelte", "solid"];
if (incompatibleFrontends.includes(frontend)) return false;
}
return true;
}

View File

@@ -1,6 +1,7 @@
import path from "node:path";
import type {
API,
Auth,
Backend,
CLIInput,
Database,
@@ -57,7 +58,7 @@ export function processFlags(
}
if (options.auth !== undefined) {
config.auth = options.auth;
config.auth = options.auth as Auth;
}
if (options.git !== undefined) {

View File

@@ -66,15 +66,21 @@ export function validateDatabaseOrmAuth(
);
}
if (has("auth") && has("database") && cfg.auth && db === "none") {
if (
has("auth") &&
has("database") &&
cfg.auth !== "none" &&
db === "none" &&
cfg.backend !== "convex"
) {
exitWithError(
"Authentication requires a database. Please choose a database or set '--no-auth'.",
"Authentication requires a database. Please choose a database or set '--auth none'.",
);
}
if (cfg.auth && db === "none") {
if (cfg.auth !== "none" && db === "none" && cfg.backend !== "convex") {
exitWithError(
"Authentication requires a database. Please choose a database or set '--no-auth'.",
"Authentication requires a database. Please choose a database or set '--auth none'.",
);
}
@@ -178,6 +184,35 @@ export function validateBackendConstraints(
): void {
const { backend } = config;
if (config.auth === "clerk" && backend !== "convex") {
exitWithError(
"Clerk authentication is only supported with the Convex backend. Please use '--backend convex' or choose a different auth provider.",
);
}
if (backend === "convex" && config.auth === "clerk" && config.frontend) {
const incompatibleFrontends = config.frontend.filter((f) =>
["nuxt", "svelte", "solid"].includes(f),
);
if (incompatibleFrontends.length > 0) {
exitWithError(
`Clerk authentication is not compatible with the following frontends: ${incompatibleFrontends.join(
", ",
)}. Please choose a different frontend or auth provider.`,
);
}
}
if (
backend === "convex" &&
config.auth === "better-auth" &&
providedFlags.has("auth")
) {
exitWithError(
"Better-Auth is not compatible with the Convex backend. Please use '--auth clerk' or '--auth none'.",
);
}
if (
providedFlags.has("backend") &&
backend &&

View File

@@ -40,13 +40,7 @@ export function displayConfig(config: Partial<ProjectConfig>) {
}
if (config.auth !== undefined) {
const authText =
typeof config.auth === "boolean"
? config.auth
? "Yes"
: "No"
: String(config.auth);
configDisplay.push(`${pc.blue("Authentication:")} ${authText}`);
configDisplay.push(`${pc.blue("Auth:")} ${String(config.auth)}`);
}
if (config.addons !== undefined) {

View File

@@ -14,7 +14,7 @@ export function generateReproducibleCommand(config: ProjectConfig): string {
flags.push(`--database ${config.database}`);
flags.push(`--orm ${config.orm}`);
flags.push(`--api ${config.api}`);
flags.push(config.auth ? "--auth" : "--no-auth");
flags.push(`--auth ${config.auth}`);
if (config.addons && config.addons.length > 0) {
flags.push(`--addons ${config.addons.join(" ")}`);