Skip to content

Commit 54a6844

Browse files
Add async call to access secret
1 parent 8af3536 commit 54a6844

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/content/docs/secrets-store/integrations/workers.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ If [using the Dashboard](#via-dashboard), make sure you already have a Workers a
2222

2323
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.
2424

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 default store.
2626

2727
## 1. Set up account secrets in Secrets Store
2828

@@ -155,15 +155,17 @@ export default {
155155
export default {
156156
async fetch(request, env) {
157157
// Example of using the secret safely in an API request
158-
let response = await fetch("https://api.example.com/data", {
159-
headers: { "Authorization": `Bearer ${env.MY_SECRETS_STORE_SECRET}` },
158+
const APIkey = await env.MY_SECRET_NAME.get()
159+
160+
const response = await fetch("https://api.example.com/data", {
161+
headers: { "Authorization": `Bearer ${env.APIKey}` },
160162
});
161163

162164
if (!response.ok) {
163165
return new Response("Failed to fetch data", { status: response.status });
164166
}
165167

166-
let data = await response.json();
168+
const data = await response.json();
167169
return new Response(JSON.stringify(data), {
168170
headers: { "Content-Type": "application/json" },
169171
});

0 commit comments

Comments
 (0)