Overview
CEMAC uses Firebase as its backend platform, leveraging Firebase Authentication for user management and Firestore Database for data storage. This guide will walk you through setting up Firebase for your CEMAC instance.Prerequisites
- Google account
- Firebase project (or ability to create one)
- Node.js 18 or higher installed
Creating a Firebase Project
Access Firebase Console
Navigate to the Firebase Console and sign in with your Google account.
Create new project
Click Add project and follow these steps:
- Enter a project name (e.g., “CEMAC Production”)
- (Optional) Enable Google Analytics if you want usage insights
- Click Create project and wait for setup to complete
Add web app
From your project dashboard:
- Click the Web icon (
</>) to add a web app - Register your app with a nickname (e.g., “CEMAC Web”)
- (Optional) Check “Also set up Firebase Hosting” if deploying to Firebase
- Click Register app
Configuring Firebase Authentication
CEMAC uses Firebase Authentication to manage user access and secure API endpoints.Enable Authentication
In the Firebase Console, navigate to Authentication from the left sidebar and click Get started.
Configure sign-in methods
Add authorized domains
Under the Settings tab, add your application domains to the authorized domains list:
- For development:
localhost - For production: your actual domain (e.g.,
app.cemac.com)
Setting Up Firestore Database
Firestore is used to store inventory data, sales records, analytics, and user information.Create Firestore database
In the Firebase Console:
- Navigate to Firestore Database from the left sidebar
- Click Create database
Choose location
Select a database location closest to your users:
- us-central1 (Iowa) - Default, good for North America
- europe-west1 (Belgium) - Europe
- asia-northeast1 (Tokyo) - Asia
Configure security rules
Choose Start in production mode for now. We’ll configure detailed security rules next.Click Enable to create the database.
Set up security rules
Navigate to the Rules tab and replace the default rules with:Click Publish to apply the rules.
Create initial collections
Create the following collections to match CEMAC’s data structure:
users- User profiles and settingsinventory- Product inventory datasales- Sales transactionscategories- Product categoriesbrands- Product brandssuppliers- Supplier informationcustomers- Customer recordsalerts- System alerts and notifications
Firebase Admin SDK (Optional)
For backend operations, you may need the Firebase Admin SDK:Generate service account key
In Firebase Console:
- Go to Project Settings (gear icon) > Service accounts
- Click Generate new private key
- Confirm and download the JSON file
External API Integration
CEMAC uses an external API hosted athttps://cemac-api.vercel.app for backend operations. This API handles:
- User authentication via Firebase
- Database operations with Firestore
- Server-side business logic
The external API is pre-configured and deployed separately. You don’t need to deploy it yourself unless you’re forking the entire CEMAC project.
Connecting CEMAC to Firebase
Once Firebase is configured:Update environment variables
Testing Firebase Integration
Verify your Firebase setup is working:- Authentication Test: Try logging in with credentials
- Database Test: Check if data appears in Firestore console
- Security Test: Ensure unauthorized users cannot access data
Troubleshooting
Authentication errors
- Verify your API key is correct
- Check that Email/Password auth is enabled in Firebase Console
- Ensure your domain is in the authorized domains list
Permission denied errors
- Review Firestore security rules
- Verify user is authenticated before accessing data
- Check that collections exist in Firestore
CORS errors
- Add your domain to Firebase authorized domains
- Verify API key restrictions in Google Cloud Console
Best Practices
Next Steps
- Configure Environment Variables
- Set up Deployment
- Review API Endpoints