handle session expired
This commit is contained in:
parent
195fff27ab
commit
1e6900d147
@ -7,7 +7,7 @@ import {
|
|||||||
import { LocalStorage } from '@vegaprotocol/storage';
|
import { LocalStorage } from '@vegaprotocol/storage';
|
||||||
|
|
||||||
export interface VegaConnector {
|
export interface VegaConnector {
|
||||||
connect(): Promise<VegaKey[]>;
|
connect(): Promise<VegaKey[] | null>;
|
||||||
disconnect(): Promise<void>;
|
disconnect(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,13 +46,26 @@ export class RestConnector implements VegaConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async connect() {
|
async connect() {
|
||||||
const res = await this.service.keysGet();
|
try {
|
||||||
return res.keys;
|
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() {
|
async disconnect() {
|
||||||
await this.service.authTokenDelete();
|
try {
|
||||||
LocalStorage.removeItem('vega_wallet_token');
|
await this.service.authTokenDelete();
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
} finally {
|
||||||
|
// Always clear the tokens
|
||||||
|
LocalStorage.removeItem('vega_wallet_token');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,12 @@ export function RestConnectorForm({
|
|||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useForm<FormFields>();
|
} = useForm<FormFields>({
|
||||||
|
defaultValues: {
|
||||||
|
wallet: 'test6',
|
||||||
|
passphrase: '123',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
async function onSubmit(fields: FormFields) {
|
async function onSubmit(fields: FormFields) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user