Skip to main content

Provider Configuration

The template uses a centralized ConfigService singleton to manage all external service providers. Each provider is configured through Zod-validated schemas with automatic feature detection -- providers are enabled when their required credentials are present.

ConfigService Architecture

The ConfigService at lib/config/config-service.ts is a server-only singleton that validates all environment variables at startup:

import { configService } from '@/lib/config';

// Access configuration sections
const appUrl = configService.core.APP_URL;
const stripeEnabled = configService.payment.stripe.enabled;
const posthogEnabled = configService.analytics.posthog.enabled;

The service is organized into six sections, each with its own Zod schema:

SectionAccessorSchema File
CoreconfigService.coreschemas/core.schema.ts
AuthconfigService.authschemas/auth.schema.ts
EmailconfigService.emailschemas/email.schema.ts
PaymentconfigService.paymentschemas/payment.schema.ts
AnalyticsconfigService.analyticsschemas/analytics.schema.ts
IntegrationsconfigService.integrationsschemas/integrations.schema.ts

Tree-Shakeable Imports

Individual sections can be imported directly for better tree-shaking:

import { coreConfig, paymentConfig, analyticsConfig } from '@/lib/config';

const url = coreConfig.APP_URL;
const stripeKey = paymentConfig.stripe.publishableKey;

Validation at Startup

All configuration is validated with Zod on first import. Invalid values trigger .catch() fallbacks where possible, while truly unrecoverable errors throw at startup:

const result = appConfigSchema.safeParse(rawConfig);
if (!result.success) {
throw new Error(`[ConfigService] Configuration errors:\n${...}`);
}

Authentication Providers

Defined in lib/config/schemas/auth.schema.ts. OAuth providers auto-detect enablement:

const oauthProviderSchema = z.object({
clientId: z.string().optional(),
clientSecret: z.string().optional(),
}).transform((data) => ({
...data,
enabled: Boolean(data.clientId && data.clientSecret),
}));

Supported OAuth Providers

ProviderClient ID VariableClient Secret Variable
GoogleGOOGLE_CLIENT_IDGOOGLE_CLIENT_SECRET
GitHubGITHUB_CLIENT_IDGITHUB_CLIENT_SECRET
MicrosoftMICROSOFT_CLIENT_IDMICROSOFT_CLIENT_SECRET
FacebookFB_CLIENT_IDFB_CLIENT_SECRET
Twitter/XX_CLIENT_IDX_CLIENT_SECRET
LinkedInLINKEDIN_CLIENT_IDLINKEDIN_CLIENT_SECRET

Supabase Auth Backend

const supabaseConfigSchema = z.object({
url: z.string().url().optional(),
anonKey: z.string().optional(),
}).transform((data) => ({
...data,
enabled: Boolean(data.url && data.anonKey),
}));
VariableDescription
NEXT_PUBLIC_SUPABASE_URLSupabase project URL
NEXT_PUBLIC_SUPABASE_ANON_KEYSupabase anonymous key

Additional Auth Settings

VariableDefaultDescription
AUTH_SECRET--Required for session signing
COOKIE_SECRET--Cookie encryption secret
COOKIE_DOMAIN'localhost'Cookie domain
COOKIE_SECUREfalseHTTPS-only cookies
JWT_ACCESS_TOKEN_EXPIRES_IN'15m'Access token TTL
JWT_REFRESH_TOKEN_EXPIRES_IN'7d'Refresh token TTL

Payment Providers

Defined in lib/config/schemas/payment.schema.ts. Each provider is auto-enabled when its required credentials are set.

Stripe

Auto-enabled when secretKey and publishableKey are present:

VariableDescription
STRIPE_SECRET_KEYServer-side secret key
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEYClient-side publishable key
STRIPE_WEBHOOK_SECRETWebhook signature verification
NEXT_PUBLIC_STRIPE_FREE_PRICEPrice ID for free plan
NEXT_PUBLIC_STRIPE_STANDARD_PRICE_IDPrice ID for standard plan
NEXT_PUBLIC_STRIPE_PREMIUM_PRICE_IDPrice ID for premium plan

LemonSqueezy

Auto-enabled when apiKey and storeId are present:

VariableDescription
LEMONSQUEEZY_API_KEYAPI key
LEMONSQUEEZY_STORE_IDStore identifier
LEMONSQUEEZY_WEBHOOK_SECRETWebhook secret
LEMONSQUEEZY_WEBHOOK_URLWebhook endpoint URL
LEMONSQUEEZY_TEST_MODEEnable test mode ('true'/'false')
NEXT_PUBLIC_LEMONSQUEEZY_FREE_VARIANT_IDVariant ID for free plan
NEXT_PUBLIC_LEMONSQUEEZY_STANDARD_VARIANT_IDVariant ID for standard plan
NEXT_PUBLIC_LEMONSQUEEZY_PREMIUM_VARIANT_IDVariant ID for premium plan

