Skip to content

FluxbaseTenant

FluxbaseTenant provides multi-tenant management functionality

// List tenants I have access to
const { data } = await client.tenant.listMine()
// Get tenant details
const { data } = await client.tenant.get('tenant-id')
// Create a tenant (instance admin only)
const { data } = await client.tenant.create({
slug: 'acme-corp',
name: 'Acme Corporation'
})
// Assign admin to tenant (tenant admin only)
await client.tenant.assignAdmin('tenant-id', {
user_id: 'user-id'
})

new FluxbaseTenant(fetch): FluxbaseTenant

ParameterType
fetchFluxbaseFetch

FluxbaseTenant

assignAdmin(tenantId, options): Promise<FluxbaseResponse<TenantAdminAssignment>>

Assign an admin to a tenant (tenant admin only)

ParameterTypeDescription
tenantIdstringTenant ID
optionsAssignAdminOptionsAdmin assignment options

Promise<FluxbaseResponse<TenantAdminAssignment>>

Promise with created assignment or error

const { data, error } = await client.tenant.assignAdmin('tenant-id', {
user_id: 'user-id'
})

create(options): Promise<FluxbaseResponse<Tenant>>

Create a new tenant (instance admin only)

This creates a new isolated database for the tenant.

ParameterTypeDescription
optionsCreateTenantOptionsTenant creation options

Promise<FluxbaseResponse<Tenant>>

Promise with created tenant or error

const { data, error } = await client.tenant.create({
slug: 'acme-corp',
name: 'Acme Corporation',
metadata: { plan: 'enterprise' }
})

delete(id): Promise<FluxbaseResponse<void>>

Delete a tenant (instance admin only)

This permanently deletes the tenant’s database and all its data. Cannot delete the default tenant.

ParameterTypeDescription
idstringTenant ID

Promise<FluxbaseResponse<void>>

Promise that resolves when deleted

const { error } = await client.tenant.delete('tenant-id')

get(id): Promise<FluxbaseResponse<Tenant>>

Get a tenant by ID

ParameterTypeDescription
idstringTenant ID

Promise<FluxbaseResponse<Tenant>>

Promise with tenant details or error

const { data, error } = await client.tenant.get('tenant-id')

list(): Promise<FluxbaseResponse<Tenant[]>>

List all tenants (instance admin only)

Promise<FluxbaseResponse<Tenant[]>>

Promise with tenants list or error

const { data, error } = await client.tenant.list()

listAdmins(tenantId): Promise<FluxbaseResponse<TenantAdminAssignment[]>>

List admins of a tenant

ParameterTypeDescription
tenantIdstringTenant ID

Promise<FluxbaseResponse<TenantAdminAssignment[]>>

Promise with admin list or error

const { data, error } = await client.tenant.listAdmins('tenant-id')
// data: [{ id: '...', tenant_id: '...', user_id: '...', email: 'admin@example.com' }]

listMine(): Promise<FluxbaseResponse<TenantWithRole[]>>

List tenants the current user has access to

Promise<FluxbaseResponse<TenantWithRole[]>>

Promise with tenants and user’s role in each

const { data, error } = await client.tenant.listMine()
// data: [{ id: '...', slug: 'acme', name: 'Acme', my_role: 'tenant_admin', status: 'active' }]

migrate(id): Promise<FluxbaseResponse<{ status: string; }>>

Migrate a tenant database to the latest schema (instance admin only)

ParameterTypeDescription
idstringTenant ID

Promise<FluxbaseResponse<{ status: string; }>>

Promise with migration status or error

const { data, error } = await client.tenant.migrate('tenant-id')
// data: { status: 'migrated' }

removeAdmin(tenantId, userId): Promise<FluxbaseResponse<void>>

Remove an admin from a tenant (tenant admin only)

ParameterTypeDescription
tenantIdstringTenant ID
userIdstringUser ID

Promise<FluxbaseResponse<void>>

Promise that resolves when removed

const { error } = await client.tenant.removeAdmin('tenant-id', 'user-id')

update(id, options): Promise<FluxbaseResponse<Tenant>>

Update a tenant (tenant admin only)

ParameterTypeDescription
idstringTenant ID
optionsUpdateTenantOptionsUpdate options

Promise<FluxbaseResponse<Tenant>>

Promise with updated tenant or error

const { data, error } = await client.tenant.update('tenant-id', {
name: 'New Name'
})