# Firebase Backend (Database + Accounts)

> A hosted database and user accounts for an app with no server of its own.

- **Applies to:** AppMint and Appwright
- **Source:** the Integration Guide shipped inside the app; this page is generated from it.
- **HTML:** https://freewebtoapk.com/docs/firebase-backend
- **Using AppMint:** wherever the text below says "Appwright", read "AppMint". The two builders share this feature and only the name changes. Steps where the instructions genuinely differ are given separately and labelled.

Give AI-generated apps a cloud database and user login using your own free Firebase project

### 1. What this gives your app

Normally your generated app stores data only on the phone it's running on. Turning on Firebase gives the app a free cloud database, so the same data is visible from any device and (if you want) people can sign up with email + password.

It's BRING-YOUR-OWN - the app talks to YOUR free Firebase project. Appwright hosts nothing and charges you nothing extra. You paste one config once; the AI writes all the code.

You do NOT have to write or design anything - no tables, no schema, no SQL. Firebase + Appwright figure it out from your app description.

### 2. Create the Firebase project (5 min, free)

On a computer is easiest:

1. Open console.firebase.google.com and sign in with any Google account.
2. Tap 'Add project' → give it any name → keep clicking 'Continue' → skip Google Analytics → 'Create project'. Wait ~30 sec.
3. In the left menu: Databases & Storage → Firestore → 'Create database'.

