Skip to content

Commit 892bc0e

Browse files
authored
feat(backend,shared): Move buildAccountsBaseUrl to shared utility (#5416)
1 parent 2080625 commit 892bc0e

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

.changeset/clever-walls-shave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/backend': patch
3+
---
4+
5+
Update `@clerk/shared` dependency to use new shared `buildAccountsBaseUrl` utility.

.changeset/spicy-radios-happen.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/shared': minor
3+
---
4+
5+
Add shared `buildAccountsBaseUrl` utility.

packages/backend/src/createRedirect.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { buildAccountsBaseUrl } from '@clerk/shared/buildAccountsBaseUrl';
2+
13
import { constants } from './constants';
24
import { errorThrower, parsePublishableKey } from './util/shared';
35

@@ -54,19 +56,6 @@ const legacyBuildUrl = (targetUrl: string, redirectUrl?: string) => {
5456
return url.toString();
5557
};
5658

57-
const buildAccountsBaseUrl = (frontendApi?: string) => {
58-
if (!frontendApi) {
59-
return '';
60-
}
61-
62-
// convert url from FAPI to accounts for Kima and legacy (prod & dev) instances
63-
const accountsBaseUrl = frontendApi
64-
// staging accounts
65-
.replace(/clerk\.accountsstage\./, 'accountsstage.')
66-
.replace(/clerk\.accounts\.|clerk\./, 'accounts.');
67-
return `https://${accountsBaseUrl}`;
68-
};
69-
7059
type RedirectAdapter<RedirectReturn> = (url: string) => RedirectReturn;
7160
type RedirectToParams = { returnBackUrl?: string | URL | null };
7261
export type RedirectFun<ReturnType> = (params?: RedirectToParams) => ReturnType;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { buildAccountsBaseUrl } from '../buildAccountsBaseUrl';
2+
3+
test.each([
4+
['', ''],
5+
[undefined, ''],
6+
['one-two-three.clerk.accountsstage.dev', 'https://one-two-three.accountsstage.dev'],
7+
['one-two-three.clerk.accounts.dev', 'https://one-two-three.accounts.dev'],
8+
['clerk.accounts.example.com', 'https://accounts.example.com'],
9+
['clerk.example.com', 'https://accounts.example.com'],
10+
])('buildAccountsBaseUrl(%s)', (frontendApi, accountsBaseUrl) => {
11+
expect(buildAccountsBaseUrl(frontendApi)).toBe(accountsBaseUrl);
12+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Builds a full origin string pointing to the Account Portal for the given frontend API.
3+
*/
4+
export function buildAccountsBaseUrl(frontendApi?: string): string {
5+
if (!frontendApi) {
6+
return '';
7+
}
8+
9+
// convert url from FAPI to accounts for Kima and legacy (prod & dev) instances
10+
const accountsBaseUrl = frontendApi
11+
// staging accounts
12+
.replace(/clerk\.accountsstage\./, 'accountsstage.')
13+
.replace(/clerk\.accounts\.|clerk\./, 'accounts.');
14+
return `https://${accountsBaseUrl}`;
15+
}

0 commit comments

Comments
 (0)