Nextjs supabase auth

From Asymmetric-al/core · View interactive version

Nextjs supabase auth is an AI agent skill from the GitHub repository Asymmetric-al/core. Integrate Supabase Auth with Next.js App Router using each app's proxy.ts (Next.js 16 Proxy, formerly middleware), callback handling, protected routes, and server/client client boundaries.

How to use this skill

Skill file

Next.js + Supabase Auth

Use this skill for authentication work in Next.js App Router with Supabase Auth.

When to Apply

Use this skill when:

Do not use this skill when:

Core Rules

  1. Shared auth lives in packages/auth (@asym/auth); read packages/auth/AGENTS.md first. Apps re-export package contracts instead of creating a second client.
  2. Route protection and session refresh run in each app's proxy.ts (Next.js 16 Proxy, formerly middleware) through createAuthMiddleware from @asym/auth/middleware, which validates the user with auth.getUser(). Public routes are listed explicitly there.
  3. Server code resolves the caller with getAuthContext, requireAuth, or requireRole from @asym/auth/context. Business data access stays in packages/api; app route handlers must not import @asym/database/supabase/* or @supabase/* directly (docs/guides/architecture/data-access-boundary.md).
  4. Supabase clients come from packages/database: @asym/database/supabase/server for server code, createBrowserClient from @asym/database/supabase for the browser, and @asym/database/supabase/admin (service role) only in trusted server code.
  5. Auth callbacks re-export the shared handler (export { GET } from "@asym/api/auth/callback").
  6. Do not manually store or forward auth tokens in client code. Maintain RLS assumptions; do not bypass policy boundaries. Fail closed.

Workflow

  1. Identify the execution boundary first (Server Component, Client Component, proxy, Server Action, or route handler).
  2. Use the shared helper for that boundary; do not create a new Supabase client.
  3. Check the app's proxy.ts public-route list when adding or protecting a route.
  4. Validate auth and role before sensitive reads or writes.
  5. Write the regression test first (packages/auth/context.*.test.ts cover the request auth context), then verify login, logout, and session refresh end to end.

Checklist

Common Anti-Patterns

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.