---
title: "Environment variables"
description: "Complete reference of Shelve environment variables"
canonical_url: "https://shelve.cloud/docs/self-hosting/environment-variables"
---
# Environment variables

> Complete reference of Shelve environment variables

This page documents all environment variables available in Shelve, their usage and configuration.

## Required variables

These environment variables are **mandatory** for Shelve to function:

### `DATABASE_URL`

- **Type**: String (PostgreSQL URL)
- **Required**: ✅ Yes
- **Description**: Connection URL to your PostgreSQL database
- **Format**: `postgresql://username:password@host:port/database`
- **Example**: `postgresql://user:pass@db.example.com:5432/shelve`

<callout type="info">

**Recommendation**: Use [Neon](https://neon.tech) with [Vercel integration](https://vercel.com/integrations/neon) for simplified configuration.

</callout>

### `NUXT_APP_SECRET`

- **Type**: String
- **Required**: ✅ Yes
- **Constraint**: Minimum 32 characters
- **Description**: Nuxt `appSecret`. Shelve signs session cookies and encrypts login state with it. Changing it signs every user out.
- **Generation**: `openssl rand -base64 48`

### `NUXT_PRIVATE_ENCRYPTION_KEY`

- **Type**: String
- **Required**: ✅ Yes
- **Constraint**: Minimum 32 characters
- **Description**: Key Encryption Key (KEK). Used to seal the per-project Data Encryption Keys (DEKs) that actually protect variable values. See [Encryption](https://shelve.cloud/docs/core-features/encryption) for the full model.
- **Generation**: `openssl rand -base64 48`

<callout type="warning">

**Important**: Never modify these keys after first deployment, it would make existing data inaccessible. A safe KEK rotation flow (re-sealing all DEKs) is on the roadmap.

</callout>

Environment validation rejects example values for these keys, such as a value that starts with `your-` or `your_`.

### `NUXT_PUBLIC_APP_URL`

- **Type**: String (URL origin)
- **Required**: ✅ Yes, except on Vercel
- **Description**: URL your users open Shelve at. Shelve uses it to build the links it sends: sign-in emails, team invitations, welcome emails, and the CLI login page.
- **Format**: `https://shelve.example.com`, with no path
- **On Vercel**: Optional. Without it, links use the domain the request came in on.
- **In local development** (`nuxt dev`): Optional, for the same reason.
- **Elsewhere**: Required. Shelve doesn't build links from the request's `Host` header, because the client controls it. Without this variable, sign-in emails, invitations, and CLI login fail with a server error that names it, and welcome emails aren't sent.

## Authentication configuration

Shelve now supports multiple authentication methods. **You need to configure at least one method** for users to be able to create accounts and log in:

### Option 1: Email authentication only (Recommended)

- Configure `NUXT_PRIVATE_RESEND_API_KEY` and `NUXT_PRIVATE_SENDER_EMAIL`
- Users can sign up and log in using their email with OTP codes
- No OAuth setup required

### Option 2: OAuth only

- Configure at least one OAuth provider (GitHub or Google)
- Users authenticate via OAuth providers
- No email service required

### Option 3: Both methods (Maximum flexibility)

- Configure both email service and OAuth providers
- Users can choose their preferred authentication method
- Recommended for production environments

## Authentication variables

Shelve supports multiple authentication methods. You need **at least one authentication method** configured:

### Email authentication (OTP)

For email-based authentication using one-time passwords (OTP), you need to configure email service variables below.

### OAuth authentication (Optional)

OAuth providers offer an alternative authentication method alongside email authentication.

Register `https://<your-domain>/auth/github` and `https://<your-domain>/auth/google` as the callback (redirect) URLs in your OAuth apps, without wildcard matching.

### `BETTER_AUTH_URL`

- **Type**: URL
- **Required**: 🔶 Recommended outside Vercel
- **Description**: The public URL of your Shelve instance, such as `https://shelve.example.com`. OAuth callbacks are built from it. On Vercel it defaults to the production domain, or to the preview's own URL on previews.

### GitHub OAuth

To enable GitHub authentication, configure these two variables together:

#### `NUXT_OAUTH_GITHUB_CLIENT_ID`

- **Type**: String
- **Required**: 🔶 Optional (must be paired with CLIENT_SECRET)
- **Description**: Client ID of your GitHub OAuth App
- **How to get**: [GitHub Developer Settings](https://github.com/settings/developers)

#### `NUXT_OAUTH_GITHUB_CLIENT_SECRET`

- **Type**: String
- **Required**: 🔶 Optional (must be paired with CLIENT_ID)
- **Description**: Client Secret of your GitHub OAuth App
- **How to get**: [GitHub Developer Settings](https://github.com/settings/developers)

### Google OAuth

To enable Google authentication, configure these two variables together:

#### `NUXT_OAUTH_GOOGLE_CLIENT_ID`

- **Type**: String
- **Required**: 🔶 Optional (must be paired with CLIENT_SECRET)
- **Description**: Client ID of your Google OAuth App
- **How to get**: [Google Cloud Console](https://console.cloud.google.com/)

### OAuth on preview deployments (Optional)

Preview URLs change per branch, so GitHub and Google can't list them. Set both variables below to send preview OAuth logins through production instead: production receives the provider's callback and hands the signed-in user back to the preview. Set both, with the same values, on **Production** and **Preview**: production needs them to accept the callbacks it receives for previews.

#### `OAUTH_PROXY_URL`

- **Type**: URL
- **Description**: Your production URL, such as `https://app.shelve.cloud`. Only its `/auth/github` and `/auth/google` need to be registered with the providers.

#### `OAUTH_PROXY_SECRET`

- **Type**: String
- **Constraint**: Minimum 32 characters, must be paired with `OAUTH_PROXY_URL`
- **Description**: Encrypts the profile production hands back to the preview. Use a dedicated value, never `NUXT_APP_SECRET`.
- **Generation**: `openssl rand -base64 48`

#### `NUXT_OAUTH_GOOGLE_CLIENT_SECRET`

- **Type**: String
- **Required**: 🔶 Optional (must be paired with CLIENT_ID)
- **Description**: Client Secret of your Google OAuth App
- **How to get**: [Google Cloud Console](https://console.cloud.google.com/)

## GitHub integration variables

### `NUXT_PRIVATE_GITHUB_PRIVATE_KEY`

- **Type**: String (Base64)
- **Required**: 🔶 Optional
- **Description**: Private key of your GitHub App for advanced integration
- **Usage**: Automatic secrets synchronization with GitHub
- **Format**: PKCS#8 encoded in base64

<callout type="info">

**Required setup**: This variable requires a GitHub App configured with comprehensive permissions including Secrets, Variables, and more. See the [Vercel documentation](https://shelve.cloud/docs/self-hosting/vercel#advanced-github-integration) for the complete permissions list.

</callout>

#### How to get this key

1. Create a GitHub App in your organization
2. Download the private key (.pem format)
3. Convert it to PKCS#8 format and encode in base64:

```bash
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in private-key.pem | base64 -w 0
```

## Email service variables

### `NUXT_PRIVATE_RESEND_API_KEY`

- **Type**: String
- **Required**: ⚠️ Required for email authentication (OTP)
- **Format**: Must start with `re_`
- **Description**: Resend API key for sending emails including OTP codes
- **Usage**: OTP authentication, welcome emails, notifications
- **How to get**: [Resend Dashboard](https://resend.com/dashboard)

<callout type="warning">

**Important**: This variable is now required if you want to use email authentication (OTP). Without it, users can only authenticate via OAuth providers.

</callout>

<callout type="info">

**Recommendation**: Use [Resend](https://resend.com) with [Vercel integration](https://vercel.com/integrations/resend) for automated configuration.

</callout>

### `NUXT_PRIVATE_SENDER_EMAIL`

- **Type**: String (Email)
- **Required**: ⚠️ Required for email authentication (required if RESEND_API_KEY is set)
- **Description**: Sender email address for OTP codes and notifications
- **Format**: `noreply@yourdomain.com`
- **Constraint**: Must be a valid email verified in Resend

## Administration variables

### `NUXT_PRIVATE_ADMIN_EMAILS`

- **Type**: String (comma-separated list)
- **Required**: 🔶 Optional
- **Description**: List of emails with access to admin features
- **Format**: `admin@app.com,admin2@app.com`
- **Usage**: Access to statistics, user management

### `NUXT_PRIVATE_AUDIT_RETENTION_DAYS`

- **Type**: Number (days)
- **Required**: 🔶 Optional
- **Default**: `30`
- **Description**: Audit log entries older than this are deleted. `0` keeps every entry.
- **Format**: `90`

### `NUXT_PRIVATE_ALLOWED_ORIGINS`

- **Type**: String (comma-separated list of URLs)
- **Required**: 🔶 Optional
- **Description**: Allowed origins for CORS requests
- **Format**: `https://app.com,https://www.app.com`
- **Usage**: Security, CSRF attack prevention

### `NUXT_PRIVATE_TRUST_PROXY`

- **Type**: Number
- **Required**: 🔶 Optional (set it when Shelve runs behind a reverse proxy outside Vercel)
- **Default**: `0`
- **Description**: How many reverse proxies in front of Shelve add the client address to `X-Forwarded-For`. Shelve reads the entry the nearest of them added. With `0`, it ignores the header and uses the connection's address, which behind a proxy is the proxy's.
- **Format**: `1`
- **Usage**: Client IPs in audit logs, API key IP allowlists and rate limits. On Vercel, which rewrites the header, it works without this setting.

## Automatic validation

Shelve uses an automatic environment variables validation system:

- **Startup validation**: The application checks all required variables
- **Format validation**: URLs, emails, minimum lengths are verified
- **Consistency validation**: OAuth pairs are validated together
- **Explicit error messages**: In case of error, logs indicate exactly what's wrong

## Configuration by environment

### Local development

Create a `.env` file at the root of your project:

```bash
# Copy from .env.example
DATABASE_URL=postgresql://localhost:5432/shelve_dev
NUXT_APP_SECRET=<output of: openssl rand -base64 48>
NUXT_PRIVATE_ENCRYPTION_KEY=<output of: openssl rand -base64 48>
```

### Production on Vercel

Configure all variables in your Vercel project settings:

1. Vercel Project > Settings > Environment Variables
2. Add each variable with its value
3. Select appropriate environments (Production, Preview, Development)

## Troubleshooting

### Common errors

**"Session password must be at least 32 characters long"**

- Generate a longer key: `openssl rand -base64 48`

**"Must be a valid PostgreSQL URL"**

- Check the format: `postgresql://user:pass@host:port/db`
- Test the connection to your database

**"GitHub OAuth validation failed"**

- Make sure you have defined CLIENT_ID AND CLIENT_SECRET together
- Verify that the values are correct

**"Resend API key must start with 're_'"**

- Use the Resend API key, not a test key
- Verify that you copied the complete key

### Missing environment variables

Vercel deployment logs will show:

```text
🔐 Auth configuration validated:
  GitHub OAuth: ✅/❌
  Google OAuth: ✅/❌  
  Email Service: ✅/❌
```

This allows you to quickly check which integrations are active.


## Sitemap

See the full [sitemap](https://shelve.cloud/sitemap.md) for all pages.
