> ## Documentation Index
> Fetch the complete documentation index at: https://docs.swiftaiboilerplate.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Supabase Setup

> Complete guide to setting up Supabase for authentication, database, and AI proxy.

<Info>
  **Find complete step-by-step guide in your project:** [Supabase.md](https://github.com/SwiftAIBoilerplatePro/SwiftAIBoilerplatePro-Distribution/blob/main/docs/integrations/Supabase.md)
</Info>

## What You'll Set Up

<CardGroup cols={2}>
  <Card title="Authentication" icon="shield">
    Email/password and Apple Sign In authentication
  </Card>

  <Card title="AI Proxy" icon="brain">
    Secure Edge Function for OpenRouter API calls
  </Card>
</CardGroup>

## Prerequisites

* [Supabase account](https://supabase.com) (free tier available)
* [OpenRouter account](https://openrouter.ai) (pay-as-you-go)
* Supabase CLI installed:
  ```bash theme={null}
  brew install supabase/tap/supabase
  # or: npm install -g supabase
  ```

## Step-by-Step Setup

<Steps>
  <Step title="Step 1: Open Project Settings">
    Go to Supabase dashboard and navigate to **Project Settings**.

    This is where you'll find all the credentials needed to connect your Swift app.
  </Step>

  <Step title="Step 2: Find Your API Keys">
    Find the **API Keys** tab on the left menu, then copy your **anon-public key**.

    <Note>
      This is a public key that's safe to include in your iOS app bundle.
    </Note>
  </Step>

  <Step title="Step 3: Copy Your Project ID">
    Write down your project ID. The easiest way is usually copying it from the address bar of your browser.

    ```text theme={null}
    https://supabase.com/dashboard/project/YOUR_PROJECT_ID
    ```
  </Step>

  <Step title="Step 4: Add to Secrets.xcconfig">
    Open `Config/Secrets.xcconfig` in Xcode and add your credentials:

    ```text theme={null}
    SUPABASE_URL = https://YOUR_PROJECT_ID.supabase.co
    SUPABASE_ANON_KEY = your-anon-public-key
    ```

    <Warning>
      The Secrets.xcconfig file must be under the **Config** folder in your project root.
    </Warning>
  </Step>

  <Step title="Step 5: Login to Supabase CLI">
    Open Terminal, navigate to your repo, and login to Supabase:

    ```bash theme={null}
    cd ~/path-to-your-repo
    supabase login
    ```

    Follow the instructions (press Enter to open browser and login).
  </Step>

  <Step title="Step 6: Link Your Project">
    Link your project to your repo:

    ```bash theme={null}
    supabase link --project-ref YOUR_PROJECT_ID
    ```
  </Step>

  <Step title="Step 7: Create Generated Directory">
    Create the generated directory for your configuration file:

    ```bash theme={null}
    mkdir -p "SwiftAIBoilerplatePro/Generated"
    ```

    <Note>
      If you renamed the app target folder, replace `SwiftAIBoilerplatePro` with your actual app folder name.
    </Note>
  </Step>

  <Step title="Step 8: Run Update Config Script">
    Run the update config script to generate your Swift configuration file:

    ```bash theme={null}
    bash scripts/update-config.sh
    ```

    This generates a new Swift file including your public keys. It is safe to have this in the bundle.
  </Step>

  <Step title="Step 9: Disable Email Confirmation (Development)">
    For ease of development, temporarily disable the **Confirm email** option from Supabase:

    1. Go to **Authentication** → **Providers** → **Email**
    2. Disable **Confirm email**

    <Warning>
      Remember to re-enable this before production launch if you want email verification.
    </Warning>
  </Step>
</Steps>

## What You Get

After setup:

* ✅ Real email/password authentication
* ✅ Sign in with Apple working
* ✅ Secure session management with auto-refresh
* ✅ Production-ready backend

## Continue Setup

After completing Supabase setup, continue with:

<CardGroup cols={2}>
  <Card title="OpenRouter Setup" icon="brain" href="/pages/guides/deployment#openrouter-setup">
    Deploy AI Edge Function
  </Card>

  <Card title="RevenueCat Setup" icon="dollar" href="/pages/guides/revenuecat-setup">
    Configure subscriptions
  </Card>
</CardGroup>

## Related Guides

<CardGroup cols={2}>
  <Card title="Chat Sync" icon="cloud" href="/pages/guides/chat-sync">
    Optional: Sync conversations across devices
  </Card>

  <Card title="Profile Photos" icon="image" href="/pages/guides/profile-photos">
    Optional: Cloud photo storage
  </Card>

  <Card title="Building Your App" icon="hammer" href="/pages/guides/building-your-app">
    Complete customization guide
  </Card>

  <Card title="Authentication Module" icon="lock" href="/pages/modules/auth">
    Technical documentation
  </Card>
</CardGroup>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Authentication not working">
    * Verify SUPABASE\_URL and SUPABASE\_ANON\_KEY are correct
    * Run `bash scripts/update-config.sh` again
    * Clean and rebuild in Xcode (⌘⇧K then ⌘B)
  </Accordion>

  <Accordion title="Configuration.swift not generated">
    * Make sure you created the Generated directory
    * Check the path matches your project structure
    * Run the update-config script from the project root
  </Accordion>

  <Accordion title="CLI login fails">
    * Make sure you have Supabase CLI installed
    * Try `supabase logout` then `supabase login` again
    * Check your internet connection
  </Accordion>
</AccordionGroup>

## Need Help?

* 📖 Check the troubleshooting section above
* 💬 [Create an issue](https://github.com/SwiftAIBoilerplatePro/SwiftAIBoilerplatePro-Distribution/issues)
* 🔍 Search [Supabase docs](https://supabase.com/docs)
