diff options
author | Vika <vika@fireburn.ru> | 2022-09-29 22:39:28 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2022-09-29 22:39:28 +0300 |
commit | b7d4e5c4686bc8aac41d832567190002542a1743 (patch) | |
tree | 6a42a990fbb06057a64de5f68175f94c3637c2c7 /kittybox-rs/javascript/src | |
parent | b3508ccb146648950ed392b517d12354203c4347 (diff) | |
download | kittybox-b7d4e5c4686bc8aac41d832567190002542a1743.tar.zst |
companion-lite: port to TypeScript
Diffstat (limited to 'kittybox-rs/javascript/src')
-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); +} |