Skip to main content
The Tenants module provides methods to create, fetch, update, delete, and interact with tenants that the currently authenticated user is a member of. Each user may belong to multiple tenants, and most operations automatically default to the currently selected tenant. You can explicitly override this by providing a tenant ID to most methods.
Most methods assume the current user is authenticated. If not, a 401 Unauthorized error will be returned.

Setting the Current Tenant

You can manually set the current tenant using await nile.withContext({ tenantId }). withContext returns a copy of the nile instance with a context that captures what was passed. It also accepts a second parameter for convenience for multiple requests.
Returns a nile with the context
Self contained callback
This method updates the internal configuration to use the given tenant in subsequent API calls.
Framework-specific integrations may set context automatically, so calling withContext every time may not be necessary in those environments. see extensions for more information
This ID is typically sourced from:
  • The result of create()
  • A specific tenant via get()
  • A selected tenant from list()
If not explicitly set, an error will be thrown by the SDK if the tenant Id is missing.

create

Create a new tenant using POST /api/tenants. The current user is automatically linked to the new tenant.

Parameters

  • name: Name of the tenant (required)
  • id: Optional. Unique ID to use instead of auto-generating

Returns

If successful, resolves to a Tenant object:
Returns a Response with 401 or 400 on failure.

get

Fetch a specific tenant or the current tenant using GET /api/tenants/{id}.

Parameters

  • id: Optional. If omitted, uses the current context

Returns

A Tenant object or a raw Response.

update

Update the name of the current tenant via PUT /api/tenants/{id}.

Parameters

  • name: New name of the tenant
  • id: Optional. If omitted, uses context

Returns

Updated Tenant object or a Response.
Only the name is currently updatable.

delete

Mark a tenant as deleted using DELETE /api/tenants/{id}. This is a soft delete.

Returns

A Response with status 204 on success.

list

List all tenants the current user belongs to via GET /api/tenants/by-user.

Returns

Array of Tenant objects:
401 if the user is unauthenticated.

users

List users who are members of a given tenant (or the current one).

Returns

Array of User objects, or a Response on error.

addMember

Add a user to the current tenant using their user ID.

Returns

The added User object or a Response.

removeMember

Remove a user from the tenant.

Returns

A Response.

leaveTenant

Removes the current user from a tenant they belong to.

Returns

A Response.

invites

Fetch all invites for the current tenant:

Returns

An array of Invite objects.

invite

Invite a new user by email to the current tenant. the callbackUrl is the value that is used to return the user to a page that renders HTML. There is a primary endpoint that is used to exchange the token in the email to join the tenant. Upon a successful exchange, the user will be redirected to the callbackUrl

Parameters

  • email: Email of the user to invite
  • callbackUrl: Optional URL to redirect after acceptance
  • redirectUrl: Optional URL used as the base in the email

Returns

An Invite object or a Response.

acceptInvite

Accept an invite using an emailed token and email address.

Returns

A Response indicating success or failure.

deleteInvite

Delete a previously sent invite.

Returns

A Response.