A tenant in Nile Auth represents a logical partition of the system, allowing for isolated user data and configurations. Each tenant operates independently with its own set of users, resources, and configurations, while sharing common underlying infrastructure. This is a fundamental feature for multi-tenant applications.
To manage tenants, you can interact with Nile Auth’s API and middleware. Below is an example of how you can set the tenantId based on the URL parameter and handle tenant-specific tasks:
Copy
Ask AI
// Middleware to set the tenantId from the URL parameterapp.param("tenantId", (req, res, next, tenantId) => { nile.withContext({ tenantId }); next();});// get all tasks for tenantapp.get("/api/tenants/:tenantId/todos", async (req, res) => { // No need for a "where" clause here because we are setting the tenant ID in the context const todos = await nile.query( `SELECT * FROM todos ORDER BY title` ); res.json(todos.rows);});
It is also possible to set a tenant id in a header using niledb-tenant-id
Ensure proper tenant isolation: Use tenant-specific identifiers (e.g., tenantId) in all queries and resource access to prevent cross-tenant data leakage.
Handle authentication per tenant: Authenticate users and sessions per tenant to maintain secure access controls.
Configure tenant-specific limits: For example, limit the number of tasks per tenant or customize resource allocations.