# supabase

This rule guides Supabase Auth setup in Astro apps with SSR. It covers middleware, auth endpoints, protected routes, and server-side cookies.

- rule · `type=rule` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline · ★ 267 repo stars
- Author: przeprogramowani
- License: AGPL-3.0 · policy=link-only · description only; the file stays with the author
- Source: https://github.com/przeprogramowani/ai-rules-builder/tree/HEAD/.cursor/rules/supabase.mdc
- Updated: 2026-02-20
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/rules/przeprogramowani-supabase

## What it does

The rule tells Claude Code how to add Supabase authentication to an Astro application that uses server-side rendering. It covers a server client in `src/db/supabase.client.ts`, middleware in `src/middleware/index.ts`, and API endpoints for sign-in, sign-up, and sign-out.

Session checks use the Supabase JWT flow and `supabase.auth.getUser()`. The authenticated user is placed in `Astro.locals`, while selected public paths can bypass the guard and other routes can redirect to `/auth/login`. Cookie handling is limited to `getAll` and `setAll`, with server-focused cookie options.

Install `@supabase/ssr` and `@supabase/supabase-js` first, then add `SUPABASE_URL` and `SUPABASE_PUBLIC_KEY` to `.env`. Without those packages and environment values, the described integration cannot be assembled.

## Requirements
- Works with: Supabase

## Install

### Cursor (native platform)

**Manually: put the files in place**
- File: `.cursor/rules/supabase.mdc` — Frontmatter: description, globs, alwaysApply

### Claude Code

**Manually: put the files in place**
- File: `.claude/rules/supabase.md` — The paths frontmatter field limits the files: move globs from the source into paths

### Codex

**AGENTS.md**
- Codex reads AGENTS.md: paste the rule text there

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/instructions/supabase.instructions.md` — The applyTo field sets which files it applies to: move globs from the source into applyTo

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/rules/supabase.md`

### Cline

**Manually: put the files in place**
- File: `.clinerules/supabase.md`

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/przeprogramowani/ai-rules-builder/tree/HEAD/.cursor/rules/supabase.mdc

## When to use it
- add Supabase sign-up and sign-in to Astro
- keep SSR auth sessions in middleware
- guard private Astro routes
- create login, registration, and logout endpoints
- expose the signed-in user through `Astro.locals`

## Example prompts
- Add Supabase Auth to this Astro app with SSR support.
- Create middleware that leaves `/auth/login` and `/auth/register` public and protects the other routes.
- Implement the server client with `getAll` and `setAll`, then expose the user through `Astro.locals`.

## Similar
- [nextjs-supabase-auth](https://affpapa.org/en/nevibecode/skills/sickn33-nextjs-supabase-auth.md) — skill · 6600 installs
- [nextjs-typescript-tailwindcss-supabase](https://affpapa.org/en/nevibecode/skills/nextjs-typescript-tailwindcss-supabase.md) — skill · 1400 installs
- [supabase-server](https://affpapa.org/en/nevibecode/skills/supabase-server.md) — skill · 11200 installs
- [supabase-audit-auth-config](https://affpapa.org/en/nevibecode/skills/supabase-audit-auth-config.md) — skill · 599 installs
- [supabase-audit-auth-users](https://affpapa.org/en/nevibecode/skills/supabase-audit-auth-users.md) — skill · 526 installs
- [supabase-skills](https://affpapa.org/en/nevibecode/plugins/supabase-skills.md) — plugin · ★ 1216 repo stars

## Other versions with the same name
- [supabase · sanjeed5](https://affpapa.org/en/nevibecode/rules/supabase.md) — ★ 3589 repo stars
- [supabase · rerun-build](https://affpapa.org/en/nevibecode/rules/rerun-build-supabase.md) — ★ 1120 repo stars

From the same set: [przeprogramowani/ai-rules-builder](https://affpapa.org/en/nevibecode/by/przeprogramowani/ai-rules-builder.md) — 24 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
