> ## Documentation Index
> Fetch the complete documentation index at: https://a5eb32f-docs-2.manicule.dev/llms.txt
> Use this file to discover all available pages before exploring further.
> For every page in one file, fetch https://a5eb32f-docs-2.manicule.dev/llms-full.txt (large).
> To search and read these docs as tools, connect the MCP server at https://a5eb32f-docs-2.manicule.dev/api/mcp.
> Every agent surface: https://a5eb32f-docs-2.manicule.dev/.well-known/llms-manifest.json

# Connect Your App to Supabase (/databases/supabase-postgres)

<!-- agent-signals: reading_time_min: 2 · est_tokens: 787 · updated: 2026-11-25 -->
Related: [Choose a Database for Your Project](/databases/overview.md), [Connect a Worker to Cloudflare D1](/databases/cloudflare-d1.md), [Connect Your App to Neon Postgres](/databases/neon-postgres.md), [Review and Apply Database Migrations](/databases/migrations.md)

> Connect a Supabase project to your app, choose the right credentials, and protect data with row-level security.

Supabase combines managed PostgreSQL with authentication, file storage, and realtime subscriptions. Choose it when your app needs those services alongside a relational schema. The browser client uses the project URL and a public API key, while a server-side Postgres client uses a private connection string.

## Connect a Supabase project

<Steps>
<Step title="Create or select a project in Supabase">Use the project that will hold your application's database and files. Selecting Supabase in Studio records the provider choice, but doesn't create the Supabase project or populate its credentials.</Step>

<Step title="Set the client environment variables">For the Next.js example below, set `NEXT_PUBLIC_SUPABASE_URL` and `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY` to the project's URL and publishable key. If your existing app uses a legacy `anon` key, keep its existing public variable such as `NEXT_PUBLIC_SUPABASE_ANON_KEY` until you switch the client to a publishable key.</Step>

<Step title="Check access to the tables">Enable row-level security (RLS) on exposed tables and write policies for the rows each user should be able to read or change. Test with both a signed-in user and a signed-out client before relying on the query in your app.</Step>
</Steps>

<Warning>Next.js exposes `NEXT_PUBLIC_` values to the browser. Keep Postgres connection strings, secret keys, and legacy `service_role` keys in the server environment.</Warning>

## Query related records

This example uses `@supabase/supabase-js` to read orders with their related items, newest first. It assumes your database defines the relationship and its access policies allow the query to return those rows.

```typescript
import { createClient } from "@supabase/supabase-js";

const url = process.env.NEXT_PUBLIC_SUPABASE_URL;
const key = process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY;
if (!url || !key) throw new Error("Set the public Supabase URL and key");

export const supabase = createClient(url, key);

export async function fetchOrders() {
  const { data, error } = await supabase
    .from("orders")
    .select("*, items(*)")
    .order("created_at", { ascending: false });

  if (error) throw error;
  return data;
}
```

## Check permissions before changing a query

If the orders query returns a permissions error, check whether the table is exposed to the Data API and whether the calling role has read access. If it succeeds but returns no rows, check whether that user's row-level policies allow them to see the test orders. Verify read access on the related items table too.

## Choose the services you need

Use Supabase Auth for Google, GitHub, or email and password sign-in. Use Storage buckets to upload and serve images, user media, and documents. If a view should update when data changes, use Realtime subscriptions. Apply schema changes to Postgres separately from configuring those services.

## Next

* [Review and apply database migrations](/databases/migrations).
* [Compare database engines and tooling](/databases/overview).
