Encrypting Secrets | Next.js Firebase SaaS Kit
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 secretsfunction storeApiKey(key: string) { const encryptedKey = encrypt(key); return storeKeyInFirestore(encryptedKey);}// retrieving secretsfunction getApiKey(id: string) { const encryptedKey = await getApiKeyFromFirestore(id); return decrypt(encryptedKey);}