feat: validate all required env vars at startup

This commit is contained in:
Jennie Robinson Faber 2026-04-04 12:34:49 +01:00
parent 255518a6a8
commit 1875f16d48

View file

@ -1,9 +1,24 @@
export default defineNitroPlugin(() => {
const config = useRuntimeConfig()
const required = [
'MONGODB_URI',
'JWT_SECRET',
'RESEND_API_KEY',
'HELCIM_API_TOKEN',
'NUXT_PUBLIC_HELCIM_TOKEN',
]
if (!config.jwtSecret) {
console.error('FATAL: JWT_SECRET environment variable is not set. Server cannot start without it.')
console.error('Set JWT_SECRET in your .env file or environment variables.')
const missing = required.filter((key) => {
// Check both process.env and runtime config where applicable
if (key === 'JWT_SECRET') {
const config = useRuntimeConfig()
return !config.jwtSecret
}
return !process.env[key]
})
if (missing.length > 0) {
console.error(`FATAL: Missing required environment variables: ${missing.join(', ')}`)
console.error('Set these in your .env file or environment variables.')
process.exit(1)
}
})