Multi-Tenant SaaS with Next.js and Supabase: Secure Tenant Access

A multi-tenant application serves several organizations from one product. The central security requirement is that a user can access only the organizations and records they are authorized to use. A tenant identifier in a URL, form, or token is useful context; its source and the checks around it determine whether it is safe to trust.
Updated October 28, 2026. This guide separates general Supabase design guidance from the current Isla Hotel implementation.
Choose the Data Boundary First
In a shared-schema design, tenant-owned rows carry a tenant identifier. Membership records connect authenticated users to organizations and roles. PostgreSQL row-level security can apply those relationships to queries made through Supabase's Data API.
Separate schemas or databases provide other isolation boundaries, with additional migration and operational work. Choose a model around the product's access rules, recovery needs, and operating constraints. A booking website for one hotel does not need to become a multi-tenant SaaS simply because a hotel chain might need one later.
Keep Authorization Data Under Server Control
Supabase users can update their own user_metadata. Do not use that field to grant tenant membership or administrator privileges. A signed token can contain user-editable metadata; a valid signature alone does not make every claim a safe authorization source.
app_metadata can hold server-managed authorization information. The backend that writes it must first verify the user's membership and permission to make the change. Token claims can remain stale until a token is refreshed, so decide how membership removal and role changes must take effect. Supabase documents these distinctions in its RLS reference.
A protected membership table is another option. Resolve the authenticated user to their current memberships, and restrict who can insert, update, or remove those memberships. Allowing a user to assign themselves to an arbitrary organization defeats the lookup.
Connect Authentication to Each Data Operation
- Validate the session on the server and establish the authenticated user.
- Treat a requested tenant ID or subdomain as a selection that still needs authorization.
- Check the user's membership and the permission needed for the action.
- Scope reads, writes, exports, and file access to that authorized organization. An update must not move a record into an organization the user cannot access.
- Apply database grants and policies for the role that actually executes the query, then test both allowed and denied operations.
When using custom Supabase JWT claims, issue them through a trusted authentication flow. The custom-claims guide shows how an access-token hook and stored permissions can work together.
A PostgreSQL setting such as app.current_tenant_id is separate from a JWT claim with that name. Supabase exposes request claims through auth.jwt() and request JWT settings; it does not automatically populate an arbitrary application setting. See the request-claims documentation. An unchecked function that lets callers set their own authorization context is not a membership check.
Know Which Role Reaches the Database
Supabase service-role credentials can bypass RLS and must remain on the server. A shared server role that is allowed to access all application rows also leaves ownership and permission checks to application code. Do not assume that a policy tested with an end-user token protects a query executed under a more privileged role.
Isla Hotel: The Current Single-Hotel Implementation
Isla Hotel is a booking website for one hotel in Beit Sahour. Its database moved from Supabase to Neon PostgreSQL in October 2026. It is an example of a single-hotel application with server-side authorization, rather than a deployed example of the multi-tenant Supabase design discussed above.
- Next.js and React provide the guest booking website and staff administration interface.
- NextAuth manages guest sessions; staff use a separate signed session with database-backed role checks.
- Server-side queries enforce guest ownership and staff permissions. The database application's RLS policies permit server operations; they do not isolate hotel tenants through JWT claims.
- Capacity-aware availability, server-calculated prices, and guarded booking writes support reservations. Guests reserve online and pay at the hotel.
- Resend handles transactional email, and Vercel serves the application and room images.
Read the Isla Hotel architecture article for the booking and administration implementation.
Verify the Boundary You Designed
Use controlled test accounts in separate organizations. Check signed-out requests, non-members, insufficient roles, expired sessions, changed memberships, and attempts to read or modify another tenant's records. Include API routes, server actions, exports, file access, and background jobs. Check that cache keys include the authorization context needed to keep results separate.
For Isla Hotel's current design, the relevant boundary is guest ownership and staff permissions within one hotel. Adding another hotel would require an explicit tenancy design, a data migration, and new isolation checks before presenting the system as a multi-tenant product.
Planning a booking website or an organization-based product? Discuss the access rules and workflows with Axiosware before choosing the database model.
Tags
Want More Engineering Insights?
Get startup architecture patterns, AI development techniques, and product launch strategies delivered to your inbox.
Join the Axiosware Newsletter
Weekly insights for founders and technical leaders
We respect your privacy. Unsubscribe at any time.
