# Environment variables

> The environment variables Editlet reads in production, and which values stay secret.

Set these variables on your production host. Dev mode needs none of them. Never commit real values.

## Auth handler

`handleRequest` from `editlet/auth` reads these at run time ([Deploy the auth handler](https://editlet.gunkin.dev/docs/auth-handler.md)).

| Variable | Required | Value |
|---|---|---|
| `GITHUB_CLIENT_ID` | yes | Client ID of your GitHub App |
| `GITHUB_CLIENT_SECRET` | yes | Client secret of your GitHub App, stored as a secret |
| `ALLOWED_ORIGINS` | yes | Origins that may receive tokens, separated by commas or spaces, `*` only in the host. Empty refuses every sign-in |
| `PUBLIC_URL` | under a path or behind a proxy | Public HTTPS URL of the handler, such as `https://example.com/api/editlet/oauth` |

## Live preview (Next.js)

The `editlet/next/preview` route reads these when `admin.preview` is on ([Live preview](https://editlet.gunkin.dev/docs/live-preview.md)).

| Variable | Required | Value |
|---|---|---|
| `CMS_GITHUB_TOKEN` | yes | Fine-grained token with read-only Contents access to the repository |
| `CMS_PREVIEW_SECRET` | yes | At least 32 characters, for example from `openssl rand -base64 32` |

## Editor settings (build time)

`withEditlet` and the Astro integration read these at build time, also from `.env` files. The matching `admin`
option wins.

| Variable | Default | Value |
|---|---|---|
| `CMS_SESSION_MINUTES` | `60` | Minutes without clicks or typing before the editor signs out, a whole number from 1 to 1440 (`admin.sessionMinutes`) |
| `EDITLET_PARAM` | `editlet` | Query parameter that opens the editor: letters, digits, `_` and `-`, starting with a letter (`admin.param`) |

The repository comes from `admin.repo`, else from Vercel's `VERCEL_GIT_REPO_OWNER` and `VERCEL_GIT_REPO_SLUG`, else
from `GITHUB_REPOSITORY` in GitHub Actions. You do not set these by hand.

## Public values

The build writes the repository, base branch, `authUrl`, session length, preview flag and a custom param to the public
file `/editlet/config.json`. `GITHUB_CLIENT_SECRET`, `CMS_GITHUB_TOKEN` and `CMS_PREVIEW_SECRET` stay on the server.
