Settings and secrets
Keep settings and passwords for your website, like API keys, safe.
Sometimes your website needs information that doesn't belong in the code. For example:
- an API key: a kind of password that lets your website use another service, like a payment system or a map;
- a password for your admin page;
- a setting, like the email address contact forms are sent to.
You keep these under Settings & secrets. Developers call these environment variables. Your website can read them, but they aren't in your files, so they're not on GitHub either.
#Adding a setting in the dashboard
- Open your website in the dashboard and go to Settings & secrets.
- Scroll down. Below your list of settings is the Add a setting block.
- Enter a name, in capitals with underscores, like
MOLLIE_API_KEYorCONTACT_EMAIL. - Enter the value and switch Secret on or off. A secret can't be viewed afterwards, only replaced. Names containing
KEY,SECRET,PASSWORDorTOKENare marked as secret automatically. - Save the setting. Click Add (or Replace, if the name already exists). A yellow Restart needed notice appears: click Restart now in it. Your website only reads the new setting after a restart.
#With your AI or the terminal
You can also ask your AI:
- "Set the CONTACT_EMAIL setting to info@bakerysmith.com."
Or do it yourself in the terminal, in your website's folder:
npx -y @switchboard-host/cli@latest env set CONTACT_EMAIL info@bakerysmith.com
npx -y @switchboard-host/cli@latest env set MOLLIE_API_KEY --secret
npx -y @switchboard-host/cli@latest env listWithout a value (like the key above) the terminal asks for it, so the key doesn't end up in your
history. Remove a setting with npx -y @switchboard-host/cli@latest env unset NAME.
#Using the setting in your website
Tell your AI which setting exists, for example: "The Mollie key is in the MOLLIE_API_KEY setting. Use it for payments." Your AI knows how to read it.
For the preview on your own computer, your AI puts the same settings in a .env file in your
website folder. That file never goes to Switchboard or GitHub.
#Names that are taken
Some settings are managed by Switchboard itself, like DATABASE_URL and PUBLIC_URL. You can't set
those yourself. Names starting with SB_, EMAIL_, AWS_, S3_ or SWITCHBOARD_ are reserved
too. See platform variables.