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
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:
Was this helpful?
Create a new secret
1import wixSecretsBackend from 'wix-secrets-backend';23export function createNewSecret() {4 const secret = {5 name: "s3_secret_key",6 value: "Fm8OfflH6bJOwWjenqAtLurLbkiMNvmhQHZV+118",7 description: "AWS secret access key"8 };910 return wixSecretsBackend.createSecret(secret)11 .then((id) => {12 return id;13 })14 .catch((error) => {15 console.error(error);16 });17}1819/*20 * Returns a Promise that resolves to:21 *22 * "5ec36ffb-2cec-489a-9c0e-d8f53fef5fd1"23 */