Sha256: a52d8c69d4027a3f349cbaf9483c7471a20ec2963547b621722c8ffacbbdd25b

Contents?: true

Size: 594 Bytes

Versions: 10

Compression:

Stored size: 594 Bytes

Contents

import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  initialize() {
    this.abortController = new AbortController()
  }

  disconnect() {
    this.abortController.abort()
  }

  connect() {
    this.#supportsOTP && this.#requestOTP()
  }

  #requestOTP() {
    navigator.credentials.get(this.#options).then(otp => {
      this.element.value = otp.code
    }).catch(error => {})
  }

  get #options() {
    return { otp: { transport: ["sms"] }, signal: this.abortController.signal }
  }

  get #supportsOTP() {
    return "OTPCredential" in window
  }
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
css-zero-1.0.4 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-1.0.3 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-1.0.2 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-1.0.1 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-1.0.0 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-0.0.98 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-0.0.97 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-0.0.96 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-0.0.95 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-0.0.94 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js