diff --git a/src/soapbox/reducers/instance.ts b/src/soapbox/reducers/instance.ts index f13b1ebaf..87a264399 100644 --- a/src/soapbox/reducers/instance.ts +++ b/src/soapbox/reducers/instance.ts @@ -64,19 +64,19 @@ const handleAuthFetch = (state: typeof initialState) => { }; }; -const getHost = (instance: { uri: string }) => { +const getHost = (instance: { uri: string | undefined, domain: string }) => { try { - return new URL(instance.uri).host; + return new URL(instance.uri ?? `https://${instance.domain}`).host; } catch { try { - return new URL(`https://${instance.uri}`).host; + return new URL(`https://${instance.uri ?? instance.domain}`).host; } catch { return null; } } }; -const persistInstance = (instance: { uri: string }) => { +const persistInstance = (instance: { uri: string | undefined, domain: string }) => { const host = getHost(instance); if (host) { diff --git a/src/soapbox/schemas/instance.ts b/src/soapbox/schemas/instance.ts index c62c86370..5a6890d82 100644 --- a/src/soapbox/schemas/instance.ts +++ b/src/soapbox/schemas/instance.ts @@ -128,6 +128,7 @@ const naiveInstanceSchema = coerceObject({ thumbnail: z.string().catch(''), title: z.string().catch(''), urls: urlsSchema, + uri: z.string().url().catch(''), usage: usageSchema, version: z.string().catch(''), }); @@ -192,6 +193,7 @@ const instanceSchema = z.preprocess((data: any) => { email: email, }, description: short_description || description, + domain: instance.uri.split('://')[1], pleroma: { ...pleroma, metadata: {