|
1 | 1 | # @dfinity/use-auth-client |
2 | 2 |
|
3 | | -> **⚠️ DEPRECATED**: This package is deprecated since v3.2.3. Please use one of the following alternatives: |
| 3 | +> [!CAUTION] |
| 4 | +> This package is deprecated since v3.2.3. Please use one of the following alternatives: |
4 | 5 | > - [`ic-use-internet-identity`](https://www.npmjs.com/package/ic-use-internet-identity) |
5 | 6 | > - [`@ic-reactor/react`](https://www.npmjs.com/package/@ic-reactor/react) |
6 | | -
|
7 | | -`@dfinity/use-auth-client`! This is a package for Internet Computer React developers, making it easier to integrate the auth-client with your React application. |
8 | | - |
9 | | -You can use it to manage your identity for you, or you can pass it an `idlFactory` and `canisterId` and it will construct and manage your entire `Actor` for you. |
10 | | - |
11 | | -Do you want to know more about developing on the Internet Computer? Visit the [Developer Docs](https://internetcomputer.org/docs/home). |
12 | | - |
13 | | -Additional API Documentation can be found [here](https://js.icp.build/core/v3.2/libs/use-auth-client/api). |
14 | | - |
15 | | ---- |
16 | | - |
17 | | -## Installation |
18 | | - |
19 | | -To install, use: |
20 | | - |
21 | | -```shell |
22 | | -npm install @dfinity/use-auth-client |
23 | | -``` |
24 | | - |
25 | | -and you can import and set it up like so: |
26 | | - |
27 | | -```ts |
28 | | -import {useAuthClient} from '@dfinity/use-auth-client'; |
29 | | - |
30 | | -...ts |
31 | | -const App = () => { |
32 | | - const identityProvider = |
33 | | - // eslint-disable-next-line no-undef |
34 | | - process.env.DFX_NETWORK === 'local' |
35 | | - ? // eslint-disable-next-line no-undef |
36 | | - `http://${process.env.CANISTER_ID_INTERNET_IDENTITY}.localhost:4943` |
37 | | - : 'https://identity.internetcomputer.org'; |
38 | | - |
39 | | - const { isAuthenticated, login, logout, actor } = useAuthClient({ |
40 | | - loginOptions: { |
41 | | - identityProvider, |
42 | | - }, |
43 | | - actorOptions: { |
44 | | - canisterId, |
45 | | - idlFactory, |
46 | | - }, |
47 | | - }); |
48 | | - ... |
49 | | -} |
50 | | -``` |
51 | | - |
52 | | -## Multiple Actors |
53 | | - |
54 | | -If you have multiple actors, you can pass a record of `actorOptions` to the `useAuthClient` hook. The keys of the record will be the names of the actors, and the values will be the `actorOptions` for that actor. It will look something like this: |
55 | | - |
56 | | -```ts |
57 | | -const { isAuthenticated, login, logout, actors } = useAuthClient({ |
58 | | - actors: { |
59 | | - actor1: { |
60 | | - canisterId: canisterId1, |
61 | | - idlFactory: idlFactory1, |
62 | | - }, |
63 | | - actor2: { |
64 | | - canisterId: canisterId2, |
65 | | - idlFactory: idlFactory2, |
66 | | - }, |
67 | | - }, |
68 | | -}); |
69 | | - |
70 | | -const { actor1, actor2 } = actors; |
71 | | -``` |
72 | | - |
73 | | -There is a live demo at https://5ibdo-haaaa-aaaab-qajia-cai.icp0.io/. |
0 commit comments