• Blog
  • Documentation
  • Courses
  • Changelog
  • AI Starters
  • UI Kit
  • FAQ
  • Supamode
    New
  • Pricing

Launch your next SaaS in record time with Makerkit, a React SaaS Boilerplate for Next.js and Supabase.

Makerkit is a product of Makerkit Pte Ltd (registered in the Republic of Singapore)Company Registration No: 202407149CFor support or inquiries, please contact us

About
  • FAQ
  • Contact
  • Verify your Discord
  • Consultation
  • Open Source
  • Become an Affiliate
Product
  • Documentation
  • Blog
  • Changelog
  • UI Blocks
  • Figma UI Kit
  • AI SaaS Starters
License
  • Activate License
  • Upgrade License
  • Invite Member
Legal
  • Terms of License
    • Building Features
    • Commands
    • Code Style
    • Security Rules
    • Translations and Locales
    • Sending Emails
    • Writing API Routes
    • Validating API payload with Zod
    • Logging
    • Enable CORS
    • Encrypting Secrets
    • User Roles

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.

tsx
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);
}