Fix instance persistence in indexeddb
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
9b63adc23f
commit
7a8b473406
1 changed files with 6 additions and 5 deletions
|
@ -72,25 +72,26 @@ const handleAuthFetch = (state: Instance) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getHost = (instance: { uri: string }) => {
|
const getHost = (instance: { uri?: string; domain?: string }) => {
|
||||||
|
const domain = instance.uri || instance.domain as string;
|
||||||
try {
|
try {
|
||||||
return new URL(instance.uri).host;
|
return new URL(domain).host;
|
||||||
} catch {
|
} catch {
|
||||||
try {
|
try {
|
||||||
return new URL(`https://${instance.uri}`).host;
|
return new URL(`https://${domain}`).host;
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const persistInstance = (instance: { uri: string }, host: string | null = getHost(instance)) => {
|
const persistInstance = ({ instance }: { instance: { uri: string } }, host: string | null = getHost(instance)) => {
|
||||||
if (host) {
|
if (host) {
|
||||||
KVStore.setItem(`instance:${host}`, instance).catch(console.error);
|
KVStore.setItem(`instance:${host}`, instance).catch(console.error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const persistInstanceV2 = (instance: { uri: string }, host: string | null = getHost(instance)) => {
|
const persistInstanceV2 = ({ instance }: { instance: { domain: string } }, host: string | null = getHost(instance)) => {
|
||||||
if (host) {
|
if (host) {
|
||||||
KVStore.setItem(`instanceV2:${host}`, instance).catch(console.error);
|
KVStore.setItem(`instanceV2:${host}`, instance).catch(console.error);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue