- Home
- Skills
- APIs & Backend
- Auth & Multi-Tenant Blueprint: Sessions, RBAC, Isolation
Works with the AI Agents you already use
Auth & Multi-Tenant Blueprint: Sessions, RBAC, Isolation
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
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%.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.
Requires Postgres for RLS features. Does not generate frontend UI components or login forms.
How to use
- 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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 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
Permissions
No special permissions declared or detected