web-otp-angular
Version:
Angular library to automatically detect OTP from mobile device (Both mobile web site and Desktop)
74 lines (68 loc) • 2.86 kB
JavaScript
import * as i0 from '@angular/core';
import { Directive, Input, NgModule } from '@angular/core';
class WebOtpDirective {
constructor(el) {
this.el = el;
this.ac = new AbortController();
this.timer = null;
}
;
ngOnInit() {
const options = {
otp: { transport: ['sms'] },
signal: this.ac.signal
};
navigator.credentials.get(options).then((otp) => {
this.el.nativeElement.value = otp.code;
}).catch(err => {
console.log(err);
});
if (this.timeout) {
this.timer = setTimeout(() => {
this.ac.abort();
}, this.timeout);
}
}
ngOnDestroy() {
this.ac.abort();
if (this.timer) {
clearTimeout(this.timer);
}
}
}
WebOtpDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WebOtpDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
WebOtpDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.12", type: WebOtpDirective, selector: "[appWebOtp]", inputs: { timeout: "timeout" }, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WebOtpDirective, decorators: [{
type: Directive,
args: [{
selector: '[appWebOtp]',
}]
}], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { timeout: [{
type: Input,
args: ['timeout']
}] } });
class WebOtpAngularModule {
}
WebOtpAngularModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WebOtpAngularModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
WebOtpAngularModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.12", ngImport: i0, type: WebOtpAngularModule, declarations: [WebOtpDirective], exports: [WebOtpDirective] });
WebOtpAngularModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WebOtpAngularModule });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WebOtpAngularModule, decorators: [{
type: NgModule,
args: [{
declarations: [
WebOtpDirective,
],
imports: [],
exports: [
WebOtpDirective,
]
}]
}] });
/*
* Public API Surface of web-otp-angular
*/
/**
* Generated bundle index. Do not edit.
*/
export { WebOtpAngularModule, WebOtpDirective };
//# sourceMappingURL=web-otp-angular.mjs.map