Encrypting Secrets

When storing sensitive data, such as API keys, you must ensure to encrypt your data in Firestore. Here is how we can encrypt and decrypt it.

When storing sensitive data, such as API keys, you must ensure to encrypt your data in Firestore.

To use these utilities, you must provide an environment variable named SECRET_KEY. This should be provided safely using your CI since it's a secret key.

MakerKit provides some utilities to encrypt and decrypt your data.

import { encrypt, decrypt } from '~/core/generic/crypto'; // storing secrets function storeApiKey(key: string) { const encryptedKey = encrypt(key); return storeKeyInFirestore(encryptedKey); } // retrieving secrets function getApiKey(id: string) { const encryptedKey = await getApiKeyFromFirestore(id); return decrypt(encryptedKey); }

Subscribe to our Newsletter
Get the latest updates about React, Remix, Next.js, Firebase, Supabase and Tailwind CSS