summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/toAuthenticatorAttachment.ts
blob: 366cf8f16d4cf606daecba379cb8ecf5058a7070 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
}