# Parcel Empire — Supabase Setup Guide

Phase 6.2 connects the web-hosted game to online accounts, global parcel ownership, leaderboards, profiles, wallets and cloud saves.

## What Supabase does

Your web host serves the files. Supabase stores the online game data.

- Auth users and sessions
- Player cloud save
- Global parcel ownership
- Server wallet and transactions
- Marketplace listings
- Leaderboard rows
- Player profiles
- Event/reward data
- Payout requests and admin data

## Step 1 — Create the project

1. Create a Supabase account.
2. Create a new project.
3. Choose a strong database password and save it safely.
4. Wait for the project to finish provisioning.

## Step 2 — Copy your public keys

In Supabase, open Project Settings → API and copy:

- Project URL
- anon public key

Paste them into `js/config.js`:

```js
SUPABASE_URL: "https://YOUR-PROJECT.supabase.co",
SUPABASE_ANON_KEY: "YOUR_PUBLIC_ANON_KEY",
```

These are public browser keys. Do not paste service-role keys into the website.

## Step 3 — Run the database schema

1. Open Supabase SQL Editor.
2. Open this project file: `sql/supabase_schema.sql`.
3. Copy the whole file.
4. Paste it into SQL Editor.
5. Run it.

This creates the tables and functions used by the game.

## Step 4 — Optional production hardening

When the schema is working, review:

- `SUPABASE_RLS_GUIDE.md`
- `SUPABASE_PRODUCTION_CHECKLIST.md`
- `SUPABASE_BACKUP_PLAN.md`
- `sql/production_hardening.sql`

Do not enable stricter policies until you have tested login, buying land, leaderboard and wallet functions.

## Step 5 — Enable authentication providers

For the first beta, email/password is enough.

Recommended first setup:

- Enable Email provider
- Disable email confirmations for fast testing, or keep them enabled for a more realistic beta
- Add your hosted domain to allowed redirect URLs

Redirect URLs to add:

```text
https://YOURDOMAIN.com/login.html
https://YOURDOMAIN.com/dashboard.html
https://YOURDOMAIN.com/
```

## Step 6 — Upload config and test

Upload the updated `js/config.js` to your web host.

Then open:

```text
https://YOURDOMAIN.com/supabase-setup.html
```

Use the checklist there to confirm the project is configured.

## Step 7 — First online test

1. Open `login.html`.
2. Create a test account.
3. Open `dashboard.html`.
4. Buy a nearby parcel.
5. Open the game in another browser/account.
6. Confirm the same parcel appears as owned globally.

## Important safety notes

- Never expose Supabase service-role keys in frontend files.
- Keep real payouts disabled until legal/payment/fraud checks are complete.
- Keep server-side wallet functions for real reward/cashout logic.
- Use HTTPS for GPS, PWA install and authentication redirects.
