How to get the Internet Identity ID dynamically?

Thanks for the repo. Following worked out for me with your project:

  1. remove the hard coded II canister ID in webpack.config.js
new webpack.EnvironmentPlugin({
      NODE_ENV: "development",
      ...canisterEnvVariables,
    }),
  1. use process.env.INTERNET_IDENTITY_CANISTER_ID for the auth-client
await authClient?.login({
        onSuccess: async () => {
          initActor(authClient);
          navigate("/");
        },
        // 7 days in nanoseconds
        maxTimeToLive: BigInt(7 * 24 * 60 * 60 * 1000 * 1000 * 1000),
        ...(process.env.NODE_ENV === 'development' && {identityProvider: `http://localhost:4943/?canisterId=${process.env.INTERNET_IDENTITY_CANISTER_ID}#authorize`})
      });
  1. dfx start + dfx deploy + npm run start
  2. test on the browser on http://localhost:8080/

Hope that helps.

2 Likes