Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

React
  • Backend vs Frontend: What Runs Where, and Why the Server Is the One You Trust
  • One Request, Two Answers: the Same Post as an HTML Page and as JSON
  • A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
  • How a Web Page Works: HTML Tags, Elements and Attributes
  • Semantic HTML: header, nav, main, aside and footer as Page Landmarks
  • HTML Forms: Labels, Names, Input Types and Where the Data Goes (GET vs POST)
  • CSS Basics: Selectors, Which Rule Wins, and the Box Model
  • CSS Flexbox vs Grid: A Nav Bar, a Card Row and a Dashboard
  • Responsive CSS: Viewport, Mobile-First Media Queries, clamp() and Dark Mode with Tokens
  • JavaScript for People Who Already Code: Syntax, Modules and Five Surprises
  • JavaScript Arrays the Functional Way: map, filter, reduce, find, sort and Object.entries
  • Async JavaScript: Promises, async/await, fetch and Promise.all
  • JavaScript in the Page: the DOM, querySelector and Events
  • npm, package.json and Vite: What npm install Fetches and How Vite Serves and Builds Your Page
  • TypeScript Essentials: Types Checked, Then Erased (Interfaces, Unions, Generics)
  • Why React, JSX and Components: The Page as a Function of Data
  • React Props and Composition: Data Down, Calls Up, Children in the Slot
  • Routing With React Router: One Page, Many Addresses
  • React Component Tests With Vitest and Testing Library: Test What the User Sees
  • End-to-End Tests for a React App With Playwright: A Full Dress Rehearsal
  • Why AI-Built Websites All Look the Same, and Four Levels That Fix It
  • Visual Hierarchy, Spacing and the 8-Point Grid: Tell the Eye What to Read First
  • Colour, Contrast and Dark Palettes: 60-30-10, Semantic Tokens and Ratios You Can Compute
  • Typography That Sells: Type Scale, Line Length and Free Font Pairings
  • The UI Element Catalogue: Buttons to Toasts, Their Jobs, States and shadcn/ui Names
  • Design Tokens: Primitive and Semantic Tokens, from Figma to CSS to Tailwind
  • Tailwind CSS 4 in React: Utility Classes, Responsive Prefixes, Hover and Dark Mode
  • shadcn/ui in React: Components You Own, Edit and Commit
  • Design Tokens to a Tailwind Theme: Light and Dark Mode with @theme inline
  • Motion in React: Entrance, Hover, Exit and Layout Animations
  • A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
  • Accessibility in Practice: Dialogs, Menus and the Keyboard in React
  • Reference-Driven Design: Extract a DESIGN.md From a Site You Admire and Build From It
  • Components, Variants and Variables: One Design System in Figma and in CSS
  • Figma MCP Server: Build a React Component From a Frame, Then Write It Back
  • Claude Design: From a Brief to a Clickable Prototype, Then Hand It Off to Claude Code
  • Critiquing AI-Generated UI: Six Checks for Every Screen
  • The AI Design Landscape: Prompt to UI, Prompt to App, and Design to Code
  • Your Brand Rules Folder: One Folder Every AI-Built Page Follows
  • The Best-Practice UI Prompt: Plain Sentences That Beat the Average AI Page
  • UI Ideas From Figma Make, Google Stitch and ChatGPT: One Prompt, Three Designs
  • Google Stitch From a Sketch or Screenshot: Show the Layout, Say What to Keep
  • Stitch to Figma to Code: Turn a Stitch Screen Into Code That Uses Your Tokens
  • Figma Make: Prompt to Prototype With a Four-Part Prompt
  • Upgrade a Dated UI From One Screenshot (or a Reference Image)
  • States and Feedback: Make Every Click Get an Answer
  • A Design-Loop Skill: Claude Screenshots, Scores and Fixes Its Own UI
  • Copy Without the AI Tells: A Copy Pass on a Landing Page
  • Running a Next.js Admin Starter Kit: Route Groups, Theme Tokens and npm run dev
  • Remotion Basics: A Video as One Composition Object, Frames, Sequences and the Player
  • Spline: Put a 3D Scene on a Landing Page Without Writing 3D Code
  • Framer: A Launch Page Without Code, From a Free Animated Template
  • Three.js: What It Can Do on Real Sites, and How to Let Your AI Agent Use It
  • Animated Component Libraries (Magic UI, Aceternity UI): Copy-In Motion and When It Becomes Noise
  • WebGPU and Three.js Shaders in TSL: A Living Gradient, 4,500 Particles and a Hover Ripple
  • Deploy Many Vite Demos as One Static Site: A Gallery Page, One Build Command and import.meta.env.BASE_URL
  • React State, Events, Lists and Conditional Rendering: Follow One Click
  • React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One
  • Lifting State Up, Refs and React DevTools: Put State Where It Is Needed
  • Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus
  • React Context and Custom Hooks: Share One Value, Reuse the Logic
  • Finishing a Remotion Video Editor: Timeline Sync, Track Order, Trims and Fades, and the Server MP4 Render
  • A 3D Product Page in React and Three.js: Scroll Becomes a Number, One Camera Shot per Panel, One Choice Drives Everything
  • A Personal 3D Portfolio Room in React Three Fiber: Hover Glow, Click to Open, Pointer Drift and a Contact Form to FastAPI
  • Server State With TanStack Query: One Key, One Request, One Cache
  • Mutations and Optimistic Updates in TanStack Query: Change Data, Then Tell the Cache
  • Generate TypeScript Types, Query Hooks and Zod From an OpenAPI Spec With Orval
  • A Mock Backend in the Browser With Mock Service Worker, Generated From the Spec
  • A React Client for a FastAPI API: The CORS Wall, CORSMiddleware and the Vite Proxy
  • Forms With React Hook Form and Zod: The API's Rules in the Browser, the Server's Errors Under the Field
  • JWT Auth in a React Client With a FastAPI Backend: Log In, Carry the Token, Let the Server Decide
  • Supabase as a Backend: Postgres, Instant APIs, Row Level Security and the Two Keys
  • Email Login With Supabase in Next.js: Three Clients, Server Actions, the Callback Route and Middleware
  • Google Sign-In With Supabase in Next.js: Which Address Goes Where
  • hCaptcha on a Supabase Login Page: Site Key in the Browser, Secret in Supabase
  1. Blog
  2. /
  3. React
  4. /
  5. Working with APIs

