Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Stivenz3/Nexu/llms.txt

Use this file to discover all available pages before exploring further.

Nexu lesson content — lessons, blocks, and questions — lives in Firestore, not in the application bundle. Seed scripts are the mechanism the development team uses to write that content from local JSON files into the shared Firebase project nexu-156ce. This page covers how authentication works for seeds, how to run them for the first time on a new machine, and how to diagnose common errors.

Three distinct authentication layers

Seed scripts use a completely different authentication mechanism than the Nexu app. Understanding the distinction prevents hours of debugging.
┌─────────────────────────────────────────────────────────────────┐
│  YOUR GOOGLE ACCOUNT (Owner/Editor on console.firebase.google.com) │
└───────────────────────────────┬─────────────────────────────────┘

        ┌───────────────────────┼───────────────────────┐
        ▼                       ▼                       ▼
 npx firebase login    gcloud auth application-    npm run seed:lesson1
                       default login
        │                       │                       │
        │                       │                       │
 Authenticates the       Stores Application         Reads local JSON files
 Firebase CLI (deploy,   Default Credentials        and writes them to
 firebase use, emulators) so Node.js scripts        Firestore in nexu-156ce
                         (firebase-admin) can
                         act on your behalf
LayerToolUsed by
Firebase CLI (npx firebase login)Firebase CLIfirebase deploy, firebase use, emulators
Application Default Credentials (gcloud auth application-default login)Google Cloud SDKNode.js seed scripts via firebase-admin
Firebase Auth (email/password)Firebase AuthApp users logging in through the browser
The seed script does not use the Firebase Auth session from the browser, and the browser app never runs the seed. The seed uses applicationDefault() from firebase-admin, which reads the credentials created by gcloud auth application-default login.

Prerequisites

Before running seeds on a new machine, ensure the following are installed and available in your PATH:
  • Node.js 18+ and npm
  • Google Cloud SDK (gcloud command) — install instructions
  • A Google account with Owner or Editor role in Firebase project nexu-156ce — verify in Firebase Console → Project Settings → Users and permissions

First-time setup on a new machine

1
Install frontend dependencies
2
From the repository root:
3
npm install
4
This installs the React app’s dependencies. Seed-script dependencies (firebase-admin) are installed separately and automatically when you run a seed command.
5
Log in to the Firebase CLI
6
npx firebase login
7
A browser window opens. Sign in with the team Google account that has Owner or Editor access to nexu-156ce. Then set the active project so all firebase commands target Nexu:
8
npx firebase use nexu-156ce
9
Authenticate Application Default Credentials
10
gcloud auth application-default login
11
A browser window opens. Sign in with the same team Google account used in the previous step. This stores credentials at ~/.config/gcloud/application_default_credentials.json (Linux/macOS) or %APPDATA%\gcloud\application_default_credentials.json (Windows). The seed-lesson.mjs script reads these credentials via applicationDefault() from firebase-admin.
12
This step is required once per machine (or after the credentials expire or you switch accounts).
13
Run the lesson seed
14
npm run seed:lesson1
15
Expected output:
16
Eliminando datos previos de lesson_01_higiene_personal...
Insertando lección, bloques y preguntas...
Listo (lesson_01): 1 lección, 8 bloques, 23 preguntas.
lessonId: lesson_01_higiene_personal
17
(Optional) Deploy rules if changed
18
Only needed if you edited firestore.rules or firestore.indexes.json:
19
npm run firebase:deploy:rules
20
See Firebase Rules for full details.
21
Start the app
22
npm run dev
23
The app reads lesson data from the shared Firebase project nexu-156ce, which now contains the seeded content. Navigate to /ruta after registering or logging in to see Lesson 1.

Available seed commands

