Search.../

createSecret( )

Developer Preview

Creates a new secret.

Description

The createSecret() function returns a Promise that resolves secret ID when the secret is created.

Notes:

  • The secret's name cannot start with 'wix' or be identical to an existing secret's name.
  • Don't leave private keys in your code. Leaving them in your code is a security risk. Make sure to delete the keys from the code after running createSecret().
Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

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

createSecret Parameters

NAME
TYPE
DESCRIPTION
secret
Secret

Fields of a new secret.

Returns

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

Return Type:

Promise<
CreateSecretResponse
>
NAME
TYPE
DESCRIPTION
_id
string

The globally-unique ID assigned to the secret.

Was this helpful?

Create a new secret

Copy Code
1import { secrets } from 'wix-secrets-backend.v2';
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 secrets.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 */