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.

Authorization

Request

This endpoint does not take any parameters

Response Object

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

Returns an empty object.

Status/Error Codes

Was this helpful?

Create a new secret

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