Skip to content

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:

  1. Remove the old @dfinity/auth-client package from your project:

    Terminal window
    npm remove @dfinity/auth-client
  2. Install the new @icp-sdk/auth package:

    Terminal window
    npm install @icp-sdk/auth
  3. Replace the old imports with the new ones:

    import { AuthClient } from '@dfinity/auth-client';
    import { AuthClient } from '@icp-sdk/auth/client';
  4. 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', () => ({
    ...
    }));

If you are installing with pnpm, you might need to install the peer dependencies of @icp-sdk/auth manually:

Terminal window
pnpm add @icp-sdk/core

Tree-shaking is supported, so you can import only the submodules you need and your bundler will automatically remove the unused code.

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.

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: