summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2022-12-27 19:21:46 -0800
committerMatthew Miller <matthew@millerti.me>2022-12-27 19:21:46 -0800
commit3170379c67a9cf33374d9f9ab89dafed16ba7edf (patch)
tree9bcbfcce2a3c1e24b2ee524e88f6c3416eae56a6 /packages/browser/src/helpers
parent0571dbea85f539b350e853e716ba5489c49646c5 (diff)
Update startRegistration to use new values
Diffstat (limited to 'packages/browser/src/helpers')
-rw-r--r--packages/browser/src/helpers/toAuthenticatorAttachment.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/packages/browser/src/helpers/toAuthenticatorAttachment.ts b/packages/browser/src/helpers/toAuthenticatorAttachment.ts
new file mode 100644
index 0000000..7a2aca0
--- /dev/null
+++ b/packages/browser/src/helpers/toAuthenticatorAttachment.ts
@@ -0,0 +1,18 @@
+import { AuthenticatorAttachment } from '@simplewebauthn/typescript-types';
+
+const attachments: AuthenticatorAttachment[] = ['cross-platform', 'platform'];
+
+/**
+ * If possible coerce a `string` value into a known `AuthenticatorAttachment`
+ */
+export function toAuthenticatorAttachment(attachment: string | null): AuthenticatorAttachment | undefined {
+ if (!attachment) {
+ return;
+ }
+
+ if (attachments.indexOf(attachment as AuthenticatorAttachment) < 0) {
+ return;
+ }
+
+ return attachment as AuthenticatorAttachment;
+}