handle session expired
This commit is contained in:
parent
195fff27ab
commit
1e6900d147
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user