Keys
The space id and the two keys a Smoodly site uses, where each one may live, what the public one can reach, and how to rotate or revoke a key.
Three values
Your space's page at smoodly.io shows the three values your env file names. The env file is .env in an Astro project, Astro's own env file, and .env.local in a Next.js app:
SMOODLY_SPACE_IDserverThe space your content lives in, `sp_…`. Every read names it, and a key is refused by any other space.SMOODLY_SECRET_KEYserver onlyThe space's secret key, `sk_…`. The site reads with it, drafts included, and scripts write with it: the push, the seed, `export` and `import`. It reaches this space only. Never ship it to a browser, a client component or a public repository.SMOODLY_PUBLISHABLE_KEYserver and browserThe space's publishable key, `pk_…`. It reads published content and nothing else.The live site and its admin need the space id and the secret key. The admin's browser holds no key: it posts to Smoodly's API with the editor's session, and the API checks the session against the space's members. The starter's /api/preview route reads SMOODLY_PREVIEW_SECRET for draft previews outside the admin (Next.js only); leave it unset and the route refuses to turn draft mode on.
A preview space's values carry its name: the id is sp_preview_… (sp_eu_preview_… under the EU jurisdiction), and both keys carry the same preview. A production space's have no mark. An env file therefore shows which space it holds. A site needs smoodly 0.0.61 or newer to read a preview space; an older version refuses the key as not a Smoodly key. Deploying says when to add one.
SMOODLY_API_URL is the address of Smoodly's API, https://api.smoodly.io unless you set it. Set it only to reach another service address.
What the publishable key can reach
Treat it as public. Someone who has it, and nothing else, can read your published content over the API with plain fetch, from anywhere, and the media files by their URL.
They cannot:
- read a draft: drafts take the secret key;
- write, publish, delete or reorder anything: every write takes the secret key or an editor's session;
- see who your members are, or who is editing what: presence takes a member's session, never a key;
- open the admin: it needs a member's session.
Rotating a key
Rotate a key from the space page when someone who should not have it may have seen it, or on a schedule of your own. The space mints a new key and the old one keeps working for the time you choose, a day unless you say otherwise, so the site serves without a gap while you put the new key in your env file and your host's settings and redeploy. You can also end the old key at once: then every site still holding it stops reading until it has the new one.
Revoking a leaked key
Revoke a key that has leaked. It is refused from its next request, so revoke it once the new key is live: a site still holding it answers its pages with an error naming the key. Every read sends the key again, so a corrected key works on the next request without a restart.
Next, Deploying.