CommandScript invokedWhat it seeds
npm run seed:lesson1node scripts/seed-lesson.mjs 01Deletes and re-uploads Lesson 1 from firestore-seed/lesson_01/
npm run seed:lesson2node scripts/seed-lesson.mjs 02Deletes and re-uploads Lesson 2 from firestore-seed/lesson_02/
Both commands first run npm install --prefix scripts to ensure firebase-admin is installed in the scripts/ directory before executing the seed. This keeps seed dependencies isolated and out of the Vercel build.

What the seed script does internally

The single parameterized script scripts/seed-lesson.mjs performs the following steps every time it runs:
  1. Validates inputs — checks that a two-digit lesson key was provided (e.g., 01) and that the corresponding firestore-seed/lesson_XX/ directory exists with lesson.json, blocks.json, and questions.json.
  2. Initializes firebase-admin — calls initializeApp({ credential: applicationDefault(), projectId: 'nexu-156ce' }). This is why Application Default Credentials are required.
  3. Deletes existing data for the target lesson:
    • All documents in lessons/{lessonId}/blocks/
    • All documents in lessons/{lessonId}/questions/
    • The root lessons/{lessonId} document
  4. Writes new data from the local JSON files:
    • lesson.json → one document at lessons/{lessonId}
    • blocks.json → one document per block at lessons/{lessonId}/blocks/{blockId}
    • questions.json → one document per question at lessons/{lessonId}/questions/{questionId}
  5. Warns if isActive is false in lesson.json, since an inactive lesson will not appear in the /ruta learning path.

What the seed does NOT touch

Running a seed is safe for the following data — it will never be modified or deleted:
  • User accounts (/users/{uid})
  • User lesson progress (/users/{uid}/lessonProgress/)
  • Certificates (/certificates/ and /certificatePublic/)
  • Firestore security rules (firestore.rules) — deploy those separately with npm run firebase:deploy:rules
  • Vercel hosting or any other lesson’s content
The seed overwrites lesson content in the shared Firebase project nexu-156ce. Every developer on the team and every user of the production app reads from this same database. Running npm run seed:lesson1 will replace Lesson 1’s content for everyone simultaneously — including any active users in the middle of a session.Always coordinate with the team in your group chat before running a seed, especially for Lesson 1 which is already live.

Common errors and fixes

The seed script could not find Application Default Credentials on this machine.Fix: Run the following and complete the browser login with the team Google account (Owner/Editor on nexu-156ce):
gcloud auth application-default login
Then re-run npm run seed:lesson1.
Your Google account authenticated successfully but does not have sufficient permissions to write to Firestore in project nexu-156ce.Fix: Ask a project owner to verify your account in Firebase Console → Project Settings → Users and permissions. Your email must appear with the Owner or Editor role. The email must match exactly the account you used for gcloud auth application-default login.
A dependency in package.json was added or changed without updating pnpm-lock.yaml. Vercel requires the lockfile to be in sync before it will run pnpm install.Fix: Run the following locally and commit the updated lockfile:
pnpm install --lockfile-only
git add pnpm-lock.yaml
git commit -m "chore: sync pnpm lockfile"
git push
Note: scripts/package.json uses npm and has no effect on pnpm-lock.yaml.
The seed completed without errors but the lesson does not show up on the /ruta learning path.Fix — check isActive: Open firestore-seed/lesson_XX/lesson.json and confirm "isActive": true. If it is false, the seed script itself will print a warning. Update the JSON and re-run the seed.Fix — check project ID: Open .env.local and confirm VITE_FIREBASE_PROJECT_ID=nexu-156ce. If this variable is missing or points to a different project, the app is querying a Firestore database that the seed did not touch.
The Firebase CLI is not installed globally, or it is not in your system PATH.Fix: Never rely on a globally installed firebase binary. Always use the npx-based commands provided in package.json:
# Instead of: firebase login
npx firebase login

# Instead of: firebase use nexu-156ce
npx firebase use nexu-156ce

# To deploy rules:
npm run firebase:deploy:rules
The npm run firebase:deploy:rules script already uses npx firebase-tools internally, so it works regardless of global installs.

Build docs developers (and LLMs) love