- Pick a location near your users (you can't change this later).
- Choose 'Start in production mode' - NOT 'test mode'. Test mode auto-expires after 30 days and your app will silently stop working.

1. In the left menu: Security → Authentication → 'Get started' → tab 'Sign-in method':

- Enable 'Email/Password' (turn ON the first toggle, save).
- ALSO enable 'Anonymous' (scroll down, turn ON, save) - needed for guest/leaderboard apps.

That's it. There's no schema to design.

[Open Firebase Console](https://console.firebase.google.com)

### 3. Copy your web config

Still in Firebase Console:

1. Tap the ⚙️ gear (top left) → 'Project settings'.
2. Scroll to 'Your apps' → tap the </> (web) icon.
3. Give the app any nickname → tap 'Register app' (skip 'Firebase Hosting').
4. You'll see a code snippet. Copy ONLY the firebaseConfig object - everything from the opening { to the closing }.

The web API key is meant to be public - your data is protected by the security rules in step 6, not by hiding the key.

```
const firebaseConfig = {
  apiKey: "AIza...",
  authDomain: "my-app.firebaseapp.com",
  projectId: "my-app",
  storageBucket: "my-app.appspot.com",
  messagingSenderId: "123456789",
  appId: "1:123:web:abc"
};   ← copy the { ... } part
```

### 4. Paste it into Appwright (once)

Open AI Studio → Settings → scroll to 'BACKEND - FIREBASE (OPTIONAL)':

1. Paste the firebaseConfig you copied into the big text box.
2. Turn ON the 'Enable Firebase backend' switch.
3. Tap 'Save Firebase config'. You should see 'Saved Firebase project: <your-project-id>'.

It's stored encrypted on your device and reused for every app you generate - you only do this once.

### 5. Describe your app - the AI does the rest

Just say what you want, in plain English. The AI decides whether to add login screens or not, based on what you ask for:

- 'A notes app where each user saves their own notes' → AI builds signup/login + private notes.
- 'A global leaderboard for a tap game, no accounts' → AI uses silent guest sign-in, public scores, no login UI.
- 'A shared bulletin board everyone can post to' → AI uses guest sign-in, no login UI.

If the device is offline or the config is missing, the app automatically falls back to phone-only storage so it never crashes.

### 6. Apply the security rules (REQUIRED)

Without this step, the app will get 'permission denied' errors when it tries to read or write. The AI writes the rules FOR YOU; you just paste them in.

1. After generating your app, open the Code view (or unzip the downloaded project) and find the file named 'firestore.rules'. Tap it and copy ALL the text.
2. In Firebase Console: Databases & Storage → Firestore → 'Rules' tab → tap 'Edit rules' → delete what's there → paste the AI's rules → tap 'Publish'.

Do this once per app. The rules are tailored to your app - they let users write only their own data, while leaderboards stay publicly readable.

### 7. Verify it works

Quick sanity check after installing the APK:

1. Open the app on your phone and do one action that should save data (create a note, submit a score, etc.).
2. Back in Firebase Console: Databases & Storage → Firestore → 'Data' tab → you should see a new collection (e.g. 'notes' or 'scores') with the data you just entered.
3. Security → Authentication → 'Users' tab → if your app uses login, your account should appear here.

If nothing shows up: check the 3 most common causes in the next step.

### 8. If something doesn't work

The most common errors:

- 'permission-denied' or no data saving → you forgot step 6 (Publish the rules).
- 'auth/operation-not-allowed' on signup/login → you didn't enable Email/Password in step 2.
- 'auth/operation-not-allowed' for guest/leaderboard apps → you didn't enable Anonymous in step 2.
- 'auth/operation-not-allowed' for Google sign-in → you didn't enable Google AND paste your SHA-256 fingerprint (see step 'Add Google Sign-In' below).
- Pasted config rejected ('Couldn't find a { ... } config object') → paste the WHOLE { ... } block including the curly braces, not just the inside.

Supported sign-in methods in generated apps: Email/Password, Anonymous (guest), Google Sign-In (via native Credential Manager), and Phone/SMS (via reCAPTCHA). Facebook/Apple/Twitter sign-in is still NOT supported - they require OAuth popups that Google blocks inside Android WebView.

### 9. Add Google Sign-In (optional)

Generated apps can use Google Sign-In via Android's native Credential Manager - it works inside the WebView (unlike OAuth popups). One-time setup per app:

1. Firebase Console → Security → Authentication → 'Sign-in method' tab → enable 'Google'. Save.
2. Firebase Console → ⚙ Project settings → 'Your apps' → if you don't already have an Android app registered, tap 'Add app' → Android → enter your package name (the one you'll use in Appwright).
3. Build your APK once in Appwright. Open the downloaded '<appname>_signkey_info.txt' file - at the top you'll see SHA-1 and SHA-256 fingerprints.
4. Back in Firebase Console → ⚙ Project settings → Your apps → Android app → 'Add fingerprint' → paste the SHA-256. Tap 'Save'. (You only do this ONCE per app - the same signing key is used for every future build.)
5. Firebase Console → ⚙ Project settings → General → scroll to 'Your apps' → find the Web SDK section → copy the 'Web client ID' (ends in .apps.googleusercontent.com).
6. Open Appwright Settings → paste it into 'GOOGLE SIGN-IN - OAUTH WEB CLIENT ID'. Save.
7. Rebuild your app. Google Sign-In now works.

### 10. Add Phone / SMS Sign-In (optional)

Phone Auth uses Firebase Web SDK + reCAPTCHA (works inside WebView). The user types their phone number, taps an 'I'm not a robot' check, receives an SMS code, and enters it.

Setup:

1. Firebase Console → Security → Authentication → 'Sign-in method' tab → enable 'Phone'. Save.
2. No SHA needed (we use reCAPTCHA verification, not Play Integrity).
3. Just ask the AI for phone sign-in in your app description (e.g. 'Users sign in with their phone number').

⚠️ Billing: Sending real verification SMS now requires the Blaze (pay-as-you-go) plan - the free Spark plan no longer includes a free SMS quota. Upgrade in Firebase Console → ⚙ Project settings → Usage and billing. On Blaze, Firebase Authentication allows up to 3,000 verification SMS per day; SMS pricing varies by country.

💡 To test WITHOUT billing or real SMS: Authentication → Settings → 'Phone numbers for testing' lets you add a fixed test number + code (no SMS is sent).

[Firebase Auth quotas & pricing](https://firebase.google.com/docs/auth/limits)

### 11. Cost - what to expect

Firebase's free 'Spark' plan covers most hobby apps. Free per day:

- 50,000 document reads
- 20,000 writes
- 20,000 deletes
- 1 GiB total storage
- 10 GiB / month outbound network

For reference: a small notes app with 100 active users does ~5,000 reads/day. A viral game leaderboard could blow past 50k reads in an hour.

⚠️ Set a budget alert: Google Cloud Console → Billing → Budgets & alerts → set 'Alert me at $1'. You stay safe and Firebase will email you the moment usage costs money.

[Set a budget alert](https://console.cloud.google.com/billing/budgets)

