Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    Auth & Multi-Tenant Blueprint: Sessions, RBAC, Isolation

    1

    Designs and implements authentication and authorization for SaaS: session vs JWT choice, refresh rotation, RBAC/permissions model, tenant isolation with Postgres row-level security, and the tests that prove one tenant can't read another's data.

    $8.99

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Auth & Multi-Tenant Blueprint: Sessions, RBAC, Isolation

    Auth & Multi-Tenant Blueprint: Sessions, RBAC, Isolation

    Example session with this skill installed

    Add organizations, roles and tenant isolation to my Next.js + Prisma + Postgres SaaS. Users can belong to multiple workspaces.

    • Read your context and instructions
    • Compiled the auth & multi-tenant

    Decision (ADR-007): keep Auth.js sessions (httpOnly cookie). Active workspace stored in the session; switching workspace re-issues it. No JWTs needed: single domain, no mobile app yet.

    Schema (Prisma)

    model Organization { id String @id @default(uuid()) name String memberships Membership[] }
    model Membership {
      userId String  orgId String  role Role @default(MEMBER)
      @@id([userId, orgId])
    }
    enum Role { OWNER ADMIN MEMBER VIEWER }
    

    All 9 tenant tables get orgId String + @@index([orgId]).

    Policy layer lib/authz.ts

    const PERMS = { VIEWER: ['read'], MEMBER: ['read','write'], ADMIN: ['read','write','invite'], OWNER: ['*'] } as const;
    export function can(role: Role, action: string) { return PERMS[role].includes('*' as never) || PERMS[role].includes(action as never); }
    

    RLS: migration enables RLS on all tenant tables; Prisma client extension wraps each request in a transaction with SET LOCAL app.org_id.

    Tests added (Vitest + test DB): cross-tenant read returns 404 (API) and 0 rows (DB); viewer POST /invoices → 403; removed member's next request → 401.

    Next: invite flow with signed, single-use tokens (7-day expiry).

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

    About this skill

    Designs and implements authentication and authorization for SaaS: session vs JWT choice, refresh rotation, RBAC/permissions model, tenant isolation with Postgres row-level security, and the tests that prove one tenant can't read another's data.

    How it works

    • Decide (write an ADR)
    • Tenant model
    • Authorization
    • Isolation in depth (Postgres)
    • Tests that must exist
    • Output

    Use it when

    You say build login, sessions or JWT, refresh tokens, roles and permissions, RBAC, organizations/workspaces, tenant isolation, row level security, invite users, or SSO later.

    Why this one

    • Concrete output: code, tables and next steps you can act on today
    • Verifies before it claims: no generic advice
    • Works with Claude Code, Codex CLI, Cursor, Gemini CLI and any SKILL.md agent

    More by Ignasi: 8 bundles (Ship to Production, Founder Growth, Investor Research and more) save up to 52%.

    Requires Postgres for RLS features. Does not generate frontend UI components or login forms.

    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 any payment.

    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

    Permissions

    No special permissions declared or detected

    Listedtoday

    What's inside

    Frequently Asked Questions

    This skill provides an end-to-end security architecture, including database-level Postgres RLS policies, application middleware, and optimized schemas to prevent data leaks between organizations.

    The skill is designed to work with any LLM-based agent that can process architectural logic and output code, such as AutoGPT, BabyAGI, or custom development assistants.

    No, this skill is a backend and database architecture specialist; it provides the logic, schemas, and middleware but does not generate CSS or frontend UI components.

    Yes, the blueprint is flexible and supports third-party providers like Clerk and Auth0, as well as custom-built session management or JWT-based solutions.

    You receive a comprehensive implementation package including Architecture Decision Records (ADRs), SQL migration scripts for RLS, RBAC middleware logic, and security test cases.

    While the architectural principles are universal, the data isolation features are specifically optimized for PostgreSQL due to its robust Row Level Security (RLS) capabilities.

    New in APIs & Backend