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 (dashboard page code)
Copy Code
1import { secrets } from 'wix-secrets-backend.v2';23export function createNewSecret() {4 const secret = {5 name: 's3_secret_key',6 value: 'Fm8OfflH6bJOwWjenqAtLurLbkiMNvmhQHZV+118',7 description: 'AWS secret access key'8 };910 return secrets.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 */24
Create a new secret (export from backend code)
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { secrets } from 'wix-secrets-backend.v2';34export const createNewSecret = webMethod(Permissions.Anyone, () => {5 const secret = {6 name: 's3_secret_key',7 value: 'Fm8OfflH6bJOwWjenqAtLurLbkiMNvmhQHZV+118',8 description: 'AWS secret access key'9 };1011 return secrets.createSecret(secret)12 .then((id) => {13 return id;14 })15 .catch((error) => {16 console.error(error);17 });18});1920/*21 * Returns a Promise that resolves to:22 *23 * "5ec36ffb-2cec-489a-9c0e-d8f53fef5fd1"24 */25