Retrieves the secret value specified by the secret name.
The getSecretValue()
function returns a Promise that resolves to the value of the secret with the specified given name.
Note: Only use a secret's value in the backend code. Returning the secret value in the frontend is a security risk.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function getSecretValue(name: string): Promise<GetSecretValueResponse>;
The name of the secret to get the value of.
import { secrets } from "wix-secrets-backend.v2";
import { getJSON } from "wix-fetch";
import { elevate } from "wix-auth";
const elevatedGetSecretValue = elevate(secrets.getSecretValue);
const elevatedListSecretInfo = elevate(secrets.listSecretInfo);
export function getSomeJSON() {
return elevatedGetSecretValue("myApiKeyName")
.then((secret) => {
return getJSON(`https://someapi.com/api/someendpoint?apiKey=${secret}`);
})
.catch((error) => {
console.error(error);
});
}
export function getFirstSecretValue() {
return elevatedListSecretInfo()
.then((secrets) => {
return elevatedGetSecretValue(secrets[0].name);
})
.catch((error) => {
console.error(error);
});
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.