Upgrading to @icp-sdk/auth
The new @icp-sdk/auth
package is organized into modules. Currently, there is only one module: client
, which exports the elements of the old @dfinity/auth-client
package.
To upgrade to the new package, follow these steps:
-
Remove the old
@dfinity/auth-client
package from your project:Terminal window npm remove @dfinity/auth-client -
Install the new
@icp-sdk/auth
package:Terminal window npm install @icp-sdk/auth -
Replace the old imports with the new ones:
import { AuthClient } from '@dfinity/auth-client';import { AuthClient } from '@icp-sdk/auth/client'; -
If necessary, replace all the other occurrences of
@dfinity/auth-client
with@icp-sdk/auth/client
, e.g. in tests mocks:vi.mock('@dfinity/auth-client', () => ({vi.mock('@icp-sdk/auth/client', () => ({...}));
Troubleshooting
Section titled “Troubleshooting”Installing with pnpm
Section titled “Installing with pnpm”If you are installing with pnpm, you might need to install the peer dependencies of @icp-sdk/auth
manually:
pnpm add @icp-sdk/core
Tree-shaking
Section titled “Tree-shaking”Tree-shaking is supported, so you can import only the submodules you need and your bundler will automatically remove the unused code.
Workspaces
Section titled “Workspaces”If you’re using a workspace, you must do the same steps for each package in the workspace that has the @dfinity/auth-client
dependency. You may need to first uninstall the @dfinity/auth-client
package manually from all the packages in the workspace before doing the upgrading steps, to avoid version conflicts.
A similar approach can be used for monorepos.
@dfinity/use-auth-client
Section titled “@dfinity/use-auth-client”The @dfinity/use-auth-client
package is not included in @icp-sdk/auth
and has been deprecated. Please consider using other libraries instead. Recommended alternatives: