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