Skip to content

Commit f4d59d6

Browse files
SaraVieiraCompuIves
authored andcommitted
Add docs on secrets (codesandbox#1693)
* add docs on secrets * Update packages/homepage/content/docs/5-secrets.md Co-Authored-By: SaraVieira <[email protected]> * Update packages/homepage/content/docs/5-secrets.md Co-Authored-By: SaraVieira <[email protected]> * Update packages/homepage/content/docs/5-secrets.md Co-Authored-By: SaraVieira <[email protected]> * Update packages/homepage/content/docs/5-secrets.md Co-Authored-By: SaraVieira <[email protected]> * Apply suggestions from code review Co-Authored-By: SaraVieira <[email protected]> * Update packages/homepage/content/docs/5-secrets.md Co-Authored-By: SaraVieira <[email protected]>
1 parent 36f3e08 commit f4d59d6

File tree

6 files changed

+61
-0
lines changed

6 files changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: "Secrets"
3+
authors: ["SaraVieira"]
4+
description: "CodeSandbox allows you to store secrets so you don't share your keys"
5+
---
6+
7+
## What are secrets?
8+
9+
Secrets are used to hide sensitive information in your application that you don't want the world to see, and are implemented in CodeSandbox using environment variables.
10+
The most common use case for using secrets is with API keys.
11+
12+
Secrets values will not be transferred between forks and **can only be used in container sandboxes**.
13+
14+
## Adding secrets in CodeSandbox
15+
16+
You can control the secrets in your Server Control Panel, before adding any it should look like this:
17+
18+
![No Secrets](./images/secrets-1.png)
19+
20+
Let's say you want to add a Google Maps API key. You can do it like so:
21+
22+
![Map Secrets](./images/secrets-2.png)
23+
24+
Pro tip: It's always a good practice to name your secrets all in uppercase.
25+
26+
After clicking the "Save Secret" button the secret is added, the sandbox is restarted, and you can see the list of all your secrets above the form.
27+
28+
![Secrets](./images/secrets-3.png)
29+
30+
As said earlier, secrets are environment variables, meaning they are defined on `process.env`. In the example above, we can read the API key from `process.env.GOOGLE_MAPS_API_KEY`.
31+
32+
Like so:
33+
34+
```js
35+
var http = require('http');
36+
37+
const key = process.env.GOOGLE_MAPS_API_KEY;
38+
39+
http
40+
.createServer(function(req, res) {
41+
res.write('This your maps key' + key);
42+
res.end(); //end the response
43+
})
44+
.listen(8080);
45+
```
46+
47+
The sandbox used is [https://codesandbox.io/s/2v6xq474kj](https://codesandbox.io/s/2v6xq474kj)
48+
49+
## Editing secrets in CodeSandbox
50+
51+
Our UI also gives you the option to edit or even remove a secret, by hovering the secret you want to edit you will see these two icons:
52+
53+
![Icons](./images/secrets-4.png)
54+
55+
If you click on the pencil you will see it will turn into a form again where you can edit the name and value of your secret:
56+
57+
![Icons](./images/secrets-5.png)
58+
59+
This will take effect automatically and it will also restart your sandbox to make sure we use the new value.
60+
61+
To delete you can click on the `x` icon after the pencil one and this one will also restart your sandbox.
49 KB
Loading
51.5 KB
Loading
44.5 KB
Loading
21.5 KB
Loading
25.2 KB
Loading

0 commit comments

Comments
 (0)