UNPKG

vue-web-otp

Version:

Verify phone numbers on the vue web applications

32 lines (31 loc) 873 B
import { defineComponent as s, ref as l, onMounted as i, onBeforeUnmount as c, renderSlot as u } from "vue"; const d = /* @__PURE__ */ s({ __name: "VueWebOtp", emits: ["input"], setup(m, { expose: r, emit: a }) { const n = l(null), o = () => { var e; return (e = n.value) == null ? void 0 : e.abort(); }; return i(() => { if ("OTPCredential" in window) { const e = new AbortController(); n.value = e, navigator.credentials.get({ otp: { transport: ["sms"] }, signal: e.signal }).then((t) => { a("input", (t == null ? void 0 : t.code) ?? ""); }).catch((t) => { console.log(t); }); } }), c(() => { o(); }), r({ abort: o }), (e, t) => u(e.$slots, "default", { autocomplete: "one-time-code" }); } }); export { d as VueWebOtp };