Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tidy-domains-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onkernel/managed-auth-react": patch
---

Use the public suffix list to derive the site label shown on the initial auth screen.
5 changes: 5 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/managed-auth-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"react-dom": ">=18"
},
"dependencies": {
"clsx": "^2.1.1"
"clsx": "^2.1.1",
"tldts": "7.4.15"
},
"devDependencies": {
"@types/react": "^18",
Expand Down
14 changes: 14 additions & 0 deletions packages/managed-auth-react/src/lib/profile-name.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, expect, test } from "bun:test";
import { extractPrimaryDomainLabel } from "./profile-name";

describe("extractPrimaryDomainLabel", () => {
test("uses the registrable domain for subdomains of multi-label suffixes", () => {
expect(extractPrimaryDomainLabel("login.clalit.co.il")).toBe("clalit");
expect(extractPrimaryDomainLabel("auth.example.co.uk")).toBe("example");
});

test("uses the registrable domain for regular suffixes", () => {
expect(extractPrimaryDomainLabel("login.example.com")).toBe("example");
expect(extractPrimaryDomainLabel("example.com")).toBe("example");
});
});
37 changes: 3 additions & 34 deletions packages/managed-auth-react/src/lib/profile-name.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,4 @@
const MULTI_PART_TLDS = new Set([
"co.uk",
"co.jp",
"co.kr",
"co.nz",
"co.za",
"co.in",
"co.id",
"co.th",
"com.au",
"com.br",
"com.cn",
"com.mx",
"com.tw",
"com.sg",
"com.ar",
"com.co",
"com.tr",
"org.uk",
"org.au",
"net.au",
"ac.uk",
"gov.uk",
"ne.jp",
"or.jp",
]);
import { parse } from "tldts";

export function extractDomainName(targetDomain: string): string {
return targetDomain
Expand All @@ -33,12 +8,6 @@ export function extractDomainName(targetDomain: string): string {
}

export function extractPrimaryDomainLabel(hostname: string): string {
const parts = hostname.split(".");
if (parts.length <= 1) return parts[0] || hostname;
if (parts.length === 2) return parts[0];
const lastTwo = parts.slice(-2).join(".");
const tldLength = MULTI_PART_TLDS.has(lastTwo.toLowerCase()) ? 2 : 1;
const primaryIndex = parts.length - tldLength - 1;
if (primaryIndex >= 0) return parts[primaryIndex];
return parts[0];
const domain = parse(hostname).domain;
return domain ? domain.split(".")[0] : hostname.split(".")[0] || hostname;
}
Loading