Loading video player...
βοΈGet started with Clerk here π https://go.clerk.com/sonny Building a B2B SaaS app? Then you already know the nightmare. Invite systems, membership management, org switching, role-based access control β you end up spending weeks building auth infrastructure instead of your actual product. And half the time it's still broken. This video shows you how to build a fully multi-tenant B2B SaaS app with Clerk Organizations β roles, permissions, invite flows, feature gating, and even per-org subscriptions β with very little code. Clerk Organizations lets you add Slack-style multi-tenancy to your app: one user, multiple workspaces, each with their own roles, permissions, and separate plans. It's the infrastructure layer that would take months to build from scratch, and you can drop it in with a few lines of code. In this 43-minute deep dive, I'll walk you through the entire setup from zero β creating custom roles with granular permissions, building invite flows with verified domains, gating features on both the server and client, and wiring up Clerk's built-in subscription system so each organization gets its own plan with automatic feature unlocks. We'll cover: β What multi-tenancy actually means and why it matters for B2B SaaS β Setting up Clerk Organizations with custom roles and granular permissions β Adding an org switcher to your app with a single component β Email invites, verified domain auto-join, and request-to-join flows β Server-side and client-side feature gating with has() and the Show component β Clerk's built-in subscription system with per-org plans (Free, Pro, Ultra) β Plan-based feature gating that unlocks automatically on upgrade β Handling edge cases like proration and separate org-level subscriptions Stop rebuilding auth infrastructure from scratch. Build the product instead. π£ TIMESTAMPS: 0:00 Intro 0:57 What is Multi-Tenancy? 1:56 Setting Up Clerk Organizations 2:22 Creating a New Clerk Application 2:42 Selecting Your Tech Stack (Next.js) 3:01 Installing the Starter Template 3:28 Installing Clerk SDK 3:55 Keyless Mode vs API Keys 4:16 Running the App 5:04 Testing in the Browser 5:48 Enabling Organizations in Clerk 7:10 Roles & Permissions Setup 7:35 Creating a Custom Reader Role 10:34 Adding the Organization Switcher Component 10:55 Logging In & Creating an Organization 11:53 Inviting Members to Your Organization 12:38 Verified Domains for Auto-Join 14:37 Automatic Suggestions vs Invitations 15:30 Request to Join Flow Demo 17:00 Email Invite Flow Demo 18:03 Gating Features with Server Components 20:48 Using the has() Function for Permissions 21:58 Disabling UI Based on Permissions 23:30 Task List Component with Permission Checks 24:03 Client Component Permission Checks (useOrganization) 26:24 The Show Component (Declarative Gating) 29:07 Setting Up Clerk Billing 29:16 Enabling Organization Billing 30:00 Creating Subscription Plans (Pro) 32:51 Adding a Pricing Table Component 33:32 Upgrading & Permissions Restored 36:00 Creating an Ultra Plan 36:52 Gating by Feature (Ultra Feature Demo) 39:30 Clerk Billing Edge Cases & Proration 41:00 Multiple Organizations with Separate Billing 42:30 Recap & Final Thoughts βΈ» β οΈ DISCLAIMER: This video is sponsored by Clerk. All opinions are my own β I only share tools I personally use and believe will help the developer community. ββββββ π Learn to code with AI here: https://www.papareact.com/course π₯ Join our AI coding community for FREE: https://www.universityofcode.com Follow me on socials: π Instagram: https://instagram.com/sonnysangha π Twitter/X: https://x.com/sonnysangha π LinkedIn: https://linkedin.com/in/sonnysangha π TikTok: https://tiktok.com/@sonnysangha