Help centerYour app's customers
Tenant context
Tell each domain which customer it belongs to in your app and receive that customer's id and data, signed, on every request (X-Tenanci-Tenant) and, optionally, in the browser as window.TENANCI.
An app built for one customer can serve many, each on their own domain, without you writing any per-domain routing code. You tell each domain which customer it is in your app (the id plus a few fields such as name, plan and colors), and Tenanci hands that to your backend on every request, signed, and to the browser if you want.
How it works
- Each domain stores the customer id from your system (say, the barbershop's id in your database) and, optionally, some data about them.
- On every request through the domain, the Tenanci edge adds
X-Tenanci-*headers with that context before it reaches your origin. - If the project has a signing secret, the headers are signed (HMAC-SHA256): your backend checks the signature and knows the customer was set by Tenanci.
- With Available in the browser turned on, pages also get
window.TENANCI, so your front end can show the customer's branding without calling your API.
Set the customer for a domain
- Open the project, go to Domains and click the domain.
- On the Settings tab, find the Customer for this domain card.
- In Customer id in your app, enter the id your system uses (letters, numbers and
. _ : @ -). - Under Customer data, click Add field for each piece of information: the Field name, the Type (Text, Number or Yes/no) and the Value.
- If your front end needs this data, turn on Available in the browser (window.TENANCI).
- Click Save. The context goes live within a few seconds.
To remove the customer from a domain, clear the id and save: the headers stop being sent.
Headers your backend receives
| Header | Contents |
|---|---|
X-Tenanci-Tenant |
customer id (e.g. barbershop-123) |
X-Tenanci-Tenant-Data |
customer data: JSON encoded as base64url, with no trailing = |
X-Tenanci-Domain |
the domain the visitor opened (e.g. joesbarbershop.com) |
X-Tenanci-Timestamp |
when the signature was made, in Unix seconds |
X-Tenanci-Tenant-Signature |
hex(HMAC-SHA256(secret, message)); only present if the project has a secret |
The headers are only sent when the domain has a customer id set.
Generate the signing secret
The secret belongs to the project and covers all of its domains.
- Open the project and go to the Customization tab.
- Open the Customers tab and find the Tenant context signature card.
- Click Generate secret (or Rotate secret if one already exists, and confirm).
- Copy the secret (it starts with
tsk_) and store it on your backend, in an environment variable or a secrets manager.
Without a secret, the headers still arrive, just without X-Tenanci-Tenant-Signature.
Verify the signature
The signed message is four lines joined by \n, with no trailing \n, using the values exactly as they arrived
in the headers (the data still base64url-encoded):
<X-Tenanci-Timestamp>
<X-Tenanci-Domain>
<X-Tenanci-Tenant>
<X-Tenanci-Tenant-Data>Compute the HMAC-SHA256 of that message with the secret, as lowercase hex, and compare it with
X-Tenanci-Tenant-Signature in constant time. Also reject the request if the timestamp is more than 5 minutes away
from your clock.
import crypto from "node:crypto";
export function tenantOf(req, secret) {
const ts = req.get("X-Tenanci-Timestamp");
const domain = req.get("X-Tenanci-Domain");
const id = req.get("X-Tenanci-Tenant");
const data = req.get("X-Tenanci-Tenant-Data") ?? "";
const sig = req.get("X-Tenanci-Tenant-Signature") ?? "";
if (!ts || !domain || !id || Math.abs(Date.now() / 1000 - Number(ts)) > 300) return null;
const want = crypto.createHmac("sha256", secret).update(`${ts}\n${domain}\n${id}\n${data}`).digest("hex");
if (sig.length !== want.length || !crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(want))) return null;
return { id, domain, data: JSON.parse(Buffer.from(data, "base64url").toString("utf8") || "{}") };
}import base64, hashlib, hmac, json, time
def tenant_of(headers, secret: str):
ts, domain, tid = headers.get("X-Tenanci-Timestamp"), headers.get("X-Tenanci-Domain"), headers.get("X-Tenanci-Tenant")
data, sig = headers.get("X-Tenanci-Tenant-Data", ""), headers.get("X-Tenanci-Tenant-Signature", "")
if not (ts and domain and tid) or abs(time.time() - int(ts)) > 300:
return None
want = hmac.new(secret.encode(), f"{ts}\n{domain}\n{tid}\n{data}".encode(), hashlib.sha256).hexdigest()
if not hmac.compare_digest(sig, want):
return None
raw = base64.urlsafe_b64decode(data + "=" * (-len(data) % 4)) if data else b"{}"
return {"id": tid, "domain": domain, "data": json.loads(raw)}<?php
function tenanci_tenant(string $secret): ?array {
$ts = $_SERVER['HTTP_X_TENANCI_TIMESTAMP'] ?? '';
$domain = $_SERVER['HTTP_X_TENANCI_DOMAIN'] ?? '';
$id = $_SERVER['HTTP_X_TENANCI_TENANT'] ?? '';
$data = $_SERVER['HTTP_X_TENANCI_TENANT_DATA'] ?? '';
$sig = $_SERVER['HTTP_X_TENANCI_TENANT_SIGNATURE'] ?? '';
if ($ts === '' || $domain === '' || $id === '' || abs(time() - (int) $ts) > 300) return null;
$want = hash_hmac('sha256', "$ts\n$domain\n$id\n$data", $secret);
if (!hash_equals($want, $sig)) return null;
$json = $data === '' ? '{}' : base64_decode(strtr($data, '-_', '+/'));
return ['id' => $id, 'domain' => $domain, 'data' => json_decode($json, true) ?? []];
}In the browser (window.TENANCI)
With Available in the browser (window.TENANCI) turned on, every HTML page on the domain gets this in its
<head>, before any of your app's scripts:
<script>window.TENANCI={"domain":"joesbarbershop.com","tenant":{"id":"barbershop-123","data":{"name":"Joe’s Barbershop","plan":"pro"}}};</script>Use it to swap the name, colors or plan on screen without calling your API. It's the way to go for apps that can only read the customer in the browser (FlutterFlow, WeWeb, Lovable, Bolt); see integrations.
Through the API
Set a domain's customer with PUT /domains/:id/tenant:
curl -X PUT https://api.tenanci.com/v2/domains/dom_4h7n1q/tenant \
-H "Authorization: Bearer tnc_live_xxxxxxxx_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"id":"barbershop-123","data":{"name":"Joe’s Barbershop","plan":"pro"},"expose":true}'await tenanci.domains.setTenant("dom_4h7n1q", {
id: "barbershop-123",
data: { name: "Joe’s Barbershop", plan: "pro" },
expose: true,
});Or right when you create the domain, with the tenant field on POST /domains:
curl -X POST https://api.tenanci.com/v2/domains \
-H "Authorization: Bearer tnc_live_xxxxxxxx_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"projectId":"prj_8f3k2m","hostname":"joesbarbershop.com","tenant":{"id":"barbershop-123","data":{"name":"Joe’s Barbershop"}}}'const domain = await tenanci.domains.create({
projectId: "prj_8f3k2m",
hostname: "joesbarbershop.com",
tenant: { id: "barbershop-123", data: { name: "Joe’s Barbershop" } },
});To read what's set, use GET /domains/:id/tenant: the response also tells you
whether the project already has a secret (projectHasSecret). You can generate or rotate the secret with
POST /projects/:id/tenant-secret, which returns the new value only once.
All of these calls need a key with domains:write (or domains:read to read).
Rules and limits
| Item | Rule |
|---|---|
| Customer id | letters, numbers and . _ : @ -, up to 100 characters |
| Number of fields | up to 40 |
| Field name | starts with a letter; letters, numbers and _ only; up to 40 characters |
| Value | text (up to 500 characters), number, true/false or null |
Data outside these rules is rejected with 400 (the message says which field), and the domain is left unchanged.

