-
Create an App in OTPless dashboard and copy the
APP ID
-
Add OTPLESS Script as a function
Add the following code to your utils/initOtpless.js in root directory.
export const initOTPless = (callback) => { const otplessInit = Reflect.get(window, "otplessInit"); const loadScript = () => { const isScriptLoaded = document.getElementById("otpless-sdk"); if(isScriptLoaded) return; const script = document.createElement('script') script.id = 'otpless-sdk' script.type = 'text/javascript' script.src = 'https://otpless.com/v2/auth.js' script.setAttribute("data-appid", "PASTE_YOUR_APPID_HERE") document.body.appendChild(script); }; otplessInit ? otplessInit() : loadScript(); Reflect.set(window, "otpless", callback); };
-
Load the script in Login/Signup component and add callback function
Add following code in Login/Signup component.
retrive data using otplessUser object
useEffect(() => initOTPless(callback), []); const callback = (otplessUser) => { alert(JSON.stringify(otplessUser)); };
-
Add Otpless-login-page div
Add the following div in Login/Signup component.
<div id="otpless-login-page"></div>
Prerequisites: NodeJS
-
Install Packages
npm install
-
Run the demo
npm run dev
-
Open localhost:5173 in your browser
-
Switch branches to check out available options to integrate OTPless in your project