0.0.2 • Published 3 years ago
otpless-test v0.0.2
otpless-js-sdk
Otpless-js-sdk is a vanilla javascript SDK used for authenticating users using OTPless in client side application. Demo video
Features
- Fetch WhatsApp intent and redirect users to WhatsApp.
- Get token from query params
- Get state from local storage
Getting Started
- Install the otpless-js-sdk from the npm repository.
npm i otpless-js-sdk- Initialize the sdk.
appIdis required.enableErrorLoggingis an optional parameter. On setting it to true, the error logs are consoled to the stderr.
import otplessSdk from "otpless-js-sdk";
const sdkIntance = new otplessSdk(
{
appId: "YOUR_APP_ID",
enableErrorLogging: true
}
);- create an Onclick function using
createGetIntentOnClick. It takesredirectionURLobject property as a parameter. This is the url to which the client is redirected to once it gets a response in WhatsApp.
<button
onClick={sdkIntance.createGetIntentOnClick({
redirectionURL: "YOUR_REDIRECTION_URL",
})}
>
Login with WhatsApp
</button>- After successfull redirection from WhatsApp, extract the token from query params using the static function
getTokenFromQueryParamsand the state from the local storage using the static functiongetState. The token along with the state needs to be passed to your server which in turn should make call to OTPless server for user details.
const token=otplessSdk.getTokenFromQueryParams();
const state=otplessSdk.getState()License
MIT
Made with ❤️ by OTPless