Firebase is used in TriviaPP exclusively to power the online daily leaderboard. When a player completes a game session, their name and score are written to a Firestore collection namedDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/dreancaste/TriviaPP/llms.txt
Use this file to discover all available pages before exploring further.
ranking. The app then queries that collection to display today’s top scores. No other Firebase product — including Firebase Authentication — is used; authentication is handled entirely by AWS Amplify and Amazon Cognito.
What Firebase Provides
TriviaPP’sRankingService relies on two Firestore operations:
addScore(name, score)— writes a new document to therankingcollection, stamped with today’s ISO date.getDailyRanking()— retrieves all documents inrankingordered byscoredescending, then filters client-side to only return entries whosedatematches today.
initializeApp / getApp from firebase/app and getFirestore from firebase/firestore.
Step-by-Step Setup
Create a Firebase project
Go to https://console.firebase.google.com and click Add project. Give your project a name (e.g.
triviapp), disable Google Analytics if you don’t need it, and click Create project.Enable Firestore Database in Native mode
In the Firebase console, open your project and navigate to Build → Firestore Database. Click Create database, choose Start in production mode (you will update the rules in the next step), select your preferred Cloud Firestore location, and click Enable.
Set Firestore security rules
Once Firestore is provisioned, go to the Rules tab and replace the default rules with the following:Click Publish to save the rules.
Register a web app and copy the config
In the Firebase console, click the gear icon → Project settings and scroll to the Your apps section. Click the Web icon (
</>), give the app a nickname (e.g. TriviaPP Web), and click Register app. Firebase will display a config object — copy it, you will need it in the next step.Firestore Collection Schema
All leaderboard entries are stored in a single top-level collection calledranking. Each document contains three fields:
| Field | Type | Description |
|---|---|---|
name | string | The display name the player entered at game end |
score | number | The player’s final score for that session |
date | string | The date the score was recorded (YYYY-MM-DD) |
addDoc. The getDailyRanking() method filters in memory on the date field after fetching all scores ordered by score descending, so no composite index is required.
How RankingService Initialises Firebase
RankingService guards against duplicate app initialisation with a short-circuit pattern that checks getApps() before calling initializeApp:
getFirestore then returns a Firestore instance scoped to that app, which is used for every addDoc and getDocs call.