Required Variables
These environment variables must be set for the SDK to function:Your Wacht API key for authentication. This key is sent as a Bearer token in all API requests.Example:
wacht_sk_1234567890abcdefThe base URL of your Wacht frontend deployment. Used for API requests and fetching configuration.Example:
https://your-app.wacht.ioNote: Include the protocol (https://) and exclude trailing slashes.Optional Variables
PEM-encoded public key for JWT signature verification. If not provided, the SDK will automatically fetch it from the
/.well-known/jwk endpoint.Format: Must include PEM headers and footers.Setting Environment Variables
Using a .env File
Create a.env file in your project root:
dotenv crate:
Shell Export
Docker
In yourDockerfile or docker-compose.yml:
Kubernetes
Using ConfigMaps and Secrets:Platform-Specific Setup
Heroku
AWS Lambda
Using AWS Systems Manager Parameter Store:Vercel
Set invercel.json:
Security Best Practices
1. Never Commit Secrets
Add to.gitignore:
2. Use Secret Management
For production, use proper secret management:- AWS Secrets Manager
- HashiCorp Vault
- Azure Key Vault
- Google Secret Manager
3. Principle of Least Privilege
Create API keys with minimal required permissions:4. Rotate Keys Regularly
Implement key rotation:Debugging
Verify Environment Variables
Enable Debug Logging
Set Rust log level:Common Issues
Environment variable not found
Environment variable not found
Symptom:
environment variable not foundSolutions:- Verify variable names are spelled correctly
- Ensure variables are exported (not just set)
- Check if running in correct environment
- Restart your application after setting variables
Invalid characters in API key
Invalid characters in API key
Symptom:
invalid header valueSolution: Ensure the API key doesn’t contain:- Newlines or spaces
- Non-ASCII characters
- Special shell characters that need escaping
URL parsing errors
URL parsing errors
Symptom:
invalid URLSolutions:- Include protocol:
https:// - Remove trailing slashes
- Ensure valid hostname
- Check for typos
Next Steps
- Configuration - Programmatic configuration options
- Authentication - Setting up JWT validation
- Quick Start - Get started with the SDK
