Overview
Luis IT Repair uses Firebase as its backend infrastructure, providing authentication, Firestore database, Cloud Functions, and hosting capabilities. This guide walks you through setting up your Firebase project from scratch.
Prerequisites
Before you begin, ensure you have:
A Google account
Node.js 20 or higher installed
Firebase CLI installed globally: npm install -g firebase-tools
Project source code cloned locally
Initial Project Setup
Create Firebase Project
Go to Firebase Console
Click “Add project”
Enter your project name (e.g., hojaservice-3ab3d)
Enable Google Analytics (optional but recommended)
Click “Create Project”
Register Web App
In your Firebase project, click the web icon to add a web app
Register your app with a nickname (e.g., “Luis IT Repair Web”)
Copy the Firebase configuration object - you’ll need this next
Configure Firebase SDK
Update src/initializer/firebase.js with your Firebase configuration: src/initializer/firebase.js
import { initializeApp } from "firebase/app" ;
import { getAnalytics } from "firebase/analytics" ;
import { getFirestore } from "firebase/firestore" ;
import { getAuth } from "firebase/auth" ;
const firebaseConfig = {
apiKey: "YOUR_API_KEY" ,
authDomain: "your-project.firebaseapp.com" ,
projectId: "your-project-id" ,
storageBucket: "your-project.firebasestorage.app" ,
messagingSenderId: "YOUR_SENDER_ID" ,
appId: "YOUR_APP_ID" ,
measurementId: "YOUR_MEASUREMENT_ID"
};
// Initialize Firebase
const app = initializeApp ( firebaseConfig );
const analytics = getAnalytics ( app );
// Export Firestore and Auth instances
export const db = getFirestore ( app );
export const auth = getAuth ( app );
Never commit real Firebase credentials to public repositories. Use environment variables for production deployments.
Login to Firebase CLI
This opens your browser to authenticate with Google.
Initialize Firebase in Project
If not already initialized, run: Select the following features:
Firestore
Functions
Hosting
Your .firebaserc should look like: {
"projects" : {
"default" : "your-project-id"
}
}
Firestore Configuration
Security Rules
Firestore security rules control read/write access to your database. The system uses authentication-based access control:
rules_version = '2'
service cloud . firestore {
match / databases / { database } / documents {
// Authorized users collection
match / autorizados / { document =** } {
allow read , write : if request . auth != null ;
}
// Public read for customer status lookup
match / servicios / { document =** } {
allow read : if true ;
allow write : if request . auth != null ;
}
// Authenticated access for business data
match / clientes / { document =** } {
allow read , write : if request . auth != null ;
}
match / productos / { document =** } {
allow read , write : if request . auth != null ;
}
match / ventas / { document =** } {
allow read , write : if request . auth != null ;
}
match / cortes_caja / { document =** } {
allow read , write : if request . auth != null ;
}
match / folios / { document =** } {
allow read , write : if request . auth != null ;
}
match / contadores_folio / { document =** } {
allow read , write : if request . auth != null ;
}
match / egresos_diarios / { document =** } {
allow read , write : if request . auth != null ;
}
match / empleados / { document =** } {
allow read , write : if request . auth != null ;
}
// POS mobile scans sync queue
match / pos_mobile_scans / { document =** } {
allow read , write : if request . auth != null ;
}
}
}
The servicios collection allows public read access so customers can check their service status without authentication.
Deploy Security Rules
firebase deploy --only firestore:rules
Database Indexes
The system uses automatic indexing. If you need custom composite indexes, add them to firestore.indexes.json:
{
"indexes" : [],
"fieldOverrides" : []
}
Deploy indexes with:
firebase deploy --only firestore:indexes
Cloud Functions Setup
Install Functions Dependencies
Configure Environment Variables
For the MercadoLibre search function, set environment variables: firebase functions:config:set \
meli.client_id="YOUR_MELI_CLIENT_ID" \
meli.client_secret="YOUR_MELI_CLIENT_SECRET" \
meli.refresh_token="YOUR_MELI_REFRESH_TOKEN" \
meli.access_token="YOUR_MELI_ACCESS_TOKEN"
The MercadoLibre integration is optional. The function will work in public mode without credentials.
Deploy Functions
Deploy all functions: firebase deploy --only functions
Or deploy specific function: firebase deploy --only functions:mlSearch
Available Functions
Searches MercadoLibre products for price comparison in POS. Region: southamerica-east1
Endpoint: /api/ml/search
Method: GETQuery Parameters:
q (required): Search query
limit (optional): Result limit (default: 12)
debug (optional): Enable debug mode (1 or 0)
Response: {
"results" : [
{
"id" : "web-1" ,
"title" : "Product Name" ,
"price" : 299.99 ,
"permalink" : "https://..." ,
"condition" : "new" ,
"sold_quantity" : 150
}
]
}
Firebase Hosting
Build Production Bundle
This creates an optimized production build in the dist/ directory.
Configure Hosting
Your firebase.json should include: {
"hosting" : {
"public" : "dist" ,
"ignore" : [
"firebase.json" ,
"**/.*" ,
"**/node_modules/**"
],
"headers" : [
{
"source" : "/index.html" ,
"headers" : [
{
"key" : "Cache-Control" ,
"value" : "no-cache, no-store, must-revalidate"
}
]
},
{
"source" : "/assets/**" ,
"headers" : [
{
"key" : "Cache-Control" ,
"value" : "public, max-age=31536000, immutable"
}
]
}
],
"rewrites" : [
{
"source" : "/api/ml/search" ,
"function" : {
"functionId" : "mlSearch" ,
"region" : "southamerica-east1"
}
},
{
"source" : "**" ,
"destination" : "/index.html"
}
]
}
}
Deploy Hosting
firebase deploy --only hosting
Preview Before Deploy (Optional)
firebase hosting:channel:deploy preview
Authentication Setup
Enable Email/Password Authentication
Go to Firebase Console > Authentication
Click “Get Started”
Select “Email/Password” as sign-in method
Enable it and save
Create Admin User
Go to Authentication > Users
Click “Add User”
Enter email and password
Copy the UID
Add to Authorized Users Collection
In Firestore, create a document in the autorizados collection: {
"uid" : "<user-uid>" ,
"email" : "[email protected] " ,
"rol" : "Administrador" ,
"online" : false ,
"lastActive" : null ,
"versionVista" : "1.5.0"
}
Complete Deployment
Deploy everything at once:
This deploys:
Firestore rules and indexes
Cloud Functions
Hosting configuration and static files
Monitoring and Maintenance
View Logs
# Functions logs
firebase functions:log
# Specific function
firebase functions:log --only mlSearch
Usage Dashboard
Monitor your Firebase usage at:
Firestore Usage
# Check Firestore usage
firebase projects:list
firebase use < project-i d >
Troubleshooting
Check your Firestore security rules. Ensure the user is authenticated and has the correct permissions. firebase deploy --only firestore:rules
Check Node.js version (must be 20)
Ensure functions build successfully: cd functions && npm run build
Check for TypeScript errors
Verify firebase.json configuration
CORS Errors with Functions
The mlSearch function already includes CORS headers. If you add new functions, include: response . set ( "Access-Control-Allow-Origin" , "*" );
response . set ( "Access-Control-Allow-Methods" , "GET,POST,OPTIONS" );
response . set ( "Access-Control-Allow-Headers" , "Content-Type" );
Ensure your firebase.json includes the SPA rewrite rule: {
"source" : "**" ,
"destination" : "/index.html"
}
Next Steps
POS Settings Configure IVA, billing, and ticket printing
Appearance Customize theme, colors, and fonts