Private Chat requires environment variables to connect to Upstash Redis for real-time messaging and data storage.
Required variables
The REST URL for your Upstash Redis database. This URL is used to connect to your Redis instance via HTTP.Example: https://your-database.upstash.io
The authentication token for your Upstash Redis database. This token provides secure access to your Redis instance.Keep this token secret and never commit it to version control.
How they’re used
The application uses the @upstash/redis SDK which automatically reads these environment variables when you initialize Redis with Redis.fromEnv():
import { Redis } from "@upstash/redis";
export const redis = Redis.fromEnv()
This Redis instance is then used by the real-time messaging system to:
- Store and retrieve chat messages
- Manage room state
- Handle real-time subscriptions
Setting environment variables
Create .env.local file
In your project root, create a .env.local file: Add your credentials
Add your Upstash Redis credentials to the file:UPSTASH_REDIS_REST_URL=https://your-database.upstash.io
UPSTASH_REDIS_REST_TOKEN=your_token_here
Restart your development server
If your dev server is running, restart it to load the new environment variables:
Never commit your .env.local file to version control. Add it to your .gitignore file to prevent accidentally exposing your credentials.
Getting credentials
To get your Upstash Redis credentials, follow the Upstash setup guide.