Supabase as a Backend: Postgres, Instant APIs, Row Level Security and the Two Keys

What Supabase gives a front end out of the box, how the app reads and writes rows with one line of JavaScript, why row level security is the thing that keeps that safe, and which API key belongs in the browser.

Chaand Sheikh

·27 November 2026·Updated 29 November 2026Working with APIs

What you will learn

  • List what a Supabase project gives an app: Postgres, instant APIs, realtime, auth, storage and edge functions
  • Read and insert rows from JavaScript with supabase.from()
  • Turn on row level security and write a policy with auth.uid()
  • Explain why the anon key can go in the browser and the service role key never can

Before you start

  • Basic SQL (SELECT, tables, rows)
  • Running a Next.js app locally

Every app needs a backend: a database, user logins, a place for files, and an API in between. Building all of that by hand takes weeks. Supabase hands it to you ready to use. Think of a kitchen where the plumbing, the oven and the fridge are already fitted. You walk in and start cooking.

This is the backend behind our admin starter kit (see the Next.js starter kit). In this article you'll see what Supabase is, how the app talks to it, what keeps the data safe while it does, and how to set up a project.

What Supabase is

Supabase is open source and built on Postgres, a full SQL database. People call it an alternative to Firebase: a backend as a service, but with a proper relational database underneath. Your web app or mobile app plugs into the same backend either way.

A project gives you six things, and they all share one database and one login system:

PartWhat it does
Postgres databaseEach project gets its own full database, with tables, rows and SQL
Instant APIsSupabase reads your tables and builds an API for them, so you don't write the endpoints
RealtimeWhen a row changes, the app hears about it straight away, without a refresh
AuthenticationEmail and password, social logins like Google, and sessions
StorageFiles such as images and videos
Edge FunctionsYour own small server functions, run by Supabase

How the app talks to it

In JavaScript or TypeScript, you install the Supabase package and create a client. Reading data is then one line. This is the example from the lecture deck:

// 1. Instant API: talk to your DB from the app
import { createClient } from '@supabase/supabase-js'
const supabase = createClient(URL, KEY)

// Read rows, no backend code to write
const { data } = await supabase.from('messages').select('*')
// SELECT * FROM messages

// Insert a row just as easily
await supabase.from('messages').insert({ text: 'Hello!' })

The request goes to the instant API, the API asks Postgres, and the rows come back. Realtime is a channel: say which table you care about, and subscribe.

// 2. Realtime: get live updates automatically
supabase.channel('room-1')
  .on('postgres_changes',
      { event: 'INSERT', schema: 'public', table: 'messages' },
      payload => {
        // fires the instant anyone inserts
        render(payload.new)
      })
  .subscribe()   // now you're live

Now every insert into that table is pushed to every open copy of the app. You don't have to memorise this syntax. An AI assistant can write it, as long as you know what each part does.

But notice one thing. The app talks to the database directly. So what stops one user from reading another user's data? Hold that question. We'll answer it after the tour.

Create an organisation and a project

Go to supabase.com and click Start your project. Sign up if you don't have an account, and the dashboard opens.

  1. Organisation. A group that holds your projects. Give it a name. Type: personal. Plan: free, zero dollars a month, which is enough for the whole starter kit.
  2. Project name. Ours is studyeasy.
  3. Database password. The password of your Postgres database. Use the generate link if you like, and save it somewhere safe. You'll need it if you ever connect to the database directly.
  4. Region. Where the database sits. Pick the one closest to your users, since a database far away makes every request slower. Don't leave it empty: Supabase stops with "a region must be defined".
  5. Security options. Enable Data API builds the instant API, so keep it ticked. Automatically expose new tables makes every new table reachable through that API, and Supabase itself suggests turning it off so you decide which tables are open. Enable automatic RLS switches row level security on for every new table.

