Clerk + Supabase RLS for Next.js

    by prince raj

    0

    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.

    $5

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    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 asking: “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 asking: “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 asking: “Audit my Next.js project to make sure my RLS policies are safe.”

    Clerk + Supabase RLS for Next.js

    Example session with this skill installed

    Set up Supabase RLS for a "posts" table using Clerk auth in my Next.js App Router project. Each user should only see and edit their own posts.

    • Read your context and instructions
    • Compiled the clerk + supabase

    Summary

    Connected Clerk to Supabase via native third-party auth, created a posts table owned by the Clerk user, enabled RLS with four policies, and added a server client that passes the Clerk session token.

    1. Dashboard setup

    • Clerk Dashboard: open the Supabase integration and activate it. Copy the Frontend API URL (domain).
    • Supabase Dashboard: Authentication > Sign In / Providers > add Clerk and paste that domain.

    2. Migration

    create table public.posts (
      id uuid primary key default gen_random_uuid(),
      user_id text not null default (auth.jwt()->>'sub'),
      title text not null,
      created_at timestamptz not null default now()
    );
    
    alter table public.posts enable row level security;
    
    create policy "posts_select_own" on public.posts
      for select to authenticated
      using ((select auth.jwt()->>'sub') = user_id);
    
    create policy "posts_insert_own" on public.posts
      for insert to authenticated
      with check ((select auth.jwt()->>'sub') = user_id);
    
    create policy "posts_update_own" on public.posts
      for update to authenticated
      using ((select auth.jwt()->>'sub') = user_id)
      with check ((select auth.jwt()->>'sub') = user_id);
    
    create policy "posts_delete_own" on public.posts
      for delete to authenticated
      using ((select auth.jwt()->>'sub') = user_id);
    

    3. Server client

    import { auth } from "@clerk/nextjs/server";
    import { createClient } from "@supabase/supabase-js";
    
    export async function createServerSupabase() {
      const { getToken } = await auth();
      return createClient(
        process.env.NEXT_PUBLIC_SUPABASE_URL!,
        process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
        { accessToken: async () => (await getToken()) ?? null }
      );
    }
    

    4. Audit result

    RLS audit of /your/project
    Scanned 1 SQL files and 3 code files.

    No findings. This does not prove the live database is safe; check the dashboard too.

    Next steps

    • Test with two different Clerk users and confirm each sees only their own rows
    • Keep the service-role key server-side only, never in client code
    • If you have existing rows, backfill user_id with the Clerk user IDs

    Connects securely to your tools. The creator never sees your data.

    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.

    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

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed today

    Accounts
    SupabaseClerk account
    Software
    Python 3.8+Next.js App Router projectSupabase 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.

    Permissions

    Terminal / Shell
    Read Files
    Write Files

    Allowed Hosts

    clerk.com
    supabase.com

    File Scopes

    supabase/migrations/**
    app/**
    lib/**
    middleware.ts
    src/app/**
    src/lib/**
    src/middleware.ts
    **/*.sql
    **/*.ts
    **/*.tsx
    **/*.js
    **/*.jsx
    **/*.mjs

    Writes SQL migrations and Next.js helper files. Terminal runs a local, offline Python audit script that reads .sql and code files in your project (no network, no .env files).

    Listedtoday

    What's inside

    Creator

    prince raj

    prince raj

    Frequently Asked Questions

    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.

    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.

    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.

    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.

    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.

    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.

    New in Frontend & Web Apps

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Frontend & Web Apps.