ghostguild-org/server/plugins/validate-env.js

24 lines
657 B
JavaScript

export default defineNitroPlugin(() => {
const required = [
'MONGODB_URI',
'JWT_SECRET',
'RESEND_API_KEY',
'HELCIM_API_TOKEN',
'NUXT_PUBLIC_HELCIM_TOKEN',
]
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)
}
})