diff --git a/src/screens/Signup/__tests__/handleDomains.test.ts b/src/screens/Signup/__tests__/handleDomains.test.ts index d75f670e1..917b90ed6 100644 --- a/src/screens/Signup/__tests__/handleDomains.test.ts +++ b/src/screens/Signup/__tests__/handleDomains.test.ts @@ -42,7 +42,23 @@ describe('filterUserDomains', () => { ).toEqual(['.medsky.network']) }) - it('returns nothing when no advertised domain matches the community', () => { - expect(filterUserDomains(['.blacksky.app'], ['.latinsky.app'])).toEqual([]) + it('falls back to the advertised domains when nothing intersects', () => { + expect(filterUserDomains(['.blacksky.app'], ['.latinsky.app'])).toEqual([ + '.blacksky.app', + ]) + }) + + it('never returns an empty list while the PDS advertises a domain', () => { + // Reachable today: picking a community and then switching the hosting + // provider leaves the community slug and the PDS pointing at different + // servers, so the two lists can disagree entirely. + const cases: [string[], string[]][] = [ + [['.bsky.social'], ['.latinsky.app', '.afrolatinsky.app']], + [['.medsky.network'], ['.blacksky.app']], + ] + + for (const [domains, allowed] of cases) { + expect(filterUserDomains(domains, allowed)).toEqual(domains) + } }) }) diff --git a/src/screens/Signup/handleDomains.ts b/src/screens/Signup/handleDomains.ts index cb6e1e88f..a9fadfe6c 100644 --- a/src/screens/Signup/handleDomains.ts +++ b/src/screens/Signup/handleDomains.ts @@ -2,10 +2,16 @@ * Narrow the domains a PDS advertises down to the ones the selected community * publishes. * - * An empty or missing `allowed` means "no community restriction known" — the - * community's config hasn't loaded or couldn't be fetched — so every advertised - * domain stays selectable. Signup continuing with an extra domain on offer - * beats blocking it on a brand-service failure. + * Falls back to every advertised domain in two cases: + * + * - `allowed` is empty or missing — the community's config hasn't loaded or + * couldn't be fetched, so there is no restriction to apply. + * - Nothing intersects — the community and the PDS disagree, which happens when + * the hosting provider is switched after a community is picked (the two are + * tracked in separate state). The PDS is the authority on what it accepts. + * + * Either way the PDS's own list wins over an empty handle step: an extra domain + * on offer is cheaper to correct than a signup the user has to restart. */ export function filterUserDomains( domains: string[], @@ -13,5 +19,7 @@ export function filterUserDomains( ): string[] { if (!allowed || allowed.length === 0) return domains - return domains.filter(domain => allowed.includes(domain)) + const filtered = domains.filter(domain => allowed.includes(domain)) + + return filtered.length > 0 ? filtered : domains }