Supabase with Expo

Connect Expo to Supabase: client setup, tables, Row Level Security, auth, realtime and edge functions.

Supabase is hosted PostgreSQL with auth, storage, realtime and edge functions, and it is one of the smoothest backends for AI-assisted mobile development.

Core concepts

  1. Create a project and table: Create a project, define a todos table with a user_id referencing auth.users, and enable Row Level Security before inserting any data. — Supabase Expo quickstart
  2. Row Level Security: Policies decide who can select, insert, update or delete. With RLS on and no policy, nobody can access the table, which is the safe default. — Supabase RLS
  3. Auth in React Native: Use email, magic link or OAuth. Persist the session with AsyncStorage and listen for auth state changes. — Supabase Auth
  4. Edge functions: Run server-side code (call an LLM, use a secret, handle a webhook) without exposing keys in the app. — Supabase Functions
  5. Realtime and storage: Subscribe to table changes for live updates and use storage buckets for images, with policies on buckets too. — Supabase Realtime
  6. Generate types: Generate TypeScript types from your schema so queries are typed and agents catch column mistakes. — Supabase type generation

Concept videos

YouTube channels and searches for these topics. On a large screen they open in the reading panel next to the roadmap.

Explanation

The anon key is public

The anon (public) key is designed to ship in apps; RLS is what protects data. Never use the service-role key in the app.

Use MCP carefully

A Supabase MCP server lets an agent inspect and change your project. Use a development project and read-only access, and review every migration.

What Is It?

Supabase is an open-source backend built on PostgreSQL with auth, storage, realtime and functions.

Why Should I Care?

You get a real SQL database and auth with minimal server code, and agents generate SQL well.

Real World Analogy

Supabase is a furnished office: desks (tables), reception (auth), locked cabinets (RLS) and a back room (edge functions) already installed.

Visual Mental Model

text
Expo app (anon key) -> Supabase Auth -> RLS policy -> Postgres table
Secrets -> Edge Function

Smallest Possible Example

sql
alter table public.todos enable row level security;

create policy "users read own todos"
  on public.todos for select
  using (auth.uid() = user_id);

create policy "users insert own todos"
  on public.todos for insert
  with check (auth.uid() = user_id);

Common Mistakes

❌ Creating tables without enabling RLS.

Data is exposed through the auto-generated API.

❌ Using the service-role key client-side.

It bypasses RLS entirely.

Build This Mini Project

Build an authenticated todo app with RLS policies and a screen that lists, adds and checks off todos.

Prompts for Cursor, Claude Code & Codex

Paste these into Cursor, Claude Code, Codex, or any coding agent. Replace the bracketed parts with your app details, and keep the agent in plan mode first so you review the approach before it edits files.

Todos with RLS

text
Create the todos table with RLS policies (select, insert, update, delete restricted to auth.uid() = user_id), then implement hooks/useTodos.ts with TanStack Query and a screen to list and add todos. Show the SQL separately and do not run it.

Edge function for secrets

text
Create a Supabase edge function that calls [third-party API] with a secret stored in function secrets and returns only the fields the app needs. Add auth verification of the caller.

Rules, databases & blogs to use

Resources

Threads in the same domain as this chapter — go deeper on iHateReading without leaving the roadmap.

Firebase, Supabase and Clerk authentication cover

Firebase, Supabase and Clerk authentication

Auth options for apps compared.

How to build an AI chat app with Vercel AI SDK and Firebase cover

How to build an AI chat app with Vercel AI SDK and Firebase

Chat UI, streaming and backend wiring for an AI feature.

Hosting under $100/month at 10k visitors cover

Hosting under $100/month at 10k visitors

Cut hosting burn for agent-heavy apps with sane infra choices.