Xano

How to use Xano’s multi-tenant isolation features?

Discover the secrets to using Xano's multi-tenant isolation features for building secure and scalable apps. This easy-to-follow guide covers everything from data partitioning to effective tenant management. Master these tools today!

Developer profile skeleton
a developer thinking

Overview

Xano's multi-tenant isolation features help developers build apps that are both secure and scalable. By keeping data and users separate, it makes sure each tenant's information stays protected, boosting security and performance. Knowing how to set up multi-tenant isolation means getting familiar with database partitioning, user authentication, and access controls. This setup keeps tenants' data views independent, enabling better resource use and upholding privacy standards. Learn how to make the most of these features for top-notch SaaS app development and management.

Get a Free No-Code Consultation
Meet with Will, CEO at Bootstrapped to get a Free No-Code Consultation
Book a Call
Will Hawkins
CEO at Bootstrapped

How to use Xano’s multi-tenant isolation features?

Step 1: Create a New Database Table for Tenant Information

Alright, let's dive in! First things first, we need a table just for tenant info.

  • Head over to the Database section in Xano.
  • Click on Create Table.
  • Give it a name, something like Tenants.
  • Add columns for tenant-specific details like tenant_id, tenant_name, and any other bits and bobs you think are important.

Step 2: Associate Entities with Tenants

Now, we need to make sure every piece of data knows which tenant it belongs to.

  • For each table that needs tenant-specific data, add a column called tenant_id.
  • Make tenant_id a foreign key that points to the tenant_id in the Tenants table.

Step 3: Set Up APIs to Handle Tenant Isolation

Next up, let's create some API endpoints to keep tenant data separate.

  • Go to the API section and whip up some new API endpoints.
  • Make sure each API query filters data based on the tenant_id provided.

Example:

// Always include a condition like this when fetching or manipulating data:
WHERE tenant_id = :tenant_id

Step 4: Implement Middleware for Tenant Verification

Middleware is our friend here. It helps verify tenants across all API endpoints.

  • Head to the Middleware section in your API.
  • Create a new middleware function to check and verify the tenant_id from the request.

Example:

function verifyTenant(req, res, next) {
  const tenantId = req.headers['tenant_id'];
  // Add logic to verify tenantId
  if(!tenantId) {
    return res.status(403).send("Unauthorized");
  }
  next();
}
  • Attach this middleware to your API endpoints to make sure tenant verification is enforced.

Step 5: Managing Tenant-Specific Authentication

Let's talk authentication. We need to make it tenant-specific.

  • If you're using JWT, include the tenant_id in the token payload.
  • When a user logs in, make sure the token generated includes their tenant_id.

Example Payload:

{
  "user_id": "123",
  "tenant_id": "abc-tenant-123"
}

Step 6: Testing the Multi-Tenant Setup

Finally, let's test everything to make sure it works as expected.

  • Create multiple tenant entries in your Tenants table.
  • Add some data for each tenant in the associated tables.
  • Use different tenant_id values in your API requests and check that data retrieval and manipulation are isolated based on tenant_id.

Example API Request:

GET /api/data
Headers: 
  tenant_id: "abc-tenant-123"

By following these steps, you can effectively implement Xano's multi-tenant isolation features to manage and secure tenant-specific data efficiently.

Explore more Xano tutorials

Complete Guide to Xano: Tutorials, Tips, and Best Practices

Explore our Xano tutorials directory - an essential resource for learning how to create, deploy and manage robust server-side applications with ease and efficiency.

Why are companies choosing Bootstrapped?

40-60%

Faster with no-code

Nocode tools allow us to develop and deploy your new application 40-60% faster than regular app development methods.

90 days

From idea to MVP

Save time, money, and energy with an optimized hiring process. Access a pool of experts who are sourced, vetted, and matched to meet your precise requirements.

1 283 apps

built by our developers

With the Bootstrapped platform, managing projects and developers has never been easier.

hero graphic

Our capabilities

Bootstrapped offers a comprehensive suite of capabilities tailored for startups. Our expertise spans web and mobile app development, utilizing the latest technologies to ensure high performance and scalability. The team excels in creating intuitive user interfaces and seamless user experiences. We employ agile methodologies for flexible and efficient project management, ensuring timely delivery and adaptability to changing requirements. Additionally, Bootstrapped provides continuous support and maintenance, helping startups grow and evolve their digital products. Our services are designed to be affordable and high-quality, making them an ideal partner for new ventures.

Engineered for you

1

Fast Development: Bootstrapped specializes in helping startup founders build web and mobile apps quickly, ensuring a fast go-to-market strategy.

2

Tailored Solutions: The company offers customized app development, adapting to specific business needs and goals, which ensures your app stands out in the competitive market.

3

Expert Team: With a team of experienced developers and designers, Bootstrapped ensures high-quality, reliable, and scalable app solutions.

4

Affordable Pricing: Ideal for startups, Bootstrapped offers cost-effective development services without compromising on quality.

5

Supportive Partnership: Beyond development, Bootstrapped provides ongoing support and consultation, fostering long-term success for your startup.

6

Agile Methodology: Utilizing agile development practices, Bootstrapped ensures flexibility, iterative progress, and swift adaptation to changes, enhancing project success.

Yes, if you can dream it, we can build it.