Skip to content

Commit d005e2d

Browse files
committed
Move buildRedirectUrl to utils to avoid import cycle issue
1 parent 2b13e93 commit d005e2d

File tree

8 files changed

+68
-64
lines changed

8 files changed

+68
-64
lines changed

packages/clerk-js/bundlewatch.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"files": [
33
{ "path": "./dist/clerk.js", "maxSize": "625KB" },
4-
{ "path": "./dist/clerk.browser.js", "maxSize": "75KB" },
4+
{ "path": "./dist/clerk.browser.js", "maxSize": "78KB" },
55
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "117KB" },
66
{ "path": "./dist/clerk.headless*.js", "maxSize": "61KB" },
77
{ "path": "./dist/ui-common*.js", "maxSize": "113KB" },

packages/clerk-js/src/core/clerk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,7 @@ export class Clerk implements ClerkInterface {
19931993
}
19941994

19951995
if (this.session?.currentTask) {
1996-
return this.navigate(params.taskUrl ?? this.buildTasksUrl());
1996+
return navigate(params.taskUrl ?? this.buildTasksUrl());
19971997
}
19981998

19991999
return navigateToSignIn();

packages/clerk-js/src/core/sessionTasks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { logger } from '@clerk/shared/logger';
22
import type { ClerkOptions, SessionTask, SetActiveParams } from '@clerk/types';
33

4-
import { buildRedirectUrl } from '@/ui/common';
54
import { buildURL } from '@/utils';
5+
import { buildRedirectUrl } from '@/utils/redirects';
66

77
/**
88
* @internal
Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { buildURL } from '../../utils/url';
2-
import type { SignInContextType, SignUpContextType, UserProfileContextType } from './../contexts';
1+
import { buildRedirectUrl } from '@/utils/redirects';
2+
3+
import type { SignInContextType, SignUpContextType, UserProfileContextType } from '../contexts';
34

45
export const SSO_CALLBACK_PATH_ROUTE = '/sso-callback';
56
export const MAGIC_LINK_VERIFY_PATH_ROUTE = '/verify';
@@ -44,58 +45,3 @@ export function buildSSOCallbackURL(
4445
endpoint: SSO_CALLBACK_PATH_ROUTE,
4546
});
4647
}
47-
48-
type AuthQueryString = string | null | undefined;
49-
50-
type BuildRedirectUrlParams = {
51-
routing: string | undefined;
52-
authQueryString: AuthQueryString;
53-
baseUrl: string;
54-
path: string | undefined;
55-
endpoint: string;
56-
};
57-
58-
export const buildRedirectUrl = ({
59-
routing,
60-
authQueryString,
61-
baseUrl,
62-
path,
63-
endpoint,
64-
}: BuildRedirectUrlParams): string => {
65-
// If a routing strategy is not provided, default to hash routing
66-
// All routing strategies know how to convert a hash-based url to their own format
67-
// Example: navigating from a hash-based to a path-based component,
68-
// the path-based component can parse and fix the URL automatically
69-
// /#/sso-callback?code=123 -> /sso-callback?code=123
70-
if (!routing || routing === 'hash') {
71-
return buildHashBasedUrl(authQueryString, endpoint);
72-
}
73-
74-
if (routing === 'path') {
75-
return buildPathBasedUrl(path || '', authQueryString, endpoint);
76-
}
77-
78-
return buildVirtualBasedUrl(baseUrl || '', authQueryString, endpoint);
79-
};
80-
81-
const buildHashBasedUrl = (authQueryString: AuthQueryString, endpoint: string): string => {
82-
// Strip hash to get the URL where we're mounted
83-
const hash = endpoint + (authQueryString ? `?${authQueryString}` : '');
84-
return buildURL({ hash }, { stringify: true });
85-
};
86-
87-
const buildPathBasedUrl = (path: string, authQueryString: AuthQueryString, endpoint: string): string => {
88-
const searchArg = authQueryString ? { search: '?' + authQueryString } : {};
89-
return buildURL(
90-
{
91-
pathname: path + endpoint,
92-
...searchArg,
93-
},
94-
{ stringify: true },
95-
);
96-
};
97-
98-
const buildVirtualBasedUrl = (base: string, authQueryString: AuthQueryString, endpoint: string): string => {
99-
const hash = endpoint + (authQueryString ? `?${authQueryString}` : '');
100-
return buildURL({ base, hash }, { stringify: true });
101-
};

packages/clerk-js/src/ui/contexts/components/SignIn.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import type { SessionResource } from '@clerk/types';
44
import { createContext, useContext, useMemo } from 'react';
55

66
import { buildTaskRedirectUrl, INTERNAL_SESSION_TASK_ROUTE_BY_KEY } from '@/core/sessionTasks';
7+
import { MAGIC_LINK_VERIFY_PATH_ROUTE, SSO_CALLBACK_PATH_ROUTE } from '@/ui/common';
78

89
import { SIGN_IN_INITIAL_VALUE_KEYS } from '../../../core/constants';
910
import { buildURL } from '../../../utils';
11+
import { buildRedirectUrl } from '../../../utils/redirects';
1012
import { RedirectUrls } from '../../../utils/redirectUrls';
11-
import { buildRedirectUrl, MAGIC_LINK_VERIFY_PATH_ROUTE, SSO_CALLBACK_PATH_ROUTE } from '../../common/redirects';
1213
import { useEnvironment, useOptions } from '../../contexts';
1314
import type { ParsedQueryString } from '../../router';
1415
import { useRouter } from '../../router';

packages/clerk-js/src/ui/contexts/components/SignUp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import type { SessionResource } from '@clerk/types';
44
import { createContext, useContext, useMemo } from 'react';
55

66
import { buildTaskRedirectUrl, INTERNAL_SESSION_TASK_ROUTE_BY_KEY } from '@/core/sessionTasks';
7+
import { MAGIC_LINK_VERIFY_PATH_ROUTE, SSO_CALLBACK_PATH_ROUTE } from '@/ui/common';
78

89
import { SIGN_UP_INITIAL_VALUE_KEYS } from '../../../core/constants';
9-
import { buildURL } from '../../../utils';
10+
import { buildRedirectUrl, buildURL } from '../../../utils';
1011
import { RedirectUrls } from '../../../utils/redirectUrls';
11-
import { buildRedirectUrl, MAGIC_LINK_VERIFY_PATH_ROUTE, SSO_CALLBACK_PATH_ROUTE } from '../../common/redirects';
1212
import { useEnvironment, useOptions } from '../../contexts';
1313
import type { ParsedQueryString } from '../../router';
1414
import { useRouter } from '../../router';

packages/clerk-js/src/utils/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export * from './beforeUnloadTracker';
21
export * from './appearance';
2+
export * from './beforeUnloadTracker';
33
export * from './commerce';
44
export * from './completeSignUpFlow';
55
export * from './componentGuards';
@@ -21,6 +21,7 @@ export * from './path';
2121
export * from './props';
2222
export * from './queryStateParams';
2323
export * from './querystring';
24+
export * from './redirects';
2425
export * from './runtime';
2526
export * from './url';
2627
export * from './web3';
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { buildURL } from './url';
2+
3+
type AuthQueryString = string | null | undefined;
4+
5+
type BuildRedirectUrlParams = {
6+
routing: string | undefined;
7+
authQueryString: AuthQueryString;
8+
baseUrl: string;
9+
path: string | undefined;
10+
endpoint: string;
11+
};
12+
13+
export const buildRedirectUrl = ({
14+
routing,
15+
authQueryString,
16+
baseUrl,
17+
path,
18+
endpoint,
19+
}: BuildRedirectUrlParams): string => {
20+
// If a routing strategy is not provided, default to hash routing
21+
// All routing strategies know how to convert a hash-based url to their own format
22+
// Example: navigating from a hash-based to a path-based component,
23+
// the path-based component can parse and fix the URL automatically
24+
// /#/sso-callback?code=123 -> /sso-callback?code=123
25+
if (!routing || routing === 'hash') {
26+
return buildHashBasedUrl(authQueryString, endpoint);
27+
}
28+
29+
if (routing === 'path') {
30+
return buildPathBasedUrl(path || '', authQueryString, endpoint);
31+
}
32+
33+
return buildVirtualBasedUrl(baseUrl || '', authQueryString, endpoint);
34+
};
35+
36+
const buildHashBasedUrl = (authQueryString: AuthQueryString, endpoint: string): string => {
37+
// Strip hash to get the URL where we're mounted
38+
const hash = endpoint + (authQueryString ? `?${authQueryString}` : '');
39+
return buildURL({ hash }, { stringify: true });
40+
};
41+
42+
const buildPathBasedUrl = (path: string, authQueryString: AuthQueryString, endpoint: string): string => {
43+
const searchArg = authQueryString ? { search: '?' + authQueryString } : {};
44+
return buildURL(
45+
{
46+
pathname: path + endpoint,
47+
...searchArg,
48+
},
49+
{ stringify: true },
50+
);
51+
};
52+
53+
const buildVirtualBasedUrl = (base: string, authQueryString: AuthQueryString, endpoint: string): string => {
54+
const hash = endpoint + (authQueryString ? `?${authQueryString}` : '');
55+
return buildURL({ base, hash }, { stringify: true });
56+
};

0 commit comments

Comments
 (0)