npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

otpless-next-js-auth-sdk

v1.0.10

Published

NextJs SDK for authenticating users.

Downloads

106

Readme

Merchant Integration Documentation(Backend Next JS Auth SDK)


A. OTPLessAuth Dependency

You can install the OTPLessAuth SDK using npm:

npm install otpless-next-js-auth-sdk

B. OTPLessAuth class

The OTPLessAuth Next.js SDK is a powerful library that enables you to perform authentication using the OTPLess service. This SDK simplifies the integration of OTPLess authentication into your Next.js applications.

Methods:


1. Verify Auth Token

This method help to resolve token which is issued by OTPLess which return user detail from that token also this method verify that token is valid, token should not expired and issued by only otpless.com

Method Signature:
const userDetail = await verifyToken(token, clientId, clientSecret);

Method Params:

| Params | Data type | Mandatory | Constraints | Remarks | | ------------ | --------- | --------- | ----------- | ---------------------------------- | | token | String | true | | token which you get from OTPLess | | clientId | String | true | | Your OTPLess Client Id | | clientSecret | String | true | | Your OTPLess Client Secret |

Return

Return: Object Name: UserDetail


2. Decode IdToken

This method help to resolve idToken(JWT token) which is issued by OTPLess which return user detail from that token also this method verify that token is valid, token should not expired and issued by only otpless.com

Method Signature:
const userDetail = await decodeIdToken(
  idToken,
  clientId,
  clientSecret
);

Method Params:

| Params | Data type | Mandatory | Constraints | Remarks | | ------------ | --------- | --------- | ----------- | ---------------------------------------------------------------------------- | | idToken | String | true | | idToken which is JWT token which you get from OTPLess by exchange code API | | clientId | String | true | | Your OTPLess Client Id | | clientSecret | String | true | | Your OTPLess Client Secret |

Return

Return: Object Name: UserDetail


3. Verify Code

This method help to resolve code which is return from OTPLess which will return user detail from that code also this method verify that code is valid, code should not expired and issued by only otpless.com

Method Signature:
const userDetail = await verifyCode(code, clientId, clientSecret);

Method Params:

| Params | Data type | Mandatory | Constraints | Remarks | | ------------ | --------- | --------- | ----------- | --------------------------------- | | code | String | true | | code which you get from OTPLess | | clientId | String | true | | Your OTPLess Client Id | | clientSecret | String | true | | Your OTPLess Client Secret |

Return

Return: Object Name: UserDetail


4. Magic Link

This method help to get magic link which is return from OTPLess which will return token and request id from that mobile number or email id. Issued by only otpless.com

Method Signature:
const magicLinkTokens = await magicLink(mobile, email, redirectURI, clientId, clientSecret);

Method Params:

| Params | Data type | Mandatory | Constraints | Remarks | | ------------ | --------- | --------- | ----------- | ----------------------------------------------------------------- | | mobile | String | false | | Input by your user. | | email | String | false | | Input by your user. | | redirectURI | String | true | | Your redirectURI. | | channel | String | false | | WHATSAPP/SMS (if no channel given WHATSAPP is chosen as default) | | clientId | String | true | | Your OTPLess Client Id | | clientSecret | String | true | | Your OTPLess Client Secret |

Return

Return: Object Name: magicLinkTokens


5. Send OTP

This method help to send OTP to your users and OTP issued by only otpless.com

Method Signature:
const response = await sendOTP(phoneNumber, email, channel, hash, orderId, expiry, otpLength, clientId, clientSecret);

Method Params:

| Params | Data type | Mandatory | Constraints | Remarks | | ------------ | --------- | --------- | ----------- | --------------------------------- | | phoneNumber | String | true | | Mobile Number of your users | | email | String | true | | Mail Id of your users | | channel | String | false | | WHATSAPP, SMS | | hash | String | true | | Your mobile application Hash | | orderId | String | true | | Unique Order id | | expiry | Int | false | | OTP expiry in sec | | otpLength | String | false | | Values like 6 or 4 | | clientId | String | true | | Your OTPLess Client Id | | clientSecret | String | true | | Your OTPLess Client Secret |

Return

success (boolean): This will be true in case of method successfully performed operation. errorMessage (String): The will be errorMessage in case of any error. orderId (String): This will be your Unique Order id. refId (String): The will be refId when OTP successfully send.


6. ReSend OTP

This method help to resend OTP to your users and OTP issued by only otpless.com

Method Signature:
const response = await resendOTP(orderId, clientId, clientSecret);

Method Params:

| Params | Data type | Mandatory | Constraints | Remarks | | ------------ | --------- | --------- | ----------- | --------------------------------------| | orderId | String | true | | Unique Order id(same as send method) | | clientId | String | true | | Your OTPLess Client Id | | clientSecret | String | true | | Your OTPLess Client Secret |

Return

success (boolean): This will be true in case of method successfully performed operation. errorMessage (String): The will be errorMessage in case of any error. orderId (String): This will be your Unique Order id. refId (String): The will be refId when OTP successfully send.


7. Verify OTP

This method help to Verify OTP to your users and OTP issued by only otpless.com

Method Signature:
const response = await verifyOTP(email, phoneNumber, orderId, otp, clientId, clientSecret);

Method Params:

| Params | Data type | Mandatory | Constraints | Remarks | | ------------ | --------- | --------- | ----------- | --------------------------------------| | email | String | true | | Mail Id of your users | | phoneNumber | String | true | | Mobile Number of your users | | orderId | String | true | | Unique Order id | | otp | String | true | | Enter otp here | | clientId | String | true | | Your OTPLess Client Id | | clientSecret | String | true | | Your OTPLess Client Secret |

Return

isOTPVerified (boolean): This will be true in case of OTP verified. reason (String): The will be errorMessage in case of OTP doesn't verified.


UserDetail Object Fields:

success (boolean): This will be true in case of method successfully performed operation. authTime (Long, required): The time when authentication was completed. phoneNumber (String, required): The user's phone number. countryCode (String, required): The country code of user's phone number. nationalPhoneNumber (String, required): The user's phone number without country code. email (String, required): The user's email address. name (String, required): The user's full name.

MagicLinkTokens Object Fields:

success (boolean): This will be true in case of method successfully performed operation. requestIds (List, required): List of Token and Type of AUth. type (String, required): Auth type. value (String, required): Token value.

Error case:

success (boolean): This will be false. The method is failed to perform. errorMessage (String): The message contains error information.

Example of usage

import { decodeIdToken } from 'otpless-next-js-auth-sdk';

const idToken = "..."; // Replace with your ID token
const clientId = "..."; // Replace with your client ID
const clientSecret = "..."; // Replace with your client secret

const userDetail = await decodeIdToken(idToken, clientId, clientSecret);
console.log("User Details:", userDetail);

This method allows you to decode and verify OTPLess tokens and retrieve user information for integration into your next js application.