# Clerk + Supabase RLS for Next.js

> Set up Clerk as a native Supabase third-party auth provider in Next.js App Router, write correct RLS policies for users and Organizations, and audit what you already have.

Clerk + Supabase RLS for Next.js is a paid AI agent skill on Agensi by prince raj, in Frontend & Web Apps. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $5 (one-time purchase)
- Creator: [prince raj](https://www.agensi.io/creators/prince-raj)
- Category: [Frontend & Web Apps](https://www.agensi.io/skills/frontend-web-apps)
- Version: 1.0.0
- Last updated: 2026-12-04
- Security: scan passed (2026-12-04); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/clerk-supabase-rls-for-next-js
- Tags: nextjs, clerk, supabase, rls, auth, typescript

## What it does

- Connects Clerk user sessions to Supabase databases securely
- Writes data policies that separate users or organizations
- Fixes common ID format errors between Clerk and Supabase
- Audits your code for leaked secret keys and missing security rules
- Creates database migration files you can copy and paste into your project

## Who it's for

- **Founders building with Next.js and Supabase:** Make sure your users can only see their own data and stop security leaks before you launch. Try: "Set up RLS for my new SaaS project using Clerk and Supabase."
- **Web developers fixing database errors:** Fix those annoying uuid cast errors and RLS blocks that stop your app from working. Try: "Why is my Supabase query returning zero rows even when I am signed in with Clerk?"
- **Teams worried about data security:** Audit your existing code to find missing security policies or leaked secret keys. Try: "Audit my Next.js project to make sure my RLS policies are safe."

## About this skill

If you use Clerk for sign-ins and Supabase for your database, you need a way to make sure User A cannot read User B's private notes. This skill sets up that "Row Level Security" so your database knows exactly who is asking for data. It fixes the common problem where Supabase expects a certain ID format but Clerk provides a different one.

### How it works
1. **Scan your project:** Your AI agent looks at your code to see how you currently handle users and data.
2. **Setup guide:** You get the exact steps to connect Clerk and Supabase in their respective dashboards.
3. **Connect the code:** This skill writes the code that passes the user's secret token from your app to your database.
4. **Write the rules:** You get database files that lock down your tables based on the user or their organization.
5. **Verify security:** Your AI agent runs a check to prove that one user cannot see another's data.

### Frameworks & tools
This skill works with Next.js App Router, TypeScript, and the Supabase CLI. It uses a Python script to scan your local files for security holes.

### Why this beats prompting it yourself
Standard AI prompts often suggest an old way of connecting these tools that is now less secure. This skill uses the modern way that doesn't require sharing secret keys between services. It also knows that Clerk IDs are text strings, not numbers, which prevents the most common crash developers face when combining these two tools.

### Use cases
- Locking a "to-do list" table so users only see their own tasks
- Setting up a team dashboard where everyone in an "Organization" shares data
- Finding and fixing "invalid input syntax" errors in your database logs
- Checking your code for leaked "service role" keys that bypass security

### Known limitations
This skill focuses on the newer App Router and native third-party auth. It does not support the older, deprecated JWT template method for new setups.

## Requires

- Python 3.8+
- Next.js App Router project
- Clerk account
- Supabase project
- Optional: Clerk webhooks (for user sync)

Enable Clerk as a third-party auth provider in your Supabase dashboard before running the setup steps. The skill cannot do this part for you.

## Technical details

Built for Next.js App Router using @clerk/nextjs and @supabase/supabase-js. Uses the native third-party auth flow (JWKS) rather than deprecated JWT templates. Handles auth.jwt() claims for sub and org_id, specifically addressing the text-vs-uuid casting issue. Includes a Python audit script for static analysis of SQL migrations and Next.js code (flags auth.uid() misuse, missing RLS, exposed service-role keys, deprecated JWT templates).

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Clerk + Supabase RLS for Next.js skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### How does this help protect my users' private data?

This skill helps you connect your login system to your database so users can only see their own information. It writes the security rules needed to stop people from accessing data that belongs to other users or organizations.

### What do I need to have ready before using this skill?

You should have a project using Next.js with the App Router, a Clerk account for sign-ins, and a Supabase account for your data. Your agent will also need access to your code files and the Supabase command line tool to check for security holes.

### Which common developer errors does this skill fix?

It fixes a frequent crash where the database expects a specific number format for user IDs while the login system sends a text string. It also ensures you are using a modern connection method that keeps your secret security keys private.

### What kind of files and reports will my agent generate?

You will receive specific dashboard instructions, code snippets for your app, and database files that lock down your tables. It also provides a report from a security scan to prove that your data is properly protected.

### Are there any versions of these tools that this skill cannot handle?

This skill is built for the newer Next.js App Router and native login connections. It does not support older setups that use the deprecated JWT template method for new projects.

### How should I ask my agent to start working on my database security?

You can ask your agent to audit your current security setup for leaks, fix specific database errors, or write new rules that limit data access to specific teams or organizations.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
