Prerequisites
Before starting, ensure you have:- A Google account
- Node.js installed (for local development)
- Basic understanding of Firebase services
Create a Firebase Project
Navigate to Firebase Console
Go to Firebase Console and sign in with your Google account.
Create New Project
Click Add Project and enter your project name (e.g., “stockpro-production”).
Choose a descriptive project name that indicates the environment (production, staging, development).
Configure Google Analytics
You can optionally enable Google Analytics for your project. This is useful for tracking user behavior and app performance.For most inventory management systems, analytics can be disabled unless you need detailed usage metrics.
Enable Firebase Services
Enable Authentication
Navigate to Authentication
In your Firebase project console, click Authentication in the left sidebar.
Enable Email/Password Sign-in
- Click on the Sign-in method tab
- Click on Email/Password provider
- Enable the Email/Password toggle
- Click Save
StockPro uses email/password authentication as implemented in
public/js/login.js:36Enable Firestore Database
Navigate to Firestore
In your Firebase project console, click Firestore Database in the left sidebar.
Select Security Rules Mode
Choose Start in production mode for now. We’ll configure proper security rules later.
Get Firebase Configuration
Register Web App
- In the Firebase Console, click the Project Overview gear icon
- Select Project settings
- Scroll down to Your apps section
- Click the web icon
</>to register a web app - Enter an app nickname (e.g., “StockPro Web App”)
- Check Also set up Firebase Hosting if you plan to use Firebase Hosting
- Click Register app
Configure StockPro
Update Firebase Configuration
Replace the configuration inpublic/js/firebase.js with your project’s credentials:
Configuration Object Explained
| Field | Description | Security Level |
|---|---|---|
apiKey | Identifies your Firebase project to Google servers | Public (safe in client code) |
authDomain | Domain used for authentication redirects | Public |
projectId | Unique identifier for your Firebase project | Public |
storageBucket | Cloud Storage bucket for file uploads | Public |
messagingSenderId | Used for Firebase Cloud Messaging | Public |
appId | Unique identifier for your Firebase app | Public |
measurementId | Google Analytics measurement ID | Public |
Firebase security is enforced through Security Rules, not by hiding configuration values. All these values are safe to expose in client-side code.
Security Best Practices
Use Environment-Specific Projects
Create separate Firebase projects for each environment:Implement Security Rules
API Key Restrictions (Optional)
While Firebase API keys are designed to be public, you can add restrictions:Navigate to Google Cloud Console
Go to Google Cloud Console
Verify Installation
Test your Firebase configuration:Next Steps
Security Rules
Configure Firestore security rules to protect your data
Deployment
Deploy StockPro to production hosting
Troubleshooting
”Firebase: Error (auth/invalid-api-key)”
Cause: The API key in your configuration is incorrect. Solution: Double-check that you copied the correctapiKey from Firebase Console.
”Missing or insufficient permissions”
Cause: Firestore security rules are blocking access. Solution: Configure proper security rules. See Security Rules.”Firebase: Error (auth/unauthorized-domain)”
Cause: Your hosting domain is not authorized in Firebase. Solution:- Go to Firebase Console → Authentication → Settings
- Scroll to Authorized domains
- Add your deployment domain (e.g.,
yourdomain.com)