Environment Variables (Local)
In a SonicJs application, environment variables serve as dynamic configuration settings that can be utilized to control various aspects of the application's behavior. These variables are external to the codebase and are set in the operating system or the hosting environment.
They are particularly useful for storing sensitive information such as API keys, database credentials, or other configuration details that may vary across different deployment environments (e.g., development, testing, production). By utilizing environment variables, SonicJs applications can achieve greater flexibility, security, and portability, as developers can adjust configurations without modifying the source code.
Environment variable are managed at the BOTTOM of your /wrangler.toml
file, for example:
// ... other setting above, environment variables go at the bottom
[vars]
datadog_apikey = 'abc123abc123'
datadog_service = 'local.sonicjs.com'
useAuth = 'false'
Environment Variables (Deployed on Cloudflare)
To add environment variables via the dashboard:
- Log in to Cloudflare dashboard and select your account.
- Select Workers & Pages.
- In Overview, select your Worker > Settings.
- Under Environment Variables, select Add variable.
- Input a Variable name and its value, which will be made available to your Worker.
- (Optional) To add multiple environment variables, select Add variable.
- Select Save to implement your changes.
Available Environment Variables
Here are the available environment variables you can configure in your SonicJs application:
Authentication Settings
Authentication Settings
Note: For the latest environment variables and their default values, please refer to the example configuration at: wrangler.example.toml
- Name
INVALIDATE_USER_SESSIONS
- Type
- boolean
- Description
When set to true, invalidates all existing user sessions, forcing users to log in again
- Name
REQUIRE_EMAIL_CONFIRMATION
- Type
- boolean
- Description
Controls whether users need to confirm their email address after registration
- Name
USERS_CAN_REGISTER
- Type
- boolean
- Description
Enables or disables user self-registration functionality
Caching
- Name
DISABLED_CACHE
- Type
- boolean
- Description
When true, disables all caching functionality in the application
Email Configuration
- Name
RESEND_API_KEY
- Type
- string
- Description
API key for the Resend email service
- Name
EMAIL_FROM
- Type
- string
- Description
Email address used as the sender for all system emails
- Name
EMAIL_BASE_URL
- Type
- string
- Description
Base URL of your application, used for generating email links
- Name
EMAIL_FROM_NAME
- Type
- string
- Description
Display name used for the sender in system emails
- Name
EMAIL_SEND_WELCOME_EMAIL
- Type
- boolean
- Description
Controls whether welcome emails are sent to new users
One-Time Password (OTP) Settings
- Name
ONE_TIME_PASSWORD_CHARACTER_LENGTH
- Type
- number
- Description
Length of generated one-time passwords
- Name
ONE_TIME_PASSWORD_EXPIRATION_TIME
- Type
- number
- Description
OTP expiration time in milliseconds (default: 20 minutes)
- Name
ONE_TIME_PASSWORD_EMAIL_SUBJECT
- Type
- string
- Description
Subject line for emails containing one-time passwords
Testing Mode
- Name
TESTING_MODE
- Type
- boolean
- Description
Enables testing endpoints and functionality. Should be set to false in production.