Skip to content

Commit

Permalink
fix(clerk-js): Support legacy redirectUrl prop
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosdouvlis committed Apr 18, 2024
1 parent da9c31f commit f00fd2d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/silent-rocks-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
'@clerk/types': patch
---

Support legacy redirectUrl prop on SignIn and SignUp
33 changes: 33 additions & 0 deletions packages/clerk-js/src/utils/__tests__/redirectUrls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,39 @@ describe('redirectUrls', () => {
expect(redirectUrls.getAfterSignUpUrl()).toBe(`${mockWindowLocation.href}sign-up-fallback-redirect-url`);
});

// TODO: v6 - remove this test
it('falls back to legacy redirect prop if no new props are found', () => {
const redirectUrls = new RedirectUrls(
{
signUpFallbackRedirectUrl: 'sign-up-fallback-redirect-url',
},
{
redirectUrl: 'redirect-url',
},
);

expect(redirectUrls.getAfterSignInUrl()).toBe(`${mockWindowLocation.href}redirect-url`);
expect(redirectUrls.getAfterSignUpUrl()).toBe(`${mockWindowLocation.href}sign-up-fallback-redirect-url`);
});

// TODO: v6 - remove this test
it('falls back to legacy redirect prop if no new props are found', () => {
const redirectUrls = new RedirectUrls(
{
signUpForceRedirectUrl: 'sign-up-fallback-redirect-url',
},
{
redirectUrl: 'redirect-url',
},
{
redirect_url: 'redirect-url-params',
},
);

expect(redirectUrls.getAfterSignInUrl()).toBe(`${mockWindowLocation.href}redirect-url-params`);
expect(redirectUrls.getAfterSignUpUrl()).toBe(`${mockWindowLocation.href}sign-up-fallback-redirect-url`);
});

it('prioritizes force urls among other urls in the same group', () => {
const redirectUrls = new RedirectUrls({
signInForceRedirectUrl: 'sign-in-force-redirect-url',
Expand Down
8 changes: 7 additions & 1 deletion packages/clerk-js/src/utils/redirectUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class RedirectUrls {
'signUpFallbackRedirectUrl',
'afterSignInUrl',
'afterSignUpUrl',
'redirectUrl',
];

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

// TODO: v6
// Remove the compatibility layer for afterSignInUrl and afterSignUpUrl
result ||= this.fromSearchParams[legacyPropKey] || this.fromProps[legacyPropKey] || this.fromOptions[legacyPropKey];
result ||=
this.fromSearchParams[legacyPropKey] ||
this.fromSearchParams.redirectUrl ||
this.fromProps[legacyPropKey] ||
this.fromProps.redirectUrl ||
this.fromOptions[legacyPropKey];

return result || '/';
}
Expand Down
5 changes: 5 additions & 0 deletions packages/types/src/redirects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export type LegacyRedirectProps = {
* Use `fallbackRedirectUrl` or `forceRedirectUrl` instead.
*/
afterSignUpUrl?: string | null;
/**
* @deprecated This is deprecated and will be removed in a future release.
* Use `fallbackRedirectUrl` or `forceRedirectUrl` instead.
*/
redirectUrl?: string | null;
};

/**
Expand Down

0 comments on commit f00fd2d

Please sign in to comment.