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

@launchlense-ai/authmiddleware-react

v1.0.0

Published

`AuthMiddlewareService` is an npm package for managing authentication via various API endpoints. It provides methods for login, OTP initialization, verification, and authorization.

Downloads

6

Readme

AuthMiddlewareService

AuthMiddlewareService is an npm package for managing authentication via various API endpoints. It provides methods for login, OTP initialization, verification, and authorization.

Installation

To use AuthMiddlewareService in your React project, install it via npm:

npm install @launchlense-ai/authmiddleware-react

Usage

Get API Access keys

  1. Login/Signup to https://portal.amw.launchlense.tech.
  2. Create a new Project.
  3. You will get a access token as soon as you create a project. (!!!Do not loose the access token!!!)

Import the Service

First, import the AuthMiddlewareService class into your React component:

import AuthMiddlewareService from 'AuthMiddlewareService';

Initialize the Service

Create an instance of AuthMiddlewareService and initialize it with your access key:

const authService = new AuthMiddlewareService();
authService.initAuthMiddleware('your-access-key-here');

Replace 'your-access-key-here' with your actual access key.

API Methods

1. loginWithEmail

Logs in a user with email and password.

authService.loginWithEmail(
  '[email protected]',
  'password123',
  (response) => {
    console.log('Login successful:', response);
  },
  (error) => {
    console.error('Login failed:', error);
  }
);

Parameters:

  • email - The user's email address.
  • password - The user's password.
  • onSuccess - Callback function to handle a successful response.
  • onError - Callback function to handle an error response.

2. initLogin

Initializes the login process and optionally supports MFA.

authService.initLogin(
  'contact_number_or_email',
  6,
  (response) => {
    console.log('Initialization successful:', response);
  },
  (error) => {
    console.error('Initialization failed:', error);
  },
  true, // isMfa
  ['SMS', 'Email'], // mfaTypes
  'otp' // authType
);

Parameters:

  • contact - The user's contact number or email.
  • otpLength - The length of the OTP.
  • onSuccess - Callback function to handle a successful response.
  • onError - Callback function to handle an error response.
  • isMfa - Whether multi-factor authentication is enabled (default is false).
  • mfaTypes - List of MFA types (optional).
  • authType - The type of authentication ('otp' or other types).

3. verifyAuth

Verifies the user's authentication using OTP or biometrics.

authService.verifyAuth(
  'contact_number_or_email',
  '123456',
  (response) => {
    console.log('Verification successful:', response);
  },
  (error) => {
    console.error('Verification failed:', error);
  },
  false, // isBiometric
  {} // biometricsInput
);

Parameters:

  • contact - The user's contact number or email.
  • password - The OTP or password.
  • onSuccess - Callback function to handle a successful response.
  • onError - Callback function to handle an error response.
  • isBiometric - Whether biometric authentication is used (default is false).
  • biometricsInput - Input for biometric verification (optional).

4. authorizeUser

Authorizes a user with a given token.

authService.authorizeUser(
  'user_token',
  (response) => {
    console.log('Authorization successful:', response);
  },
  (error) => {
    console.error('Authorization failed:', error);
  }
);

Parameters:

  • token - The token to authorize the user.
  • onSuccess - Callback function to handle a successful response.
  • onError - Callback function to handle an error response.

Example

Here’s a full example of using the AuthMiddlewareService in a React component:

import React, { useEffect, useState } from 'react';
import AuthMiddlewareService from 'AuthMiddlewareService';

const authService = new AuthMiddlewareService();

function App() {
  const [message, setMessage] = useState('');
  const [error, setError] = useState('');

  useEffect(() => {
    authService.initAuthMiddleware('your-access-key-here');

    const onSuccess = (response) => {
      setMessage(`Success: ${JSON.stringify(response)}`);
    };

    const onError = (error) => {
      setError(`Error: ${error}`);
    };

    authService.loginWithEmail('[email protected]', 'password123', onSuccess, onError);
  }, []);

  return (
    <div>
      <h1>AuthMiddlewareService Test</h1>
      {message && <p>{message}</p>}
      {error && <p style={{ color: 'red' }}>{error}</p>}
    </div>
  );
}

export default App;

License

MIT License. See the LICENSE file for details.