renew default api class after authentication
This commit is contained in:
parent
59d0beebe2
commit
a44b8538fa
@ -27,6 +27,16 @@ export class RestConnector implements VegaConnector {
|
|||||||
async authenticate(params: { wallet: string; passphrase: string }) {
|
async authenticate(params: { wallet: string; passphrase: string }) {
|
||||||
try {
|
try {
|
||||||
const tokenRes = await this.service.authTokenPost(params);
|
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);
|
LocalStorage.setItem('vega_wallet_token', tokenRes.token);
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -36,28 +46,12 @@ export class RestConnector implements VegaConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async connect() {
|
async connect() {
|
||||||
const res = await this.service.keysGet(
|
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')}`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
return res.keys;
|
return res.keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
async disconnect() {
|
async disconnect() {
|
||||||
await this.service.authTokenDelete(
|
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')}`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
LocalStorage.removeItem('vega_wallet_token');
|
LocalStorage.removeItem('vega_wallet_token');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user