Search.../

createSecret( )

Creates a new secret.

Description

The createSecret() function returns a Promise that resolves to the newly created secret's ID when a secret has been created in the Secrets Manager. Secrets created by this function are available in the Secrets Manager section in your site's dashboard, just like any other secret created using the UI.

Note:

  • The secret's name cannot start with wix or be identical to an existing secret's name.

  • Do not leave private keys in your code! Leaving them in is a security risk. Either delete the keys from the code after running createSecret(), or pass the parameters in using the Functional Testing tool.

Syntax

function createSecret(secret: Secret): Promise<string>

createSecret Parameters

NAME
TYPE
DESCRIPTION
secret
Secret

The object including the fields of a new secret to be stored.

Returns

Fulfilled - The ID of the created secret. Rejected - Error message.

Return Type:

Promise<string>

Was this helpful?

Create a new secret

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import wixSecretsBackend from 'wix-secrets-backend';
3
4export const createNewSecret = webMethod(Permissions.Anyone, () => {
5 const secret = {
6 name: "s3_secret_key",
7 value: "Fm8OfflH6bJOwWjenqAtLurLbkiMNvmhQHZV+118",
8 description: "AWS secret access key"
9 };
10
11 return wixSecretsBackend.createSecret(secret)
12 .then((id) => {
13 return id;
14 })
15 .catch((error) => {
16 console.error(error);
17 });
18});
19
20/*
21 * Returns a Promise that resolves to:
22 *
23 * "5ec36ffb-2cec-489a-9c0e-d8f53fef5fd1"
24 */