Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
24 changes: 19 additions & 5 deletions apps/cli/src/helpers/core/post-installation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ export async function displayPostInstallInstructions(
: "";
const clerkInstructions =
config.auth === "clerk" ? getClerkInstructions(frontend || [], backend, api) : "";
const polarInstructions =
config.payments === "polar" && config.auth === "better-auth"
? getPolarInstructions(backend)
: "";
const alchemyDeployInstructions = getAlchemyDeployInstructions(
runCmd,
webDeploy,
Expand All @@ -135,6 +131,10 @@ export async function displayPostInstallInstructions(
isConvex && config.auth === "better-auth"
? getBetterAuthConvexInstructions(hasWeb ?? false, webPort, packageManager)
: "";
const polarInstructions =
config.payments === "polar" && config.auth === "better-auth"
? getPolarInstructions(backend, packageManager)
: "";

const bunWebNativeWarning =
packageManager === "bun" && hasNative && hasWeb ? getBunWebNativeWarning() : "";
Expand Down Expand Up @@ -572,7 +572,21 @@ function getBetterAuthConvexInstructions(hasWeb: boolean, webPort: string, packa
);
}

function getPolarInstructions(backend: Backend) {
function getPolarInstructions(backend: Backend, packageManager: string) {
if (backend === "convex") {
const cmd = packageManager === "npm" ? "npx" : packageManager;
return (
`${pc.bold("Polar Payments Setup:")}\n` +
`${pc.cyan("•")} Create a Polar organization token, webhook secret, and product in ${pc.underline("https://sandbox.polar.sh/")}\n` +
`${pc.cyan("•")} Set the Convex env vars from ${pc.white("packages/backend")}:\n` +
`${pc.white(" cd packages/backend")}\n` +
`${pc.white(` ${cmd} convex env set POLAR_ORGANIZATION_TOKEN your_polar_token`)}\n` +
`${pc.white(` ${cmd} convex env set POLAR_WEBHOOK_SECRET your_polar_webhook_secret`)}\n` +
`${pc.white(` Optional: ${cmd} convex env set POLAR_SERVER production`)}\n` +
`${pc.cyan("•")} Configure a Polar webhook to ${pc.white("https://<your-convex-site-url>/polar/events")}`
);
}

const envPath = backend === "self" ? "apps/web/.env" : "apps/server/.env";
return `${pc.bold("Polar Payments Setup:")}\n${pc.cyan("•")} Get access token & product ID from ${pc.underline("https://sandbox.polar.sh/")}\n${pc.cyan("•")} Set POLAR_ACCESS_TOKEN in ${envPath}`;
}
Expand Down
8 changes: 2 additions & 6 deletions apps/cli/src/prompts/payments.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import { DEFAULT_CONFIG } from "../constants";
import type { Auth, Backend, Frontend, Payments } from "../types";
import { splitFrontends } from "../utils/compatibility-rules";
import { UserCancelledError } from "../utils/errors";
import { isCancel, navigableSelect } from "./navigable";

export async function getPaymentsChoice(
payments?: Payments,
auth?: Auth,
backend?: Backend,
frontends?: Frontend[],
_frontends?: Frontend[],
) {
if (payments !== undefined) return payments;

if (backend === "none") {
return "none" as Payments;
}

const isPolarCompatible =
auth === "better-auth" &&
backend !== "convex" &&
(frontends?.length === 0 || splitFrontends(frontends).web.length > 0);
const isPolarCompatible = auth === "better-auth";

if (!isPolarCompatible) {
return "none" as Payments;
Expand Down
9 changes: 1 addition & 8 deletions apps/cli/src/utils/compatibility-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export function validatePaymentsCompatibility(
payments: Payments | undefined,
auth: Auth | undefined,
_backend: Backend | undefined,
frontends: Frontend[] = [],
_frontends: Frontend[] = [],
): ValidationResult {
if (!payments || payments === "none") return Result.ok(undefined);

Expand All @@ -410,13 +410,6 @@ export function validatePaymentsCompatibility(
"Polar payments requires Better Auth. Please use '--auth better-auth' or choose a different payments provider.",
);
}

const { web } = splitFrontends(frontends);
if (web.length === 0 && frontends.length > 0) {
return validationErr(
"Polar payments requires a web frontend or no frontend. Please select a web frontend or choose a different payments provider.",
);
}
}

return Result.ok(undefined);
Expand Down
Loading
Loading