Skip to content
Packstub

Custom domains

Let each tenant serve their panel from a domain they own — app.acme-corp.com instead of acme.myapp.test — with DNS ownership verification, full-host routing, and single-origin authentication handled by the plugin. Subdomain identification mode only.

Enable the feature

TenancyPlugin::make()->customDomains()

or in config/packstub-tenancy.php:

'custom_domains' => [
    'enabled' => true,
],

Enabling it turns on three things:

  • a Domains page in the tenant panel (visible to tenant owners; placeable or optional) to add, verify, and remove domains, plus the tenants:domains Artisan command for operators;
  • routing: verified custom domains resolve the tenant exactly like subdomains do;
  • the auth handoff endpoints that sign users in on custom domains (see below).

Placing the Domains page

The Domains page shows up in the panel's main navigation with sort 90. Move it into a navigation group, give it another sort, or put it inside a cluster:

TenancyPlugin::make()->customDomains(
    group: 'Settings',          // a string or a navigation group enum
    sort: 10,
    cluster: Settings::class,   // your cluster class, registered on the panel
)

In a cluster the page shows in the cluster's sub-navigation and its URL moves under the cluster's slug (/settings/domains).

To change anything else (the label, icon, slug or who can open it), extend the page and pass your class:

use BackedEnum;
use Packstub\Tenancy\Filament\Pages\ManageTenantDomains;
use UnitEnum;

class Domains extends ManageTenantDomains
{
    protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-link';

    protected static string|UnitEnum|null $navigationGroup = 'Settings';

    public static function getNavigationLabel(): string
    {
        return 'Your domains';
    }
}
TenancyPlugin::make()->customDomains(page: Domains::class)

A group, sort or cluster passed to customDomains() (or set in the config) takes precedence over the subclass's own properties. These settings reach the page through ManageTenantDomains, so a page that doesn't extend it places itself.

When operators manage domains for tenants (with tenants:domains or a central panel of their own), leave the tenant-facing page out. Routing, verification and sign-in on custom domains keep working:

TenancyPlugin::make()->customDomains(page: false)

The same settings live in the config file as custom_domains.page, navigation_group, navigation_sort and cluster. They apply to the page class, so with custom domains on in two panels both panels share them.

Styling requirement: the Domains page is styled with Tailwind utilities, which your app compiles through a custom Filament theme that @sources this plugin's views. See Customizing the UI → Compiling the plugin's styles. Without it the page works but renders unstyled.

How a tenant attaches a domain

  1. Add the domain on the Domains page (or php artisan tenants:domains acme --add=app.acme-corp.com). It starts unverified — unverified domains never identify a tenant, so someone pointing a domain at your platform gains nothing until they prove ownership.

  2. Point DNS at your deployment — typically a CNAME from app.acme-corp.com to the tenant's default subdomain (acme.myapp.test), or an A/ALIAS record per your host's instructions.

  3. Publish the verification TXT record shown on the page:

    _packstub-verify.app.acme-corp.com   TXT   packstub-verify=<token>
    

    A CNAME pointing the domain at the tenant's default subdomain (or the central domain) also counts as proof — it demonstrates control and routing at once.

  4. Verify. The plugin checks DNS and stamps verified_at. From that moment the domain resolves the tenant.

Operators can bypass DNS with php artisan tenants:domains acme --force-verify=app.acme-corp.com (useful in local/dev environments where no real DNS exists — add a hosts-file or Herd alias instead).

How sign-in works (the handoff)

Browsers no longer share cookies across registrable domains, so a session on myapp.test is invisible on app.acme-corp.com. The plugin uses the post-third-party-cookie standard pattern (Clerk satellite domains, Shopify, Auth0): login happens on exactly one origin — your central domain — and identity crosses to custom domains via a single-use, short-lived code.

  1. An unauthenticated visit to app.acme-corp.com/admin redirects to the central authorize endpoint, carrying only the target host (validated against verified domains — never a free-form URL) and a path.
  2. If a central session exists, nothing is shown (silent). Otherwise the central login form appears — and the flow resumes after login.
  3. The server mints a 256-bit single-use code (only its hash is stored, TTL 60 seconds) and redirects to https://app.acme-corp.com/auth/handoff?code=….
  4. That landing page — no referrer leakage, non-cacheable, zero third-party assets — immediately POSTs the code same-origin. The exchange atomically consumes the code (replays fail), re-validates the tenant↔host mapping at redemption time, regenerates the session, and signs the user in behind a host-only cookie scoped to the custom domain.

