Benefiting from Supabase Vault
Supabase Vault is an extension within the Supabase database (enabled by default) that allows you to easily manage and encrypt secrets. For instance, you can store API keys or environment variables inside of it, and then use them within your database with Edge Functions (which we look at in the next chapter), or even inside your application. Let me show you how it works.
Creating secrets in the Vault and reading them
To create a secret, simply call the vault.create_secret()
function, as follows:
SELECT vault.create_secret( 'THE_ACTUAL_SECRET', 'A_SECRET_NAME', 'Just some description' );
Running this will confirm its creation by returning the specific UUID of the secret:
Figure 12.6: Running vault.create_secret
This key is encrypted and stored in the vault
schema inside the secrets
table. If you want to read it, you can do so using a special view: