deleteSecret( )
Deletes an existing secret by ID.
Description
The deleteSecret()
function returns a Promise that resolves when a secret from the Secrets Manager is deleted.
You can retrieve the id
parameter using the listSecretInfo()
function.
Note that the ID used here is the ID retrieved from listSecretInfo()
, not the secret name used by getSecret()
.
Note: Deleting a secret is irreversible and will break all code using the secret.
Syntax
function deleteSecret(id: string): Promise<void>
deleteSecret Parameters
NAME
TYPE
DESCRIPTION
The ID of the secret to be deleted.
Returns
Fulfilled - When the secret is deleted from the Secrets Manager. Rejected - Error message.
Return Type:
Was this helpful?
1import wixSecretsBackend from 'wix-secrets-backend';23export function deleteMySecret() {4 const id = "b741766c-eead-46fe-8e7f-fd01ff3d6e21";56 return wixSecretsBackend.deleteSecret(id)7 .then(() => {8 console.log("Secret deleted");9 })10 .catch((error) => {11 console.error(error);12 });13}
This example demonstrates how to delete the first secret stored in the Secrets Manager. First we retrieve the ID of the secret using the listSecretInfo() function. Then we delete the secret using the retrieved ID.
1import wixSecretsBackend from 'wix-secrets-backend';23export function deleteFirstSecret() {4 return wixSecretsBackend.listSecretInfo()5 .then((secrets) => {6 return wixSecretsBackend.deleteSecret(secrets[0].id);7 })8 .then(() => {9 console.log("Secret deleted");10 })11 .catch((error) => {12 console.error(error);13 });14}15