Click Create new project. It takes a minute or two, then the overview shows the status as healthy, with the project URL under the name. That URL is the address of your API, and the app will need it.

A quick tour of the dashboard

  • Table editor shows tables like a spreadsheet. SQL editor runs SQL directly.
  • Database lists tables, and further down, Policies, where each table's security rules live. A fresh project says "no tables in schema".
  • Authentication holds your users, and under Sign in / Providers, the login methods. Email and password is at the top. Social logins like Google are below it, all disabled for now. Supabase also offers captcha, rate limits, email verification and multi-factor authentication to keep bots out.
  • Storage, Edge Functions and Realtime for the parts in the table above.
  • Project settings, at the bottom, holds the API keys. The Connect button at the top opens the ways in: a framework library, a connection string, an ORM, an MCP for your agent, and the keys.

Row level security: a bouncer for every row

Back to the question. The answer is row level security, or RLS. Every row has an owner. With RLS on, Postgres checks each row against a rule before it returns it, like a bouncer at the door who checks every guest against the list.

RLS filters rows per user Alice's app select * profiles RLS check auth.uid() = user_id ? owner: Alice passes owner: Bob stays behind owner: Carol stays behind
Same query for everyone. Postgres hands each user only their own rows.

The rule is called a policy, and it's a small piece of SQL. From the lecture deck:

-- 1. Turn the bouncer on for this table
alter table profiles enable row level security;
-- now NOTHING is readable until a
-- policy explicitly allows it

-- 2. Allow reading only your own row
create policy "Read own profile"
  on profiles for select
  using ( auth.uid() = user_id );
-- auth.uid() = the logged-in user

-- 3. Allow updating only your own row
create policy "Update own profile"
  on profiles for update
  using ( auth.uid() = user_id );
-- Bob can't edit Alice's profile

In plain words: you can read or update a row only when its user_id is your own id. And the nice part is that the app code doesn't change. It's still supabase.from('profiles').select('*'). Postgres filters the rows for you.

The golden rule: always enable RLS on every table your app reads. Without it, the public key can read the whole table.

Two keys, two places

Open Project settings → API keys. There are two tabs. The first has the newer publishable and secret keys. The second has the classic pair, anon and service_role. The newer keys do the same jobs: publishable does the anon key's job, secret does the service role key's job.

  • The anon key is public. As the page says, it's safe in a browser, but only when RLS is on and the policies are in place.
  • The service role key bypasses RLS completely. It never goes into front-end code and you never share it. If it ever leaks, generate a new one straight away.
Anon key in the browser, service role key on the server Browser anon key (public) Trusted server service role key RLS checks every row Postgres skips RLS, sees all rows
The anon key goes in the browser. The service role key stays on the server.

Common mistakes

  • A table with RLS off. Anyone with your public key can read all of it.
  • The service role key in front-end code. It skips every policy you wrote.
  • Leaving the region empty. Project creation fails until you pick one.
  • Auto-exposing every new table. Turn that option off and open tables on purpose.

Quick recap

IdeaIn one line
SupabaseOpen source backend on Postgres: database, instant APIs, realtime, auth, storage, edge functions
Reading datasupabase.from('messages').select('*')
RLSPostgres checks every row against a policy before returning it
Policyusing ( auth.uid() = user_id )
anon / publishable keyBrowser, safe only with RLS on
service role / secret keyServer only, bypasses RLS

Next, we connect the starter kit to this project and give it real sign-up and login: email login with Supabase in Next.js.

Keep going in React · 72 of 75

Previous
JWT Auth in a React Client With a FastAPI Backend: Log In, Carry the Token, Let the Server Decide
Next post
Email Login With Supabase in Next.js: Three Clients, Server Actions, the Callback Route and Middleware
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Related posts

Server State With TanStack Query: One Key, One Request, One Cache

Three components need the same list of books. Fetch it by hand and you get three requests; ask TanStack Query for one key and you get one. With real request counts, retries and a quiet refetch on tab focus.

Mutations and Optimistic Updates in TanStack Query: Change Data, Then Tell the Cache

Add a book with useMutation and let invalidateQueries refetch the list, then make delete instant: snapshot, remove the row in 3 ms, roll back on a 404 and refetch the truth in onSettled.

Generate TypeScript Types, Query Hooks and Zod From an OpenAPI Spec With Orval

Let the API's OpenAPI spec write your React client: Orval turns /v3/api-docs into TypeScript types, useGetBooks and a Zod schema, and a renamed field becomes error TS2339 at BookList.tsx line 26.

A Mock Backend in the Browser With Mock Service Worker, Generated From the Spec

Build the React screen before the API exists: Orval writes MSW handlers and faker data from the spec, a service worker answers GET /api/books inside the browser, and npm run dev:real switches back to the real server.

On this page

  • What Supabase is
  • How the app talks to it
  • Create an organisation and a project
  • A quick tour of the dashboard
  • Row level security: a bouncer for every row
  • Two keys, two places
  • Common mistakes
  • Quick recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.