Sha256: 28a40dc5c6d4956e538318c41c371879ed036905cd10c117e3e4226c0fd72852

Contents?: true

Size: 625 Bytes

Versions: 10

Compression:

Stored size: 625 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 => {
      console.log(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-0.0.72 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-0.0.71 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-0.0.70 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-0.0.69 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-0.0.68 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-0.0.67 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-0.0.66 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-0.0.65 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-0.0.64 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js
css-zero-0.0.63 lib/generators/css_zero/add/templates/app/javascript/controllers/otp_input_controller.js