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

ivalt-react

v1.2.9

Published

React hooks for iVALT Biometric Authentication

Downloads

1,411

Readme

iVALT React - Biometric Authentication Package

A flexible React hooks package for integrating iVALT biometric authentication into your React applications.

INSTALLATION

To install the package, run one of the following commands:

npm install ivalt-react
# or
yarn add ivalt-react
# or
pnpm add ivalt-react

Additional dependencies (only if using the pre-built form component):

If you want to use the pre-built form component with Tailwind CSS, install these required libraries:

npm install intl-tel-input tailwindcss postcss autoprefixer

BASIC SETUP

  1. Initialize the package before use:
const initializeIValt = require("ivalt-react").initializeIValt;

initializeIValt({
  baseURL: "https://your-ivalt-api-url",
  apiKey: "your-api-key",
});
  1. If using the pre-built form component with Tailwind CSS, add to your CSS:
@tailwind base;
@tailwind components;
@tailwind utilities;

USING THE HOOK

The useBiometricAuth hook provides all necessary functionality for authentication:

const {
  status, // Current authentication status
  error, // Error object if any
  startAuth, // Function to start authentication
  stopPolling, // Function to stop polling
  userData, // User data after successful authentication
  isPolling, // Boolean indicating if currently polling
} = useBiometricAuth({
  requestFrom: "YourAppName", // Required: App identifier
  pollingInterval: 2000, // Optional: Default 2000ms
  maxAttempts: 150, // Optional: Default 150
  onSuccess: (userData) => {}, // Optional: Success callback
  onError: (error) => {}, // Optional: Error callback
});

HOOK CONFIGURATION OPTIONS

  • requestFrom: (Required) String - Application identifier
  • pollingInterval: (Optional) Number - Polling interval in milliseconds (default: 2000)
  • maxAttempts: (Optional) Number - Maximum polling attempts (default: 150)
  • onSuccess: (Optional) Function - Callback for successful authentication
  • onError: (Optional) Function - Callback for authentication errors

AUTHENTICATION STATES

  • idle: Initial state
  • requesting: Authentication request is being sent
  • polling: Waiting for user authentication
  • success: Authentication successful
  • error: Authentication failed

TYPE DEFINITIONS

interface UserData {
  id: string;
  name: string;
  email: string;
  mobile: string;
}

interface BiometricAuthHookResult {
  status: BiometricStatus;
  error: Error | null;
  startAuth: (mobile: string) => Promise<void>;
  stopPolling: () => void;
  userData: UserData | null;
  isPolling: boolean;
}

EXAMPLE USAGE

import { useBiometricAuth } from "ivalt-react";

function AuthComponent() {
const { status, error, startAuth, userData } = useBiometricAuth({
requestFrom: 'MyApp',
onSuccess: (data) => console.log('Success:', data),
onError: (err) => console.error('Error:', err)
});

    const handleSubmit = (phoneNumber) => {
        startAuth(phoneNumber);
    };

    return (
        // Your custom UI implementation
    );
}

Example of using the pre-built form component:

import { BiometricAuthForm } from "ivalt-react";

function App() {
  const handleAuthSuccess = (userData: any) => {
    console.log("Authentication successful:", userData);
  };

  return <BiometricAuthForm onSuccess={handleAuthSuccess} />;
}

ERROR HANDLING

The hook handles various error scenarios:

  • Network errors
  • Authentication timeout (after maxAttempts)
  • Invalid phone numbers
  • Server errors

Errors are available through:

  1. The error object in hook result
  2. The onError callback function

SECURITY BEST PRACTICES

  1. Store API keys securely
  2. Use HTTPS for all API communications
  3. Implement proper session management
  4. Follow security best practices for user data
  5. Never store sensitive data in local storage
  6. Always validate phone numbers before submission

TROUBLESHOOTING

Common issues:

  1. Authentication timeout: Check maxAttempts and pollingInterval
  2. Network errors: Verify API endpoint and connectivity
  3. Invalid phone format: Ensure proper phone number formatting
  4. Configuration errors: Verify initializeIValt setup

For additional support:

  • Check documentation at docs.ivalt.com
  • Submit issues at https://github.com/iVALT-Inc/ivalt-react/issues
  • Contact support at [email protected]

LICENSE

MIT License - See LICENSE file for details

Version: 1.0.4 Last Updated: 2024-11-11