Skip to main content
Concordia requires several environment variables for database connections, authentication, email, and API configuration.

Setup

Create a .env file in the root directory:
Then configure the variables according to your environment.

Database Configuration

boolean
default:"false"
Controls which database to use during development:
  • true - Use test database (DATABASE_URL_TEST)
  • false - Use local or production database
boolean
default:"false"
Whether to connect to the production database:
  • true - Use production database (DATABASE_URL_PROD)
  • false - Use local or test database
Never set USE_PROD_DB=true in development unless you know what you’re doing.
string
required
PostgreSQL connection string for local development database.Format:
Example:
string
required
PostgreSQL connection string for test database used during automated testing.Format:
Example:
string
required
PostgreSQL connection string for production database.Format (Neon):
Example:
Always use SSL (sslmode=require) for production database connections.

Authentication Configuration

string
required
Secret key used to sign JWT tokens and secure sessions. Must be a strong random string.Generation:
Example:
Never commit this secret to version control. Generate a unique value for each environment.
string
required
The base URL where your application is accessible. Used for generating callback URLs and verification links.Development:
Production:
Do not include a trailing slash.

SMTP Email Configuration

Concordia uses SMTP for sending transactional emails (verification, password reset, notifications).
string
required
The name of your SMTP provider. Common values:
  • gmail
  • sendgrid
  • mailgun
  • custom
string
required
The email address or username for SMTP authentication.
string
required
The password or app-specific password for SMTP authentication.
For Gmail, use an App Password instead of your account password.
string
required
The “From” email address used in outgoing emails.

Optional SMTP Configuration

string
Custom SMTP server hostname. If not set, automatically determined from SMTP_PROVIDER.
number
default:"587"
SMTP server port. Common values:
  • 587 - TLS (recommended)
  • 465 - SSL
  • 25 - Unencrypted (not recommended)
boolean
default:"false"
Whether to use SSL/TLS:
  • true - Use SSL (port 465)
  • false - Use STARTTLS (port 587)
boolean
default:"true"
Whether to use connection pooling for better performance.
number
default:"5"
Maximum number of simultaneous SMTP connections in the pool.
number
default:"1000"
Time window in milliseconds for rate limiting.
number
default:"5"
Maximum number of emails to send within the rate limit window.

Alternative Email Provider: Resend

As an alternative to SMTP, you can use Resend for email delivery:
string
API key from your Resend account. When set, Resend will be used instead of SMTP.
To use Resend, comment out or remove SMTP variables and set only RESEND_API_KEY.

Application Configuration

string
default:"development"
The environment mode for Node.js. Affects logging, error handling, and optimizations.Valid values:
  • development - Development mode with verbose logging
  • production - Production mode with optimizations
  • test - Test mode for automated testing
string
Public-facing API URL used by client-side code. Must be accessible from the browser.Development:
Production:
Variables prefixed with PUBLIC_ are exposed to client-side code. Never put secrets in PUBLIC_ variables.

Complete Example Configuration

Here’s a complete .env file template with all variables:
.env

Testing Your Configuration

Test Database Connection

Test SMTP Configuration

This will attempt to send a test email and report any configuration issues.

Environment-Specific Files

Create .env.development:

Security Best Practices

Add .env* to your .gitignore:
.gitignore
Use cryptographically secure random values:
Never reuse the same BETTER_AUTH_SECRET across development, staging, and production.
Change authentication secrets and API keys periodically, especially after:
  • Team member departures
  • Security incidents
  • Suspected compromise
Use database users with minimal required permissions:
  • Development: Full access to dev database only
  • Production: No DDL permissions, only DML (SELECT, INSERT, UPDATE, DELETE)

Troubleshooting

Error: Error: connect ECONNREFUSEDSolutions:
  1. Ensure PostgreSQL is running:
  2. Check connection string format
  3. Verify username, password, and database name
  4. Test with npm run db:check
Error: Invalid login: 535-5.7.8 Username and Password not acceptedSolutions:
  1. For Gmail: Use an App Password, not your account password
  2. Check SMTP_USER and SMTP_PASS are correct
  3. Verify SMTP provider settings
  4. Test with npm run smtp:check
Error: JsonWebTokenError: invalid signatureSolutions:
  1. Ensure BETTER_AUTH_SECRET is set and matches between environments
  2. Check for whitespace or newlines in the secret
  3. Regenerate the secret if corrupted
Issue: Variables are undefined at runtimeSolutions:
  1. Ensure .env file is in the project root
  2. Restart the development server after changing .env
  3. Check for typos in variable names
  4. Verify dotenv is configured in astro.config.mjs

Next Steps

Database Setup

Learn about the database schema and migrations

Authentication

Configure authentication and user management