create-perfect-template
Version:
Create a modern Next.js SaaS template with progressive feature activation
63 lines (52 loc) • 1.73 kB
text/typescript
// Service configuration with hierarchical dependencies
// CORE: Just Next.js - no auth, no db
// DATABASE: Requires auth (Clerk) + database (Convex)
// BILLING: Optional add-on for monetization
const hasClerkKeys = !!(
process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY &&
process.env.CLERK_SECRET_KEY
);
const hasConvexKeys = !!(
process.env.NEXT_PUBLIC_CONVEX_URL &&
process.env.CONVEX_DEPLOY_KEY
);
const hasAutumnKeys = !!(
process.env.NEXT_PUBLIC_AUTUMN_ORG_ID &&
process.env.AUTUMN_API_KEY
);
const hasAIKeys = !!(
process.env.AI_GATEWAY_API_KEY ||
process.env.OPENAI_API_KEY ||
process.env.ANTHROPIC_API_KEY
);
// If database is enabled, auth must be enabled too
const authEnabled = hasClerkKeys || hasConvexKeys;
const databaseEnabled = hasConvexKeys && authEnabled;
export const config = {
mode: databaseEnabled ? 'full' : 'core' as 'core' | 'full',
auth: {
enabled: authEnabled,
clerkPublishableKey: process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
clerkSecretKey: process.env.CLERK_SECRET_KEY,
},
database: {
enabled: databaseEnabled,
convexUrl: process.env.NEXT_PUBLIC_CONVEX_URL,
convexDeployKey: process.env.CONVEX_DEPLOY_KEY,
},
billing: {
enabled: hasAutumnKeys && authEnabled, // Billing requires auth
autumnOrgId: process.env.NEXT_PUBLIC_AUTUMN_ORG_ID,
autumnApiKey: process.env.AUTUMN_API_KEY,
},
ai: {
enabled: hasAIKeys,
gatewayApiKey: process.env.AI_GATEWAY_API_KEY,
openaiApiKey: process.env.OPENAI_API_KEY,
anthropicApiKey: process.env.ANTHROPIC_API_KEY,
},
};
export const isServiceEnabled = (service: keyof typeof config) => {
if (service === 'mode') return true;
return config[service].enabled;
};