From b7d4e5c4686bc8aac41d832567190002542a1743 Mon Sep 17 00:00:00 2001 From: Vika Date: Thu, 29 Sep 2022 22:39:28 +0300 Subject: companion-lite: port to TypeScript --- kittybox-rs/javascript/src/indieauth.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'kittybox-rs/javascript/src/indieauth.ts') diff --git a/kittybox-rs/javascript/src/indieauth.ts b/kittybox-rs/javascript/src/indieauth.ts index ef314e9..01732b7 100644 --- a/kittybox-rs/javascript/src/indieauth.ts +++ b/kittybox-rs/javascript/src/indieauth.ts @@ -1,3 +1,5 @@ +import { unreachable } from "./lib.js"; + const WEBAUTHN_TIMEOUT = 60 * 1000; interface KittyboxWebauthnPreRegistrationData { @@ -69,16 +71,19 @@ export async function submit_handler(e: SubmitEvent) { const form = e.target as HTMLFormElement; let scopes: Array; - if (form.elements.namedItem("scope") === undefined) { + let scope_elem = form.elements.namedItem("scope"); + if (scope_elem == null) { scopes = [] - } else if (form.elements.namedItem("scope") instanceof Node) { - scopes = ([form.elements.namedItem("scope")] as Array) + } else if (scope_elem instanceof Element) { + scopes = ([scope_elem] as Array) .filter((e: HTMLInputElement) => e.checked) .map((e: HTMLInputElement) => e.value); - } else { - scopes = (Array.from(form.elements.namedItem("scope") as RadioNodeList) as Array) + } else if (scope_elem instanceof RadioNodeList) { + scopes = (Array.from(scope_elem) as Array) .filter((e: HTMLInputElement) => e.checked) .map((e: HTMLInputElement) => e.value); + } else { + unreachable("HTMLFormControlsCollection returned something that's not null, Element or RadioNodeList") } const authorization_request = { -- cgit 1.4.1