History

refactor(shared): remove unused Clerk hostname predicate (#10008)

Julius Marminge committed 2 months ago

Commit cb58dfd1 parent 6270a6f2 files · +0 −22Browse files

Unified · Split

2 files
  1. packages/shared/src/relayAuth.test.ts +0 −11
  2. packages/shared/src/relayAuth.ts +0 −11
packages/shared/src/relayAuth.test.ts+0−11
@@ -5,7 +5,6 @@ import { · 4 unmodified lines
5 ClerkPublishableKeyFrontendApiError,5 ClerkPublishableKeyFrontendApiError,
6 clerkFrontendApiHostnameFromPublishableKey,6 clerkFrontendApiHostnameFromPublishableKey,
7 clerkFrontendApiUrlFromPublishableKey,7 clerkFrontendApiUrlFromPublishableKey,
8 isAllowedClerkFrontendApiHostname,
9} from "./relayAuth.ts";8} from "./relayAuth.ts";
10 9
11const clerkPublishableKey = (hostname: string): string => `pk_test_${btoa(`${hostname}$`)}`;10const clerkPublishableKey = (hostname: string): string => `pk_test_${btoa(`${hostname}$`)}`;
@@ -75,14 +74,4 @@ describe("Clerk relay auth", () => { · 63 unmodified lines
75 });74 });
76 expect((error as ClerkPublishableKeyFrontendApiError).cause).toBeInstanceOf(Error);75 expect((error as ClerkPublishableKeyFrontendApiError).cause).toBeInstanceOf(Error);
77 });76 });
78
79 it("allows standard Clerk hosts and an exact configured custom hostname", () => {
80 expect(isAllowedClerkFrontendApiHostname("example.clerk.accounts.dev", null)).toBe(true);
81 expect(isAllowedClerkFrontendApiHostname("example.clerk.accounts.com", null)).toBe(true);
82 expect(isAllowedClerkFrontendApiHostname("clerk.t3.codes", "clerk.t3.codes")).toBe(true);
83 expect(isAllowedClerkFrontendApiHostname("attacker.example", "clerk.t3.codes")).toBe(false);
84 expect(isAllowedClerkFrontendApiHostname("nested.clerk.t3.codes", "clerk.t3.codes")).toBe(
85 false,
86 );
87 });
88});77});
packages/shared/src/relayAuth.ts+0−11
@@ -81,17 +81,6 @@ export function clerkFrontendApiHostnameFromPublishableKey(publishableKey: strin · 80 unmodified lines
81 return parseClerkFrontendApi(publishableKey).hostname;81 return parseClerkFrontendApi(publishableKey).hostname;
82}82}
83 83
84export function isAllowedClerkFrontendApiHostname(
85 hostname: string,
86 configuredHostname: string | null,
87): boolean {
88 return (
89 hostname.endsWith(".clerk.accounts.dev") ||
90 hostname.endsWith(".clerk.accounts.com") ||
91 hostname === configuredHostname
92 );
93}
94
95export function relayClerkTokenOptions(template: string) {84export function relayClerkTokenOptions(template: string) {
96 return {85 return {
97 template,86 template,