You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Secrets Store] Fix examples and review workers guide (#21603)
* Add async call to access secret
* Remove extra env. from fixed auth bearer
* Replace default store by first store
* Add async call to first code example and fix env.<binding name>
* Remove top level scope example
* Further adjustments
* More consistent naming: binding vs secret_name examples
* Opt for binding variable in h3
Copy file name to clipboardExpand all lines: src/content/docs/secrets-store/integrations/workers.mdx
+13-27Lines changed: 13 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,13 +20,13 @@ This is different from Workers [Variables and Secrets](/workers/configuration/se
20
20
21
21
If [using the Dashboard](#via-dashboard), make sure you already have a Workers application. Refer to the [Workers get started](/workers/get-started/dashboard/) for guidance.
22
22
23
-
You should also have a store created under the Secrets Store tab on the Dashboard. The default store in your account is automatically created when a user with [Super Administrator or Secrets Store Admin role](/secrets-store/access-control/) interacts with it.
23
+
You should also have a store created under the Secrets Store tab on the Dashboard. The first store in your account is created automatically when a user with [Super Administrator or Secrets Store Admin role](/secrets-store/access-control/) interacts with it.
24
24
25
-
You can also use the [Wrangler command](/workers/wrangler/commands/#secrets-store-store)`secrets-store store create <name>` to create your default store.
25
+
You can also use the [Wrangler command](/workers/wrangler/commands/#secrets-store-store)`secrets-store store create <name>` to create your first store.
26
26
27
27
## 1. Set up account secrets in Secrets Store
28
28
29
-
If there are no account secrets yet, follow the steps below. You must have a [Super Administrator or a Secrets Store Admin role](/secrets-store/access-control/) within your Cloudflare account.
29
+
If there are no secrets in the store yet, follow the steps below. You must have a [Super Administrator or a Secrets Store Admin role](/secrets-store/access-control/) within your Cloudflare account.
30
30
31
31
:::note
32
32
You may also add account secrets directly from the Workers settings on the dashboard. You can skip to [step 2](#via-dashboard) to do that.
@@ -38,13 +38,13 @@ Use the [Wrangler command](/workers/wrangler/commands/#secrets-store-secret) `se
38
38
To use the following example, replace the store ID and secret name by your actual data. You can find and copy the store ID from the [Secrets Store tab](https://dash.cloudflare.com/?to=/:account/secrets-store/) on the dashboard. A secret name cannot contain spaces.
[Bindings](/workers/runtime-apis/bindings/) are located on the `env` object, which can be accessed in several ways. Two examples are presented below. For further options, refer to the [Workers documentation](/workers/runtime-apis/bindings/#how-to-access-env).
133
+
[Bindings](/workers/runtime-apis/bindings/) are located on the `env` object. To access the secret you first need an asynchronous call.
135
134
136
-
### Import `env` from `cloudflare:workers`
137
135
138
-
```js
139
-
import { env } from"cloudflare:workers";
140
-
importApiClientfrom"example-api-client";
141
-
142
-
// MY_SECRETS_STORE_SECRET is now usable in top-level scope
143
-
let apiClient =ApiClient.new({ apiKey:env.MY_SECRETS_STORE_SECRET });
144
-
145
-
exportdefault {
146
-
fetch(req) {
147
-
// you can use apiClient configured before any request is handled
148
-
},
149
-
};
150
-
```
151
-
152
-
### Pass `env` as an argument to `fetch`
136
+
### Call `get()` on the binding variable
153
137
154
138
```js
155
139
exportdefault {
156
140
asyncfetch(request, env) {
157
141
// Example of using the secret safely in an API request
158
-
let response =awaitfetch("https://api.example.com/data", {
0 commit comments