Polar

Auto-enabled when accessToken and organizationId are present:

VariableDefaultDescription
POLAR_ACCESS_TOKEN--API access token
POLAR_ORGANIZATION_ID--Organization ID
POLAR_WEBHOOK_SECRET--Webhook secret
POLAR_SANDBOXtrueSandbox mode (set 'false' for production)
POLAR_API_URL--Custom API URL
NEXT_PUBLIC_POLAR_FREE_PLAN_ID--Plan ID for free tier
NEXT_PUBLIC_POLAR_STANDARD_PLAN_ID--Plan ID for standard tier
NEXT_PUBLIC_POLAR_PREMIUM_PLAN_ID--Plan ID for premium tier

Product Pricing Display

VariableDefaultDescription
NEXT_PUBLIC_PRODUCT_PRICE_FREE0Display price for free plan
NEXT_PUBLIC_PRODUCT_PRICE_STANDARD10Display price for standard plan
NEXT_PUBLIC_PRODUCT_PRICE_PREMIUM20Display price for premium plan

Email Providers

Defined in lib/config/schemas/email.schema.ts.

SMTP

Auto-enabled when host, user, and password are all present:

VariableDefaultDescription
SMTP_HOST--SMTP server hostname
SMTP_PORT587SMTP server port
SMTP_USER--SMTP authentication username
SMTP_PASSWORD--SMTP authentication password

Resend

Auto-enabled when apiKey is present:

VariableDescription
RESEND_API_KEYResend API key

Novu

Auto-enabled when apiKey is present:

VariableDescription
NOVU_API_KEYNovu API key

Email Settings

VariableDefaultDescription
COMPANY_NAME'Ever Works'Company name in email templates
EMAIL_PROVIDER'resend'Active email provider ('resend', 'novu')
EMAIL_FROM--Sender email address
EMAIL_SUPPORT--Support email address

Analytics Providers

Defined in lib/config/schemas/analytics.schema.ts.

PostHog

Auto-enabled when key is present:

VariableDefaultDescription
NEXT_PUBLIC_POSTHOG_KEY--PostHog project API key
NEXT_PUBLIC_POSTHOG_HOST'https://us.i.posthog.com'PostHog host URL
POSTHOG_DEBUGfalseEnable debug mode
POSTHOG_SESSION_RECORDING_ENABLEDtrueEnable session recording
POSTHOG_AUTO_CAPTUREfalseAuto-capture events
POSTHOG_EXCEPTION_TRACKINGtrueTrack exceptions
POSTHOG_PERSONAL_API_KEY--Personal API key (admin dashboard)
POSTHOG_PROJECT_ID--Project ID (admin dashboard)

Sentry

Auto-enabled when dsn is present:

VariableDefaultDescription
NEXT_PUBLIC_SENTRY_DSN--Sentry DSN
SENTRY_ORG--Sentry organization slug
SENTRY_PROJECT--Sentry project name
SENTRY_AUTH_TOKEN--Auth token for source maps
SENTRY_ENABLE_DEVfalseEnable in development
SENTRY_DEBUGfalseDebug mode

reCAPTCHA

Auto-enabled when both siteKey and secretKey are present:

VariableDescription
NEXT_PUBLIC_RECAPTCHA_SITE_KEYClient-side site key
RECAPTCHA_SECRET_KEYServer-side secret key

Vercel Analytics

VariableDefaultDescription
NEXT_PUBLIC_SPEED_INSIGHTS_ENABLEDfalseEnable Vercel Speed Insights
NEXT_PUBLIC_SPEED_INSIGHTS_SAMPLE_RATE0.5Sampling rate (0--1)

Exception Tracking Provider

VariableDefaultDescription
EXCEPTION_TRACKING_PROVIDER'posthog''posthog', 'sentry', or 'none'

Checking Provider Status

import { configService } from '@/lib/config';

// Check if Stripe is configured
if (configService.payment.stripe.enabled) {
// Stripe is ready to use
}

// Check if any email provider is available
const hasEmail = configService.email.resend.enabled
|| configService.email.novu.enabled
|| configService.email.smtp.enabled;

// List enabled OAuth providers
const oauthProviders = ['google', 'github', 'microsoft', 'facebook', 'twitter', 'linkedin']
.filter(p => configService.auth[p].enabled);
PathDescription
lib/config/config-service.tsConfigService singleton
lib/config/schemas/auth.schema.tsAuth provider schemas
lib/config/schemas/payment.schema.tsPayment provider schemas
lib/config/schemas/email.schema.tsEmail provider schemas
lib/config/schemas/analytics.schema.tsAnalytics provider schemas
lib/config/schemas/integrations.schema.tsIntegration provider schemas
lib/config/schemas/core.schema.tsCore configuration schema
lib/config/types.tsTypeScript type definitions
lib/config/index.tsBarrel export
.env.exampleFull environment variable reference