Skip to content

A simple library to automatically generate and validate OTP codes for your website.

Notifications You must be signed in to change notification settings

Vesal-J/autowebotp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Auto Web OTP

A simple library to automatically take and validate OTP codes for your website.

Installation

npm install autowebotp

Usage

React

import { webotp } from "autowebotp"
import { useEffect, useState } from "react"

export default function Home() {
  const [otp, setOtp] = useState<string>("");

  useEffect(() => {
    const abortWebOTP = webotp((receivedOtp) => {
      console.log("OTP received:", receivedOtp);
      setOtp(receivedOtp);
      alert(`OTP received: ${receivedOtp}`);
    });

    // Clean up function
    return () => {
      abortWebOTP();
    };
  }, []);

  return (
    <>
      <input 
        type="text" 
        autoComplete="one-time-code" 
        inputMode="numeric" 
        className="border-2"
        value={otp}
        onChange={(e) => setOtp(e.target.value)}
      />
    </>
  )
}