agentleFS
imbhargav5imbhargav5/nextbase-nextjs-supabase-starter/.agents/skills/nextbase-auth-ssr/SKILL.md

nextbase-auth-ssr

Skill827 starsChanged 3 months agoMITView on GitHub

Use for NextBase Supabase SSR authentication, browser/server/middleware clients, cookie propagation, protected routes, auth callbacks, redirects, getClaims, getUser, or session handling.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 1 is distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Only the publishable key may be used in browser-visible code.

    line 17
  2. Very specific:

    Use getUser() when the request boundary must revalidate the user with Supabase, especially middleware/proxy route protection and sensitive …

    line 21
  3. Very specific:

    Use getClaims() for locally verified claims and authenticated IDs inside already protected server work when its guarantees are sufficient.

    line 22
  4. Very specific:

    Do not authorize from getSession() alone.

    line 23
  5. Very specific:

    Use the request-memoized helpers in src/rsc-data/supabase.ts instead of repeating auth calls during one render.

    line 24
  6. Very specific:

    Do not insert unrelated work between createServerClient() and the auth verification call in middleware.

    line 28
  7. Distinctive:

    Do not treat the protected-route list as data authorization.

    line 31

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

NextBase Auth SSR

Load the vendored supabase skill as well. Verify current Supabase SSR guidance before changing auth behavior.

Existing Client Boundaries

  • Browser code uses createClient() from src/supabase-clients/client.ts.
  • Server Components, actions, and route handlers use createSupabaseClient() from src/supabase-clients/server.ts.
  • src/supabase-clients/middleware.ts owns request/response cookie refresh. Preserve the complete getAll/setAll propagation to both the request and response.
  • src/proxy.ts owns route matching and delegates session refresh. Keep API and static-asset exclusions deliberate.

Only the publishable key may be used in browser-visible code. Never expose a secret or service_role key.

Verification Choice

  • Use getUser() when the request boundary must revalidate the user with Supabase, especially middleware/proxy route protection and sensitive re-verification.
  • Use getClaims() for locally verified claims and authenticated IDs inside already protected server work when its guarantees are sufficient.
  • Do not authorize from getSession() alone. A locally stored session is not a fresh authorization check.
  • Use the request-memoized helpers in src/rsc-data/supabase.ts instead of repeating auth calls during one render.

Middleware and Protected Routes

  1. Do not insert unrelated work between createServerClient() and the auth verification call in middleware.
  2. Match actual public URL segments, including nested routes. Test both the route root and a representative child route.
  3. Redirect anonymous users to /login while preserving cookies set on the Supabase response.
  4. Do not treat the protected-route list as data authorization; RLS remains mandatory.

Callback Safety

  1. Exchange the code or verify the OTP before redirecting.
  2. Accept a next destination only when it is a same-origin relative path beginning with one / and not //. Reject encoded or decoded absolute URLs and protocol-relative URLs.
  3. Construct the final destination from an approved path and the request origin. Never pass arbitrary user input directly to new URL().
  4. Send failed verification to /auth/auth-code-error and avoid logging tokens or cookie values.
  5. Revalidate only after auth state changes successfully.

Verification

Cover anonymous redirect, authenticated access, cookie refresh, callback success, callback failure, and malicious next values. Use the real local Supabase stack for auth integration tests.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.