Skip to main content

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

1

Create Firebase Project

  1. Go to Firebase Console
  2. Click “Add project”
  3. Enter your project name (e.g., hojaservice-3ab3d)
  4. Enable Google Analytics (optional but recommended)
  5. Click “Create Project”
2

Register Web App

  1. In your Firebase project, click the web icon to add a web app
  2. Register your app with a nickname (e.g., “Luis IT Repair Web”)
  3. Copy the Firebase configuration object - you’ll need this next
3

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.
4

Login to Firebase CLI

firebase login
This opens your browser to authenticate with Google.
5

Initialize Firebase in Project

If not already initialized, run:
firebase init
Select the following features:
  • Firestore
  • Functions
  • Hosting
Your .firebaserc should look like:
.firebaserc
{
  "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:
firestore.rules
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:
firestore.indexes.json
{
  "indexes": [],
  "fieldOverrides": []
}
Deploy indexes with:
firebase deploy --only firestore:indexes

Cloud Functions Setup

1

Install Functions Dependencies

cd functions
npm install
2

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.
3

Build Functions

npm run build
4

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: GET
Query 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

1

Build Production Bundle

npm run build
This creates an optimized production build in the dist/ directory.
2

Configure Hosting

Your firebase.json should include:
firebase.json
{
  "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"
      }
    ]
  }
}
3

Deploy Hosting

firebase deploy --only hosting
4

Preview Before Deploy (Optional)

firebase hosting:channel:deploy preview

Authentication Setup

1

Enable Email/Password Authentication

  1. Go to Firebase Console > Authentication
  2. Click “Get Started”
  3. Select “Email/Password” as sign-in method
  4. Enable it and save
2

Create Admin User

  1. Go to Authentication > Users
  2. Click “Add User”
  3. Enter email and password
  4. Copy the UID
3

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:
firebase deploy
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-id>

Troubleshooting

Check your Firestore security rules. Ensure the user is authenticated and has the correct permissions.
firebase deploy --only firestore:rules
  1. Check Node.js version (must be 20)
  2. Ensure functions build successfully: cd functions && npm run build
  3. Check for TypeScript errors
  4. Verify firebase.json configuration
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

Build docs developers (and LLMs) love