diff options
Diffstat (limited to 'kittybox-rs/javascript')
-rw-r--r-- | kittybox-rs/javascript/src/indieauth.ts | 15 | ||||
-rw-r--r-- | kittybox-rs/javascript/src/lib.ts | 3 |
2 files changed, 13 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 = { diff --git a/kittybox-rs/javascript/src/lib.ts b/kittybox-rs/javascript/src/lib.ts new file mode 100644 index 0000000..38ba65b --- /dev/null +++ b/kittybox-rs/javascript/src/lib.ts @@ -0,0 +1,3 @@ +export function unreachable(msg: string): never { + throw new Error(msg); +} |