Core 2 is included in the Javascript SDK starting with version 5. This new version ships with an improved design and UX for its built-in components, no "flash of white page" when authenticating, and a variety of smaller DX improvements and housekeeping items. Each of the potentially breaking changes are detailed in this guide, below.
By the end of this guide, you'll have successfully upgraded your JS project to use @clerk/clerk-js v5. You'll learn how to update your dependencies, resolve breaking changes, and find deprecations. Step-by-step instructions will lead you through the process.
Preparing to upgrade
Before uprading, it's highly recommended that you update your Clerk SDKs to the latest Core 1 version (npm i @clerk/clerk-js@4). Some changes required for Core 2 SDKs can be applied incrementally to the v5 release, which should contribute to a smoother upgrading experience. After updating, look out for deprecation messages in your terminal and browser console. By resolving these deprecations you'll be able to skip many breaking changes from Core 2.
Note that Core 2 is currently in beta, while we field feedback and ensure stability. Deploying beta versions to production is not recommended and should be done at your own risk.
Additionally, some of the minumum version requirements for some base dependencies have been updated such that versions that are no longer supported or are at end-of-life are no longer guaranteed to work correctly with Clerk.
Updating to Core 2 Beta
Whenever you feel ready, go ahead and install the latest beta version of any Clerk SDKs you are using. Make sure that you are prepared to patch some breaking changes before your app will work properly, however. The commands below demonstrate how to install the latest beta.
terminal
npminstall@clerk/clerk-js@beta
terminal
yarnadd@clerk/clerk-js@beta
terminal
pnpmadd@clerk/clerk-js@beta
CLI upgrade helper
Clerk now provides a @clerk/upgrade CLI tool that you can use to ease the upgrade process. The tool will scan your codebase and produce a list of changes you'll need to apply to your project. It should catch the vast majority of the changes needed for a successful upgrade to any SDK including Core 2. This can save you a lot of time reading through changes that don't apply to your project.
To run the CLI tool, navigate to your project and run it in the terminal:
terminal
npx@clerk/upgrade
terminal
yarndlx@clerk/upgrade
terminal
pnpmdlx@clerk/upgrade
If you are having trouble with npx, it's also possible to install directly with npm i @clerk/upgrade -g, and can then be run with the clerk-upgrade command.
Breaking Changes
Component design adjustments
The new version ships with improved design and UX across all of Clerk's UI components. If you have used the appearance prop or tokens for a custom theme, you will likely need to make some adjustments to ensure your styling is still looking great. If you're using the localization prop you will likely need to make adjustments to account for added or removed localization keys.
Defining redirect URLs for after sign up, in, and/or out via the Clerk dashboard has been removed in Core 2. In your Clerk dashboard, under "paths", there is a section called "Component paths", where URLs could be defined that had a deprecation warning. In Core 2, this functionality has been removed, and specifying redirect paths via the dashboard will no longer work. If you need to pass a redirect URL for after sign in/up/out, there are a few different ways this can be done(opens in a new tab), from environment variables to middleware to supplying them directly to the relevant components.
As part of this change, the default URL for each of these props has been set to /, so if you are passing / explicitly to any one of the above props, that line is no longer necessary and can be removed.
In the previous version of Clerk's SDKs, if you decode the session token that Clerk returns from the server, you'll currently find an orgs claim on it. It lists all the orgs associated with the given user. Now, Clerk returns the org_id, org_slug, and org_role of the active organization.
The orgs claim was part of the JwtPayload. Here are a few examples of where the JwtPayload could be found.
If you would like to have your JWT return all of the user's organizations, you can create a custom JWT template in your dashboard. Add { "orgs": "user.organizations" } to it.
Path routing is now the default
On components like <SignIn /> you can define the props routing and path. routing can be set to 'hash' | 'path' | 'virtual' and describes the routing strategy that should be used. path defines where the component is mounted when routing="path" is used.
In the latest version, the defaultrouting strategy has become 'path'. Unless you change the routing prop, you'll need to define the path prop. The affected components are:
<SignIn />
<SignUp />
<UserProfile />
<CreateOrganization />
<OrganizationProfile />
Here's how you'd use the components going forward:
There are a number of Clerk primitives that contain images, and previously they each had different property names, like avatarUrl, logoUrl, profileImageUrl, etc. In order to promote consistency and make it simpler for developers to know where to find associated images, all image properties are now named imageUrl. See the list below for all affected classes:
The profileImageUrl property of any OrganizationMembershipPublicUserData object has been changed to imageUrl.
Changes to pagination arguments for some functions
There were some changes made to pagination-related arguments passed into functions, in order to make it more clear how to control paginated results. See each function impacted by these changes below:
There have been a couple changes to the pagination arguments that can be passed into this function - limit has been renamed to pageSize, and offset has been renamed to initialPage. This will help to make it more clear and simple to reason about pagination control. Example of how changes might look below:
There have been a couple changes to the pagination arguments that can be passed into this function - limit has been renamed to pageSize, and offset has been renamed to initialPage. This will help to make it more clear and simple to reason about pagination control. Example of how changes might look below:
There have been a couple changes to the pagination arguments that can be passed into this function - limit has been renamed to pageSize, and offset has been renamed to initialPage. This will help to make it more clear and simple to reason about pagination control. Example of how changes might look below:
There have been a couple changes to the pagination arguments that can be passed into this function - limit has been renamed to pageSize, and offset has been renamed to initialPage. This will help to make it more clear and simple to reason about pagination control. Example of how changes might look below:
There have been a couple changes to the pagination arguments that can be passed into this function - limit has been renamed to pageSize, and offset has been renamed to initialPage. This will help to make it more clear and simple to reason about pagination control. Example of how changes might look below:
There have been a couple changes to the pagination arguments that can be passed into this function - limit has been renamed to pageSize, and offset has been renamed to initialPage. This will help to make it more clear and simple to reason about pagination control. Example of how changes might look below:
There have been a couple changes to the pagination arguments that can be passed into this function - limit has been renamed to pageSize, and offset has been renamed to initialPage. This will help to make it more clear and simple to reason about pagination control. Example of how changes might look below:
There have been a couple changes to the pagination arguments that can be passed into this function - limit has been renamed to pageSize, and offset has been renamed to initialPage. This will help to make it more clear and simple to reason about pagination control. Example of how changes might look below:
There have been changes to return signatures for some functions. Since Clerk's API responses are paginated, the totalCount property is helpful in determining the total number of items in the response easily. This change also aligns the response shape with what is returned from the Clerk backend API. Each impacted function is listed below, along with code examples:
The response payload of Users.getOrganizationInvitationList was changed as part of the v5 release. Rather than directly returning data, the return signature is now { data, totalCount }. Since backend API responses are paginated, the totalCount property is helpful in determining the total number of items in the response easily, and this change in the backend SDK aligns the response shape with what the backend API returns directly.
Here's an example of how the response shape would change with this modification:
The return type for this function was previously [Items] but has now been updated to { data: [Items], totalCount: number }. Since Clerk's API responses are paginated, the totalCount property is helpful in determining the total number of items in the response easily. A before/after code example can be seen below:
The return type for this function was previously [Items] but has now been updated to { data: [Items], totalCount: number }. Since Clerk's API responses are paginated, the totalCount property is helpful in determining the total number of items in the response easily. A before/after code example can be seen below:
The response payload of Users.getOrganizationList was changed as part of the v5 release. Rather than directly returning data, the return signature is now { data, totalCount }. Since backend API responses are paginated, the totalCount property is helpful in determining the total number of items in the response easily, and this change in the backend SDK aligns the response shape with what the backend API returns directly.
Here's an example of how the response shape would change with this modification:
The return type for this function was previously [Items] but has now been updated to { data: [Items], totalCount: number }. Since Clerk's API responses are paginated, the totalCount property is helpful in determining the total number of items in the response easily. A before/after code example can be seen below:
As part of this major version, a number of previously deprecated props, arugments, methods, etc. have been removed. Additionally there have been some changes to things that are only used internally, or only used very rarely. It's highly unlikely that any given app will encounter any of these items, but they are all breaking changes, so they have all been documented below.
For this section more than any other one, please use the CLI upgrade tool (npx @clerk/upgrade). Changes in this
section are very unlikely to appear in your codebase, the tool will save time looking for them.
Deprecation removals
If you are updating a user's password via the User.update method(opens in a new tab), it must be changed to User.updatePassword(opens in a new tab) instead. This method will require the current password as well as the desired new password. We made this update to improve the security of password changes. Example below:
The experimental property Clerk.experimental_canUseCaptcha has been removed. There is no replacement for this functionality currently. If this is problematic for your application, please reach out to our support team(opens in a new tab)!
The experimental property Clerk.experimental_captchaURL has been removed. There is no replacement for this functionality currently. If this is problematic for your application, please reach out to our support team(opens in a new tab)!
The experimental property Clerk.experimental_captchaSiteKey has been removed. There is no replacement for this functionality currently. If this is problematic for your application, please reach out to our support team(opens in a new tab)!
The Clerk.__unstable__invitationUpdate experimental property has been removed, and has no current replacement. If this is an issue in your codebase, please reach out to Clerk support(opens in a new tab)!
The Clerk.__unstable__membershipUpdate experimental property has been removed, and has no current replacement. If this is an issue in your codebase, please reach out to Clerk support(opens in a new tab)!
The generatedSignature param to Signup.attemptWeb3WalletVerification()(opens in a new tab) has been removed. Instead, use the signature param. Note that this param takes a string, where the generatedSignature param took a function, so both key and value will need to change.
// befores.attemptWeb3WalletVerification({generatedSignature: async () =>'signatureString',});// afters.attemptWeb3WalletVerification({ signature: 'signatureString' });// or, if you still need to fetch the signature asyncconstsignatureString=await (async () =>'signatureString');s.attemptWeb3WalletVerification({ signature: signatureString });
Other Breaking changes
setSession should be replaced with setActive. The format of the parameters has changed slightly - setActive takes an object where setSession took params directly. The setActive function also can accept an organization param that is used to set the currently active organization. The return signature did not change. Read the API documentation for more detail. This function should be expected to be returned from one of the following Clerk hooks: useSessionList, useSignUp, or useSignIn. Some migration examples:
If you are using Clerk.addListener(opens in a new tab) or OrganizationContext and utilizing either the lastOrganizationInvitation and/or lastOrganizationMember emitted events, these properties have been removed, as they were only relevant for internal use. We are not providing a way to backfill this functionality at the moment. If you are using it and this is an issue for you, please reach out to Clerk support(opens in a new tab) and we can find a way to resolve the issue!
The Clerk.redirectToHome method has been removed. If you are looking for a generic replacement for this method, you can instead use window.Clerk.redirectToAfterSignUp() or window.Clerk.redirectAfterSignIn().
To set the afterSignUpUrl or afterSignInUrl, you can:
If not using a react-based SDK, pass the values into Clerk.load as such: Clerk.load({ afterSignUpUrl: 'x', afterSignInUrl: 'y' })