The default is fully silent. To show a "Continue as …" confirmation on the custom domain instead:

TenancyPlugin::make()->customDomains()->handoffInterstitial()

Failures (expired code, replay, tampering) are deliberately generic — the visitor is returned to the central login; details are logged server-side under a correlation id, and rate limiting is keyed per host and per code (never per client IP, which CDN edges don't reliably preserve).

Logout propagates everywhere

Every custom-domain session references a central session grant. Logging out on any host — central, subdomain, or custom domain — revokes all grants minted from that central session and destroys the central session itself. Custom domains notice on their next request (each request re-validates the grant — a cheap central query); subdomains notice immediately because their shared session is gone. Expect propagation within one request per host.

Things to know

  • HTTPS/TLS is deployment-level. The plugin verifies ownership and routes requests; issuing certificates for tenant domains is your platform's job — e.g. Laravel Cloud/Vapor custom domains, Caddy on-demand TLS, Cloudflare for SaaS, or a wildcard + per-domain ACME setup on your own proxy. Serve custom domains over HTTPS only; the session cookie is issued Secure when the request is.
  • Passkeys/WebAuthn stay on the central domain. The credentials are origin-bound; a passkey registered on myapp.test can never sign in directly on app.acme-corp.com — which is fine, because login only ever happens centrally and the handoff carries the session across.
  • Remember-me is per-host. The central session's lifetime is what makes re-handoffs silent — protect it (sensible session lifetime, rotation).
  • Slug renames don't touch custom domains. Renaming a tenant's slug moves its default subdomain; explicitly added domains are never modified.
  • Sanctum guards are unsupported for the handoff (it requires a stateful guard); the guard in use is captured when the code is minted and re-checked at redemption.
  • URL generation follows the host. While a user browses app.acme-corp.com, every generated panel link stays on it; links generated anywhere else (central panel, email, console) use the tenant's default subdomain.

Configuration reference

'custom_domains' => [
    'enabled' => false,
    // The tenant-facing Domains page: a class, or false for none.
    'page' => ManageTenantDomains::class,
    // Where it sits in the navigation; null keeps the defaults.
    'navigation_group' => null,
    'navigation_sort' => null,
    'cluster' => null,
    // Show "Continue as …" instead of signing in silently.
    'interstitial' => false,
    // Seconds a handoff code stays redeemable. Hard-capped at 120.
    'handoff_ttl' => 60,
    // Path of the landing/exchange endpoint on tenant hosts.
    'handoff_path' => 'auth/handoff',
    // DNS TXT record name prefix used for ownership verification.
    'verification_prefix' => '_packstub-verify',
],

Fluent equivalents: ->customDomains(bool, page:, group:, sort:, cluster:) and ->handoffInterstitial(bool).

The tenants:domains command

php artisan tenants:domains                                  # list every domain
php artisan tenants:domains acme                             # one tenant, with pending TXT records
php artisan tenants:domains acme --add=app.acme-corp.com     # attach (unverified)
php artisan tenants:domains acme --verify=app.acme-corp.com  # run DNS verification
php artisan tenants:domains acme --force-verify=app.acme-corp.com  # mark verified, no DNS check
php artisan tenants:domains acme --remove=app.acme-corp.com  # detach
php artisan tenants:domains --fix                            # repair missing/stale default subdomains

Every listing also checks that each tenant owns a verified {slug}.central-domain row and flags the ones that don't — typically tenants minted while APP_URL still pointed at a previous central domain. --fix renames a single stale default, verifies an unverified one, or creates the missing row; custom domains are never touched.

The default {slug}.central-domain subdomain can never be removed, and domains inside the central namespace can never be added manually — they're managed by the slug.