Multi-tenancy with VerifiedRoutes

Hey—I’m looking for some guidance on building multi-tenant-aware paths using VerifiedRoutes.

I have an app that supports multi-tenancy with either a tenant identifier in the path, or custom domains, and the path can optionally contain a list of directly nested entities;

  1. https://my-app.example/tenant-1/parent/child/grandchild
  2. https://tenant-2.example/parent/child/grandchild

Exploding each path into distinct helpers like grandchild_path/3, child_path/2, and parent_path/1 feels like the wrong approach, given that each entity can have many different types of children.

I thought about defining something like this, but I think I’d lose the compile time warnings if I use a list of entities to build ~p

def tenant_path(conn_or_socket, tenant, entities \\ []) when == "my-app.example",
  do: path(conn_or_socket, Router, ~p"/#{tenant}/entities...")

def tenant_path(conn_or_socket, entities \\ []),
  do: path(conn_or_socket, CustomDomainRouter, ~p"/entities...")