# 🗄️ Set Up Supabase — The Super Easy Guide

**A step-by-step visual guide for non-technical people. Just follow the pictures.**

> ⏱️ **Time needed:** ~5 minutes
> 💰 **Cost:** $0 (free tier — never charged)
> 🧠 **Skill level:** Anyone who can use a web browser

---

## 🎯 What is Supabase and why do I need it?

In plain English: **Supabase is where your app's user accounts and saved projects will live.**

Think of it like a Google Drive for your app's data:
- When someone signs up → their account is stored here
- When someone creates a project → it's saved here
- When they sign in from another device → their projects are still there

**You only need to set this up ONCE.** After that, it works automatically forever.

---

## 🛣️ The 7 Steps (At a Glance)

```
Step 1: Go to supabase.com               [30 seconds]
Step 2: Create a free account             [1 minute]
Step 3: Create a new project              [1 minute]
Step 4: Wait for the project to set up    [2 minutes]
Step 5: Copy 3 secret codes               [1 minute]
Step 6: Set up the database tables        [1 minute]
Step 7: Turn on email sign-in             [30 seconds]
```

**Total: 5 minutes. ☕ Grab a coffee and let's go!**

---

# Step 1: Go to Supabase 🖥️

## What to do:
1. Open your web browser (Chrome, Safari, Edge, or Firefox)
2. In the address bar at the top, type: **supabase.com**
3. Press **Enter** on your keyboard

## What you'll see:
A page with a big logo that says "Supabase" and probably a green button.

## What to click:
**Click the green "Start your project" button** (or "Sign up" — different wording is fine).

> 💡 **Can't find the button?** Look for any green button. They all lead to the same sign-up page.

> ⚠️ **Page looks weird?** Make sure you typed the address correctly: `supabase.com` (no `www.` needed).

### ✅ Checkpoint
You should now be on a page that says "Sign in" or "Sign up" or shows a form with email and password fields.

---

# Step 2: Create a Free Account 👤

## What to do:
Pick ONE of these sign-up methods:

### Option A: With Google (Easiest)
1. Click the **"Continue with Google"** button
2. Choose your Google account
3. Done! Skip to Step 3.

### Option B: With GitHub
1. Click the **"Continue with GitHub"** button
2. Sign in to your GitHub account
3. Click "Authorize" if asked
4. Done! Skip to Step 3.

### Option C: With Email (Always works)
1. Type your email address in the box that says "Email"
2. Type a password (at least 12 characters — make it strong!)
   - **Tip:** A good password = a sentence you can remember, like `MyDogLovesBeach2024!`
3. Click the green "Sign Up" button
4. **Check your email inbox** — Supabase sent you a confirmation email
5. Open that email
6. **Click the confirmation link** in the email
7. You'll be brought back to Supabase, signed in

> 💡 **Can't find the email?** Check your spam/junk folder. Sometimes Supabase emails end up there.

> 💡 **Email is taking forever?** Wait 2-3 minutes. If still nothing, click "Resend confirmation email" on the Supabase login page.

### ✅ Checkpoint
You should now be on the **Supabase dashboard** — a page that says "Welcome to Supabase" or shows your organization name at the top.

---

# Step 3: Create a New Project 🏗️

## What to do:
1. Look for a **big green button that says "New Project"**
   - It might be in the middle of the screen
   - Or in the top right corner
   - Or you might need to click on your organization name first
2. **Click "New Project"**

## What you'll see:
A form with several fields. Fill them in one by one:

### Field 1: Name
- **Type:** `easypeasy-feaso`
- This is just a name for you to remember. You can call it anything.
- Examples: `my-feaso-app`, `property-app`, `feaso-prod`

