Context / Problem
The template relies on environment variables (like BETTER_AUTH_SECRET, DATABASE_URL). If a new developer forgets to copy .env.example to .env, or misses a key, the app might start but fail later with a confusing runtime error deep within the authentication logic.
Proposed Solution
Validate required environment variables immediately upon startup. If a required variable is missing, throw a clear, human-readable error, causing pnpm dev to fail fast.
Implementation Details
- You can use Zod in a Nuxt Server Plugin or utilize a community module like
@t3-oss/env-nuxt.
- Example using Zod in a startup hook or module:
import { z } from 'zod';
const envSchema = z.object({
DATABASE_URL: z.string().url(),
BETTER_AUTH_SECRET: z.string().min(1),
BETTER_AUTH_URL: z.string().url(),
// ...
});
envSchema.parse(process.env); // Will throw a clear error if invalid
Acceptance Criteria
Context / Problem
The template relies on environment variables (like
BETTER_AUTH_SECRET,DATABASE_URL). If a new developer forgets to copy.env.exampleto.env, or misses a key, the app might start but fail later with a confusing runtime error deep within the authentication logic.Proposed Solution
Validate required environment variables immediately upon startup. If a required variable is missing, throw a clear, human-readable error, causing
pnpm devto fail fast.Implementation Details
@t3-oss/env-nuxt.Acceptance Criteria
.envvariables fails immediately with a descriptive error message.