| 12 | * some of the methods in promises |
| 13 | */ |
| 14 | class 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 | |
| 52 | export const authClient = new AuthClientWrapper(); |
nothing calls this directly
no outgoing calls
no test coverage detected