Skip to content

Commit f00fd2d

Browse files
committedApr 18, 2024·
fix(clerk-js): Support legacy redirectUrl prop
1 parent da9c31f commit f00fd2d

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed
 

‎.changeset/silent-rocks-do.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/types': patch
4+
---
5+
6+
Support legacy redirectUrl prop on SignIn and SignUp

‎packages/clerk-js/src/utils/__tests__/redirectUrls.test.ts

+33
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,39 @@ describe('redirectUrls', () => {
101101
expect(redirectUrls.getAfterSignUpUrl()).toBe(`${mockWindowLocation.href}sign-up-fallback-redirect-url`);
102102
});
103103

104+
// TODO: v6 - remove this test
105+
it('falls back to legacy redirect prop if no new props are found', () => {
106+
const redirectUrls = new RedirectUrls(
107+
{
108+
signUpFallbackRedirectUrl: 'sign-up-fallback-redirect-url',
109+
},
110+
{
111+
redirectUrl: 'redirect-url',
112+
},
113+
);
114+
115+
expect(redirectUrls.getAfterSignInUrl()).toBe(`${mockWindowLocation.href}redirect-url`);
116+
expect(redirectUrls.getAfterSignUpUrl()).toBe(`${mockWindowLocation.href}sign-up-fallback-redirect-url`);
117+
});
118+
119+
// TODO: v6 - remove this test
120+
it('falls back to legacy redirect prop if no new props are found', () => {
121+
const redirectUrls = new RedirectUrls(
122+
{
123+
signUpForceRedirectUrl: 'sign-up-fallback-redirect-url',
124+
},
125+
{
126+
redirectUrl: 'redirect-url',
127+
},
128+
{
129+
redirect_url: 'redirect-url-params',
130+
},
131+
);
132+
133+
expect(redirectUrls.getAfterSignInUrl()).toBe(`${mockWindowLocation.href}redirect-url-params`);
134+
expect(redirectUrls.getAfterSignUpUrl()).toBe(`${mockWindowLocation.href}sign-up-fallback-redirect-url`);
135+
});
136+
104137
it('prioritizes force urls among other urls in the same group', () => {
105138
const redirectUrls = new RedirectUrls({
106139
signInForceRedirectUrl: 'sign-in-force-redirect-url',

‎packages/clerk-js/src/utils/redirectUrls.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class RedirectUrls {
1414
'signUpFallbackRedirectUrl',
1515
'afterSignInUrl',
1616
'afterSignUpUrl',
17+
'redirectUrl',
1718
];
1819

1920
private static preserved = ['redirectUrl'];
@@ -84,7 +85,12 @@ export class RedirectUrls {
8485

8586
// TODO: v6
8687
// Remove the compatibility layer for afterSignInUrl and afterSignUpUrl
87-
result ||= this.fromSearchParams[legacyPropKey] || this.fromProps[legacyPropKey] || this.fromOptions[legacyPropKey];
88+
result ||=
89+
this.fromSearchParams[legacyPropKey] ||
90+
this.fromSearchParams.redirectUrl ||
91+
this.fromProps[legacyPropKey] ||
92+
this.fromProps.redirectUrl ||
93+
this.fromOptions[legacyPropKey];
8894

8995
return result || '/';
9096
}

‎packages/types/src/redirects.ts

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export type LegacyRedirectProps = {
2121
* Use `fallbackRedirectUrl` or `forceRedirectUrl` instead.
2222
*/
2323
afterSignUpUrl?: string | null;
24+
/**
25+
* @deprecated This is deprecated and will be removed in a future release.
26+
* Use `fallbackRedirectUrl` or `forceRedirectUrl` instead.
27+
*/
28+
redirectUrl?: string | null;
2429
};
2530

2631
/**

0 commit comments

Comments
 (0)
Please sign in to comment.