Skip to content

Revert "Revert #897"#947

Draft
busbyk wants to merge 5 commits intomainfrom
revert-926-revert-1.7.0
Draft

Revert "Revert #897"#947
busbyk wants to merge 5 commits intomainfrom
revert-926-revert-1.7.0

Conversation

@busbyk
Copy link
Collaborator

@busbyk busbyk commented Feb 16, 2026

Description

Re-lands the tenant lookup refactor (#897) that was reverted in #926 due to false 404s in production. This PR includes the original refactor, the routing fix from #949, and the removal of customDomain from the database (#972) — consolidating all tenant resolution into the hardcoded AVALANCHE_CENTERS constant as a single source of truth.

The original revert was caused by dynamicParams = false requiring generateStaticParams() to perfectly match what middleware sends — when it didn't, routes silently fell through to the catch-all 404. The fix uses dynamicParams = true so middleware handles "is this slug valid?" and the layout handles "does this center have data?", each doing what it's best positioned to do.

Related Issues

Reverts #926, re-lands #897, includes #972

Related: #579, #914

Key Changes

Tenant lookup refactor (from #897 / #949)

  • Replace Edge Config / API tenant resolution with hardcoded AVALANCHE_CENTERS — middleware is now synchronous and deterministic
  • payload-tenant cookie now stores slugs instead of numeric IDs
  • dynamicParams = true — centers in the DB are pre-rendered at build time; others served on-demand with graceful 404 handling
  • invariantnotFound() — proper 404 pages instead of 500 crashes when a center lacks DB data
  • Remove Edge Config update hooks and cached public tenants endpoint — no longer needed
  • Add useTenantLookup hook and refactor TenantSelectionProvider to use the new lookup
  • Simplify middleware — removed Edge Config and API fallback logic
  • Add decision doc docs/decisions/013-hardcoded-tenant-lookup.md and manual test cases in docs/tenant-selector.md

Remove customDomain from database (from #972)

  • Drop customDomain field from Tenants collection — all custom domain config now lives in AVALANCHE_CENTERS
  • Add getEmailDomain() utility — derives email-safe domain from custom domain by stripping www. prefix and port numbers
  • Refactor isTenantDomainScoped() — uses findCenterByDomain() instead of querying the database
  • Migration 20260303_233752_remove_custom_domain_from_tenants drops the custom_domain column
  • Fix e2e tests — updated tenant cookie assertions to use slugs instead of numeric IDs

How to test

  1. Run pnpm seed:standalone — verify it completes without errors
  2. Run pnpm dev and visit nwac.localhost:3000 — should render normally
  3. Visit a center in AVALANCHE_CENTERS but not in the DB — should show the not-found page, not crash
  4. Visit a completely invalid slug — should show the not-found page
  5. Visit localhost:3000/admin — verify the admin panel loads and tenant selector works
  6. Run pnpm tsc, pnpm lint, and pnpm test — verify no errors
  7. Test custom domain routing in a preview deployment

Screenshots / Demo video

See demo from original PR: https://www.loom.com/share/4c083b90aedf4df983eab130db9b1783

Migration Explanation

Migration: 20260303_233752_remove_custom_domain_from_tenants

  • Up: Drops the custom_domain column from the tenants table
  • Down: Re-adds the column as nullable text (values are not preserved — they now live in AVALANCHE_CENTERS)

Future enhancements / Questions

  • I think we should start redirecting /admin routes on subdomains/custom domains to the root domain, since we already direct users use the root domain in production

@github-actions
Copy link

Preview deployment: https://revert-926-revert-1x7x0.preview.avy-fx.org

* Switch to dynamicParams=true so centers not pre-built at build time can
be served on-demand

* Replace invariant crashes with notFound() calls
for graceful handling when DB data is missing.

* Resolve merge conflicts with main

* Revert test change

* Revert missing platform or metadata to correctly 500

* Add generic notFound page at app level without tenant branding

* return 404 if no tenant matches a subdomain

* Rewrite unknown subdomains to render styled 404 instead of plain text

* Add title to blank metadata object

* using getURL for find your local avalanche center link to always navigate to root domain even on invalid subdomains or custom domains

* removing [...segmentsNotFound] in favor of global level not-found file (frontend) route group is just for folder organization so (frontend)/not-found is at top level

* adding same valid tenant checks and metadata fetch error handling to page.tsx since it's called in parallel with layout.tsx

* matching dynamicParams settings in layout.tsx and page.tsx -- both set to true for proper 404 handling

* refactoring the unrecognized subdomain logic slightly with a logCompletion string change for clarity + adding similar logic for matching custom domain for center not configured for production

---------

Co-authored-by: Kellen Busby <kellenbusby@gmail.com>
@github-actions
Copy link

github-actions bot commented Mar 7, 2026

Migration Safety Check

Found 2 potential issues:

20260303_233752_remove_custom_domain_from_tenants.ts

Warning (line 5): DROP keyword detected - review for data loss

await db.run(sql`ALTER TABLE \`tenants\` DROP COLUMN \`custom_domain\`;`)

Warning (line 5): ALTER keyword detected - review for data loss

await db.run(sql`ALTER TABLE \`tenants\` DROP COLUMN \`custom_domain\`;`)

Review these patterns and add backup/restore logic if needed. See docs/migration-safety.md for guidance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants