1.0.7 • Published 4 months ago

otp-whatsapp-auth v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Dokumentasi OTP Service

Pendahuluan

OTP Service adalah library Node.js yang memungkinkan pembuatan, verifikasi, dan pengiriman OTP melalui WhatsApp dan Email. Pengguna dapat memilih metode autentikasi yang digunakan saat melakukan instansiasi.

Instalasi

Pastikan Anda memiliki Node.js terinstal, lalu jalankan perintah berikut:

npm install otp-whatsapp-auth

Penggunaan

Import Library

import OTPService from "otp-whatsapp-auth";

Konfigurasi dan Inisialisasi

Anda dapat memilih metode autentikasi yang digunakan dengan menyertakan opsi typeAuth dalam bentuk array.

import OTPService from "otp-whatsapp-auth";

const phone  = "6285121040470";

const otpService = new OTPService({
  typeAuth: ["whatsapp"],
});

otpService.on("ready", async () => {
  const otp = otpService.generateOTP(phone);
  await otpService.sendWhatsapp(phone, otp);
});

Jika hanya satu metode yang digunakan, cukup isi satu elemen dalam array typeAuth:

const otpService = new OTPService({ typeAuth: ["email"] });

Generate OTP

const otp = otpService.generateOTP("user@example.com");
console.log("OTP yang dihasilkan:", otp);

Verifikasi OTP

const isValid = otpService.verifyOTP("user@example.com", "123456");
console.log("OTP Valid:", isValid);

Mengirim OTP ke WhatsApp

otpService.sendWhatsapp("6281234567890", "123456");

Mengirim OTP ke Email

otpService.sendEmail("user@example.com", "123456");

Konfigurasi Tambahan

OpsiTipeDefaultDeskripsi
digitsNumber6Jumlah digit dalam OTP
periodNumber60Waktu validitas OTP (detik)
windowNumber1Toleransi waktu validasi OTP
typeAuthArray["email", "whatsapp"]Metode pengiriman OTP
emailConfigObjectnullKonfigurasi SMTP untuk pengiriman email OTP

Event

WhatsApp Client Ready

Ketika WhatsApp siap digunakan, event ready akan dipicu:

otpService.whatsappClient.on("ready", () => {
  console.log("WhatsApp bot siap!");
});

Kesimpulan

OTP Service adalah solusi sederhana dan fleksibel untuk mengelola OTP di aplikasi Node.js dengan dukungan WhatsApp dan Email. Gunakan dengan bijak untuk keamanan aplikasi Anda!

1.0.7

4 months ago

1.0.6

4 months ago

1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago