Handle failed space auth

This commit is contained in:
Jon Staab
2024-11-18 20:31:17 -08:00
parent cbc4c524c4
commit ed738f64c8
4 changed files with 97 additions and 11 deletions
+16 -8
View File
@@ -1,15 +1,17 @@
<script lang="ts">
import {onMount} from "svelte"
import {page} from "$app/stores"
import {ifLet, now} from "@welshman/lib"
import {now} from "@welshman/lib"
import {subscribe} from "@welshman/app"
import {DELETE, REACTION} from "@welshman/util"
import Page from "@lib/components/Page.svelte"
import SecondaryNav from "@lib/components/SecondaryNav.svelte"
import MenuSpace from "@app/components/MenuSpace.svelte"
import SpaceAuthError from "@app/components/SpaceAuthError.svelte"
import {pushToast} from "@app/toast"
import {pushModal} from "@app/modal"
import {setChecked} from "@app/notifications"
import {checkRelayConnection, checkRelayAuth} from "@app/commands"
import {checkRelayConnection, checkRelayAuth, checkRelayAccess} from "@app/commands"
import {decodeRelay, MEMBERSHIPS} from "@app/state"
import {deriveNotification, SPACE_FILTERS} from "@app/notifications"
@@ -18,13 +20,19 @@
const notification = deriveNotification($page.url.pathname, SPACE_FILTERS, url)
const checkConnection = async () => {
ifLet(await checkRelayConnection(url), error => {
pushToast({theme: "error", message: error})
})
const connectionError = await checkRelayConnection(url)
ifLet(await checkRelayAuth(url, 30_000), error => {
pushToast({theme: "error", message: error})
})
if (connectionError) {
return pushToast({theme: "error", message: connectionError})
}
const [authError, accessError] = await Promise.all([checkRelayAuth(url), checkRelayAccess(url)])
const error = authError || accessError
if (error) {
pushModal(SpaceAuthError, {url, error})
}
}
// We have to watch this one, since on mobile the badge wil be visible when active