handle session expired

This commit is contained in:
Matthew Russell 2022-02-23 09:54:42 -08:00
parent 195fff27ab
commit 1e6900d147
2 changed files with 24 additions and 6 deletions

View File

@ -7,7 +7,7 @@ import {
import { LocalStorage } from '@vegaprotocol/storage';
export interface VegaConnector {
connect(): Promise<VegaKey[]>;
connect(): Promise<VegaKey[] | null>;
disconnect(): Promise<void>;
}
@ -46,14 +46,27 @@ export class RestConnector implements VegaConnector {
}
async connect() {
try {
const res = await this.service.keysGet();
return res.keys;
} catch (err) {
console.error(err);
// keysGet failed, its likely that the session has expired so remove the token from storage
LocalStorage.removeItem('vega_wallet_token');
return null;
}
}
async disconnect() {
try {
await this.service.authTokenDelete();
} catch (err) {
console.error(err);
} finally {
// Always clear the tokens
LocalStorage.removeItem('vega_wallet_token');
}
}
}
export class InjectedConnector implements VegaConnector {

View File

@ -19,7 +19,12 @@ export function RestConnectorForm({
register,
handleSubmit,
formState: { errors },
} = useForm<FormFields>();
} = useForm<FormFields>({
defaultValues: {
wallet: 'test6',
passphrase: '123',
},
});
async function onSubmit(fields: FormFields) {
try {