Yerelde Subdomain/Tenant Geliştirme (8787)
Wrangler dev'de *.localhost tenant testleri, Better Auth cookie davranışı ve sık görülen 403/redirect döngüleri.
Bu sayfa, B2B company akışını lokalde test ederken en sık görülen iki problemi çözer:
- Login başarılı görünüp
/company’ye girince tekrar login’e düşme (cookie yazılmıyor) quaflow.localhost:8787/en/company→ 403 (tenant çözümlenemiyor)
1) Login: doğru host üzerinde oturum açın
Section titled “1) Login: doğru host üzerinde oturum açın”Lokal test için login’i tenant host’unda yapın:
- ✅
http://quaflow.localhost:8787/en/login - ❌
http://localhost:8787/en/login(cookie localhost’a yazılır; tenant host’u ile paylaşılmayabilir)
2) Better Auth: trusted origins + dev cookie stratejisi
Section titled “2) Better Auth: trusted origins + dev cookie stratejisi”Dosya: app/lib/auth.ts
Lokal geliştirmede:
trustedOrigins*.localhostorigin’lerini kabul etmelidircrossSubDomainCookiesher tarayıcıda.localhostiçin güvenilir değildir- Bu repo’da bu yüzden lokalde cross-subdomain cookie’ler kapalı tutulur
- Prod’da (
*.achidemy.net) cross-subdomain cookie’ler açılır
3) Wrangler 8787: Host ezme ve tenant hint cookie
Section titled “3) Wrangler 8787: Host ezme ve tenant hint cookie”Wrangler dev bazı ortamlarda Worker’a gelen isteklerde Host’u 127.0.0.1 gibi gösterir. Bu durumda server-side tenant çözümlemesi organizations.subdomain ile eşleşmez ve /company 403 verir.
Bu repo’daki çözüm:
GET /api/tenant-hint?host=<hostname>endpoint’i__tenant_subdomaincookie’si yazarapp/root.tsx*.localhostüzerinde çalışıyorsa bu endpoint’i çağırır ve cookie yazıldıktan sonra root loader’ı revalidate ederapp/lib/tenant.tsönce__tenant_subdomaincookie’sine bakar
4) Wrangler ayarı (opsiyonel)
Section titled “4) Wrangler ayarı (opsiyonel)”Dosya: wrangler.toml
Lokal geliştirmede host’u 127.0.0.1 yapmak genelde daha deterministik sonuç verir:
[dev]host = "127.0.0.1"Troubleshooting Checklist
Section titled “Troubleshooting Checklist”/api/auth/get-session200 dönüyor mu?- Browser’da
quaflow.localhostaltında cookie’ler yazılıyor mu?__tenant_subdomain- Better Auth session cookie’leri
/en/company403 ise: tenant çözümleniyor mu? (server log)