From a44b8538fa1f6e48753779c8c95adb44c8c4d182 Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Tue, 22 Feb 2022 21:22:05 -0800 Subject: [PATCH] renew default api class after authentication --- .../src/lib/vega-wallet/connectors.ts | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/libs/react-helpers/src/lib/vega-wallet/connectors.ts b/libs/react-helpers/src/lib/vega-wallet/connectors.ts index 0785b0547..38946e073 100644 --- a/libs/react-helpers/src/lib/vega-wallet/connectors.ts +++ b/libs/react-helpers/src/lib/vega-wallet/connectors.ts @@ -27,6 +27,16 @@ export class RestConnector implements VegaConnector { async authenticate(params: { wallet: string; passphrase: string }) { try { const tokenRes = await this.service.authTokenPost(params); + + // Renew DefaultApi now we have the token + this.service = new DefaultApi( + createConfiguration({ + authMethods: { + bearer: `Bearer ${tokenRes.token}`, + }, + }) + ); + LocalStorage.setItem('vega_wallet_token', tokenRes.token); return true; } catch (err) { @@ -36,28 +46,12 @@ export class RestConnector implements VegaConnector { } async connect() { - const res = await this.service.keysGet( - // Needs token passed in in case its the users first session and there was no - // token stored - createConfiguration({ - authMethods: { - bearer: `Bearer ${LocalStorage.getItem('vega_wallet_token')}`, - }, - }) - ); + const res = await this.service.keysGet(); return res.keys; } async disconnect() { - await this.service.authTokenDelete( - // Needs token passed in in case its the users first session and there was no - // token stored - createConfiguration({ - authMethods: { - bearer: `Bearer ${LocalStorage.getItem('vega_wallet_token')}`, - }, - }) - ); + await this.service.authTokenDelete(); LocalStorage.removeItem('vega_wallet_token'); } }