# Firebase / Firestore

Used by the [build playbook](https://www.ihatereading.lol/build.md) on ihatereading.lol.

### Firebase / Firestore

Kind: database

Official links:

- [Firebase Console](https://console.firebase.google.com/)
- [Create a web app](https://firebase.google.com/docs/web/setup)
- [Firestore](https://firebase.google.com/docs/firestore)
- [Firestore security rules](https://firebase.google.com/docs/firestore/security/get-started)
- [Admin / service account](https://firebase.google.com/docs/admin/setup)
- [firebase npm](https://www.npmjs.com/package/firebase)
- [firebase-admin npm](https://www.npmjs.com/package/firebase-admin)

npm packages:

- `firebase`
- `firebase-admin`

API keys:

- `NEXT_PUBLIC_FIREBASE_API_KEY`: Firebase Console → Project settings → Your apps → Web app → apiKey
- `NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN`: Same page → authDomain
- `NEXT_PUBLIC_FIREBASE_PROJECT_ID`: Same page → projectId
- `NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET`: Same page → storageBucket
- `NEXT_PUBLIC_FIREBASE_APP_ID`: Same page → appId
- `FIREBASE_SERVICE_ACCOUNT_JSON`: Project settings → Service accounts → Generate new private key. Store the JSON as one env string (server only).

Setup:

```
1. https://console.firebase.google.com/ → Create project
2. Build → Firestore Database → Create (test mode only for local, then lock rules)
3. Project settings (gear) → General → Your apps → Add web app → copy the firebaseConfig object
4. Project settings → Service accounts → Generate new private key → FIREBASE_SERVICE_ACCOUNT_JSON
5. Never put the service account in NEXT_PUBLIC_*
```


All platforms: https://www.ihatereading.lol/build/platforms.md
