MCPcopy Create free account
hub / github.com/dfinity/cancan / AuthClientWrapper

Class AuthClientWrapper

src/utils/authClient.ts:14–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12 * some of the methods in promises
13 */
14class AuthClientWrapper {
15 public authClient?: AuthClient;
16 public ready = false;
17 constructor() {
18 return this;
19 }
20
21 // Create a new auth client and update it's ready state
22 async create() {
23 this.authClient = await AuthClient.create();
24 await this.authClient?.isAuthenticated();
25 this.ready = true;
26 }
27
28 async login(): Promise<Identity | undefined> {
29 return new Promise(async (resolve) => {
30 await this.authClient?.login({
31 identityProvider: IDENTITY_URL,
32 onSuccess: async () => {
33 resolve(this.authClient?.getIdentity());
34 },
35 });
36 });
37 }
38
39 async logout() {
40 return this.authClient?.logout({ returnTo: '/' });
41 }
42
43 async getIdentity() {
44 return this.authClient?.getIdentity();
45 }
46
47 async isAuthenticated() {
48 return this.authClient?.isAuthenticated();
49 }
50}
51
52export const authClient = new AuthClientWrapper();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected