From 437170c203cdf50252fc88423652ea7458e29fe6 Mon Sep 17 00:00:00 2001 From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> Date: Wed, 26 Jan 2022 10:23:18 +0600 Subject: [PATCH 1/2] Create new client when token has been changed Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> --- plugins/client-resources/src/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/client-resources/src/index.ts b/plugins/client-resources/src/index.ts index af8ba3ce07..b6f2c55217 100644 --- a/plugins/client-resources/src/index.ts +++ b/plugins/client-resources/src/index.ts @@ -27,17 +27,23 @@ export { connect } */ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export default async () => { + let _token: string | undefined = undefined let client: Client | undefined return { function: { GetClient: async (token: string, endpoint: string): Promise => { + if (token !== _token && client !== undefined) { + client.close() + client = undefined + } if (client === undefined) { client = await createClient((handler: TxHander) => { const url = new URL(`/${token}`, endpoint) console.log('connecting to', url.href) return connect(url.href, handler) }) + _token = token // Check if we had dev hook for client. const hook = getMetadata(clientPlugin.metadata.ClientHook) From c7ca07134a8a4c458fc0ee9a518e11d7dd555511 Mon Sep 17 00:00:00 2001 From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> Date: Wed, 26 Jan 2022 10:30:53 +0600 Subject: [PATCH 2/2] fixes Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> --- plugins/client-resources/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/client-resources/src/index.ts b/plugins/client-resources/src/index.ts index b6f2c55217..744f8383ae 100644 --- a/plugins/client-resources/src/index.ts +++ b/plugins/client-resources/src/index.ts @@ -27,14 +27,14 @@ export { connect } */ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export default async () => { - let _token: string | undefined = undefined + let _token: string | undefined let client: Client | undefined return { function: { GetClient: async (token: string, endpoint: string): Promise => { if (token !== _token && client !== undefined) { - client.close() + await client.close() client = undefined } if (client === undefined) {