### Field 2: Database Password
- **Click the "Generate a password" button** (it's a small button next to the password box)
- Supabase will create a super-strong random password automatically
- **🚨 CRITICAL: Save this password somewhere safe! 🚨**
  - Copy it into a text file
  - Or a password manager (like 1Password, Bitwarden, LastPass)
  - Or take a photo of it
  - Or write it on a piece of paper

> ⚠️ **Why save it?** You'll never see this password again. If you lose it, you can reset it later, but it's annoying. Just save it now and save yourself the trouble.

### Field 3: Region
- **Click the dropdown box** (it might say "Select a region")
- **Pick this one (for Australia):** 🇦🇺 `Sydney (ap-southeast-2)`
  - If you're not in Australia, pick the region closest to your users:
    - 🇺🇸 USA → `North Virginia` or `Oregon`
    - 🇬🇧 UK → `London`
    - 🇪🇺 Europe → `Frankfurt`
    - 🇸🇬 Asia → `Singapore`

### Field 4: Pricing Plan
- It should say **"Free"** — leave it as is
- ❗ **Do NOT pick Pro** — you don't need it yet

## What to click:
**Click the green "Create new project" button at the bottom of the form.**

### ✅ Checkpoint
You'll see a progress bar or message saying "Setting up project..." or "Provisioning database..."

> ⏰ **Wait 1-2 minutes.** Don't close the tab! Your project is being created. This is normal.

When it's done, you'll be taken to your **project dashboard** — a page with lots of menus on the left side.

---

# Step 4: Wait for Setup (Boring But Important) ⏰

## What's happening:
Supabase is creating a private database in the cloud for you. This takes about 1-2 minutes.

## What to do:
- **Just wait.** Don't refresh the page.
- Don't click anything.
- Maybe stand up and stretch. 🧘

## What you'll see when it's done:
The page will refresh automatically, and you'll see menus on the left side like:
- Table Editor
- SQL Editor
- Authentication
- Storage
- Edge Functions
- (and more)

### ✅ Checkpoint
You can see a left sidebar with at least these items: **Table Editor**, **SQL Editor**, **Authentication**.

---

# Step 5: Copy 3 Secret Codes 🔑 (The Important Bit!)

This is the **most important step** of the whole guide. You're going to copy 3 long codes and save them in a text file. You'll need these later.

## Setup: Open a text file to save your codes
1. Open **Notepad** (Windows) or **TextEdit** (Mac) or any text editor
2. Create a new file called `supabase-codes.txt`
3. Save it somewhere easy to find (like your Desktop)

You'll paste the 3 codes into this file as you go.

## Get the codes:

### 🔑 Code #1: Your Project URL

1. Look at the **left sidebar** (the column of icons/menus on the left)
2. At the **bottom of the sidebar**, find a **gear icon** (⚙️) — it says **"Project Settings"**
3. **Click the gear icon**
4. On the Settings page, look at the **left side menu** — find and click **"API"**
5. You'll see a page with several sections

6. Find the section called **"Project URL"**

7. You'll see a URL that looks like:
   ```
   https://abcdefghijk.supabase.co
   ```
   (It will be different for you — that's normal)

8. **Click the small copy icon** next to the URL (it looks like two squares overlapping 📋)

9. **Paste it into your text file** and label it:
   ```
   NEXT_PUBLIC_SUPABASE_URL = https://abcdefghijk.supabase.co
   ```

### 🔑 Code #2: Your Anon (Public) Key

1. On the same page (Settings → API), scroll down a bit
2. Find the section called **"Project API keys"**
3. Look for the row that says **"anon" "public"** — it's the FIRST key in the list
4. It's a very long string that starts with `eyJ...`
5. **Click the copy icon** next to it
6. **Paste it into your text file** and label it:
   ```
   NEXT_PUBLIC_SUPABASE_ANON_KEY = eyJhbGciOiJIUzI1NiIsInR5cCI6...
   ```

### 🔑 Code #3: Your Service Role (Secret) Key

1. On the same page, still in "Project API keys"
2. Look for the row that says **"service_role"** — it's the SECOND key
3. ⚠️ **This one is secret — don't share it with anyone!**
4. **Click "Reveal"** first (you might need to click a button to show the key)
5. **Click the copy icon** to copy it
6. **Paste it into your text file** and label it:
   ```
   SUPABASE_SERVICE_ROLE_KEY = eyJhbGciOiJIUzI1NiIsInR5cCI6...
   ```

> 💡 **The 3 codes look very similar (they all start with `eyJ`).** Make sure you copied the RIGHT one for each slot. The first one is the URL, the second is `anon` public, the third is `service_role` secret.

> 💡 **Can't see the copy icon?** Try right-clicking the code text and choosing "Copy" from the menu.

### ✅ Checkpoint
Your text file should have 3 lines that look like this:
```
NEXT_PUBLIC_SUPABASE_URL = https://abcdefghijk.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
SUPABASE_SERVICE_ROLE_KEY = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
```

**Keep this file open — you'll need it for Vercel!**

---

# Step 6: Set Up the Database Tables 📊

The database is empty right now. We need to create the tables that store user accounts, projects, and AI usage. Don't worry — you just have to copy-paste.

## What to do:

1. In the **left sidebar**, find and click **"SQL Editor"** (it has a small database icon)

2. You'll see a page with some buttons. **Click the green "New query" button** (top right)

3. A big text box will appear. This is where we paste the SQL code.

4. **Open the file `supabase/schema.sql` from your computer**
   - It came with the Easypeasy Feaso project
   - It's a long text file
   - Open it with Notepad (Windows) or TextEdit (Mac)
   - **Select ALL the text:** press `Ctrl+A` (Windows) or `Cmd+A` (Mac)
   - **Copy the text:** press `Ctrl+C` (Windows) or `Cmd+C` (Mac)

5. **Go back to Supabase**, click in the big text box

6. **Paste the SQL code:** press `Ctrl+V` (Windows) or `Cmd+V` (Mac)

7. Now **click the green "Run" button** (top right of the editor)

## What you'll see:
- A message saying "Success. No rows returned" or similar
- It should take about 5-10 seconds

> 💡 **Got an error?** Don't panic. Common causes:
> - You accidentally pasted only part of the file. Try again, make sure you copy ALL of it.
> - Your project is still setting up. Wait 30 seconds and try again.

> 💡 **Got a "permission denied" error?** Make sure you selected "New query" (not trying to edit an existing one).

### ✅ Checkpoint
The SQL ran successfully. To verify:

1. In the left sidebar, click **"Table Editor"** (it has a table icon)
2. You should see a list of tables including: `profiles`, `projects`, `ai_usage`, `audit_log`, `billing_events`, `share_views`
3. If you see those tables → ✅ success!

---

# Step 7: Turn On Email Sign-In 🔐

Right now, your database is ready but users can't sign in yet. Let's fix that.

## What to do:

1. In the **left sidebar**, click **"Authentication"** (it has a key icon 🔑)

2. You'll see several tabs at the top. **Click "Providers"**

3. Find the row that says **"Email"** — it should already be enabled (toggled ON, green)

4. If it's OFF (gray), **click the toggle to turn it ON** ✅

5. That's it! Email sign-in is now active.

## Optional: Turn off email confirmation (for testing)

If you want users to be able to sign up without clicking an email link (faster for testing):

1. Still in **Authentication → Providers → Email**
2. Scroll down and find **"Confirm email"**
3. **Toggle it OFF** (gray)
4. Click "Save"

> 💡 **Should I turn off email confirmation?**
> - **For a real production app:** Keep it ON (more secure)
> - **For testing/demo:** Turn it OFF (faster to test)

### ✅ Checkpoint
You can see a list of users (probably empty for now) in the Authentication page. Email provider is ON.

---

# 🎉 You're Done! What's Next?

Your Supabase database is **fully set up and ready to use.**

## What you accomplished:
- ✅ Created a free Supabase account
- ✅ Created a database project
- ✅ Got 3 secret codes (saved in your text file)
- ✅ Created all the database tables
- ✅ Turned on email sign-in

## Your 3 secret codes are:
```
NEXT_PUBLIC_SUPABASE_URL      = https://xxxxx.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY = eyJ...
SUPABASE_SERVICE_ROLE_KEY     = eyJ...
```

## What's next:
**Deploy your app to Vercel** so it's actually live on the internet.

The 3 codes you saved are what you'll paste into Vercel. Open the `DEPLOY.md` guide and go to **Part 2: Deploy to Vercel**.

Or visit the in-app guide: **`/setup`** in your Easypeasy Feaso app.

---

# 🆘 Troubleshooting

### "I forgot to save the database password"
1. Go to Supabase → Project Settings → Database
2. Click "Reset database password"
3. Generate a new one
4. Save it this time! 😉

### "I lost my API keys"
1. Go to Project Settings → API
2. The URL is always visible
3. The anon key is always visible
4. For service_role: click "Reveal" then copy

### "My SQL didn't work"
- Make sure you copied ALL of the schema.sql file (Ctrl+A then Ctrl+C)
- Wait a moment and try clicking "Run" again
- Check the error message at the bottom — it usually tells you what went wrong

### "I don't see the gear icon"
- Look at the very bottom of the left sidebar
- On mobile, you might need to scroll the sidebar

### "Email confirmation is taking forever"
- Check your spam/junk folder
- Wait 5 minutes
- Click "Resend" on the Supabase login page

### "I accidentally closed the tab"
- Open a new tab and go to supabase.com
- Sign in
- Your project is still there — cloud services don't disappear

### "How much does this cost?"
**$0.** Supabase's free tier includes:
- 500 MB database (enough for ~50,000 projects)
- 1 GB file storage
- 2 GB bandwidth per month
- 50,000 monthly active users

You only need to upgrade if you grow past those limits. For 99% of apps, the free tier is plenty for years.

---

## 🆘 Still stuck?

**Common Supabase support channels:**
- 📖 Supabase docs: https://supabase.com/docs
- 💬 Supabase Discord: https://discord.supabase.com
- 🐦 Supabase Twitter: @supabase

**For Easypeasy Feaso specifically:**
- Open an issue on GitHub
- Email: support@easyfeaso.com.au
- Visit `/setup` in the app for a guided walkthrough

---

**Made with ❤️ by Globalcsm Pty Ltd · ABN 14 127 573 219 · Sydney NSW**
