feat: add multi-tenant client management for admins

- Add tenants API endpoints (list, get, create)
- Add tenant middleware override via X-View-Tenant header
- Add TenantSelector dropdown component in header
- Add tenant view store with persistence
- Add Clientes management page
- Update all navigation layouts with Clientes link for admins

Admins can now:
- View list of all clients
- Create new clients with automatic schema setup
- Switch between viewing different clients' data
- See which client they are currently viewing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Consultoria AS
2026-01-22 03:55:44 +00:00
parent 6e3e69005b
commit 0c10c887d2
16 changed files with 768 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ declare global {
namespace Express {
interface Request {
tenantSchema?: string;
viewingTenantId?: string;
}
}
}
@@ -16,8 +17,18 @@ export async function tenantMiddleware(req: Request, res: Response, next: NextFu
}
try {
// Check if admin is viewing a different tenant
const viewTenantId = req.headers['x-view-tenant'] as string | undefined;
let tenantId = req.user.tenantId;
// Only admins can view other tenants
if (viewTenantId && req.user.role === 'admin') {
tenantId = viewTenantId;
req.viewingTenantId = viewTenantId;
}
const tenant = await prisma.tenant.findUnique({
where: { id: req.user.tenantId },
where: { id: tenantId },
select: { schemaName: true, active: true },
});