diff options
Diffstat (limited to 'kittybox-rs/javascript/src/indieauth.ts')
-rw-r--r-- | kittybox-rs/javascript/src/indieauth.ts | 15 |
1 files changed, 10 insertions, 5 deletions
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<string>; - 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<HTMLInputElement>) + } else if (scope_elem instanceof Element) { + scopes = ([scope_elem] as Array<HTMLInputElement>) .filter((e: HTMLInputElement) => e.checked) .map((e: HTMLInputElement) => e.value); - } else { - scopes = (Array.from(form.elements.namedItem("scope") as RadioNodeList) as Array<HTMLInputElement>) + } else if (scope_elem instanceof RadioNodeList) { + scopes = (Array.from(scope_elem) as Array<HTMLInputElement>) .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 = { |