summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/authentication/mount_2fa.js
blob: ebdcd1e074d7f906acef34495b1e86b2c6f9f516 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import $ from 'jquery';
import initU2F from './u2f';
import U2FRegister from './u2f/register';
import initWebauthnAuthentication from './webauthn';
import WebAuthnRegister from './webauthn/register';

export const mount2faAuthentication = () => {
  if (gon.webauthn) {
    initWebauthnAuthentication();
  } else {
    initU2F();
  }
};

export const mount2faRegistration = () => {
  const el = $('#js-register-token-2fa');

  if (!el.length) {
    return;
  }

  if (gon.webauthn) {
    const webauthnRegister = new WebAuthnRegister(el, gon.webauthn);
    webauthnRegister.start();
  } else {
    const u2fRegister = new U2FRegister(el, gon.u2f);
    u2fRegister.start();
  }
};