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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@thetechfossil/auth2

v1.2.22

Published

Authentication SDK for easy integration with Auth backend

Readme

Auth SDK

A lightweight, easy-to-use authentication SDK for integrating with the Auth backend service. Works with both Node.js and React/Next.js applications.

Features

  • Dual authentication methods (email/password or email/OTP)
  • Automatic token management
  • React hooks for easy integration
  • Pre-built UI components for login, registration, OTP verification, and email verification
  • TypeScript support
  • Works with both Node.js and browser environments
  • Supports custom frontend base URLs for email verification links
  • Embedded styling - No separate CSS imports required!

Documentation

📚 Complete documentation is available at: https://ktw-auth-docs.netlify.app/

The documentation includes:

  • Getting started guides
  • API reference
  • Component documentation
  • Architecture overview
  • Environment configuration
  • Integration examples for React, Next.js, and Node.js

Additional Guides

Installation

npm install @auth/sdk
# or
yarn add @auth/sdk
# or
pnpm add @auth/sdk

Usage

React/Next.js Integration

import { react } from '@auth/sdk';
const { useAuth } = react;

function App() {
  const { user, isAuthenticated, register, login, verify, logout } = useAuth({
    baseUrl: 'http://localhost:7000', // Your auth service URL
    localStorageKey: 'auth_token' // Optional, defaults to 'auth_token'
  });

  const handleRegister = async () => {
    try {
      // The SDK automatically detects the frontend base URL
      // You can optionally override it by passing frontendBaseUrl
      const response = await register({ 
        name: 'John Doe',
        email: '[email protected]',
        password: 'securepassword'
        // frontendBaseUrl: 'https://myapp.com' // Optional: custom base URL for email verification links
      });
      console.log('Registration successful:', response.message);
    } catch (error) {
      console.error('Registration failed:', error);
    }
  };

  // Email/Password Login
  const handlePasswordLogin = async () => {
    try {
      const response = await login({ 
        email: '[email protected]',
        password: 'securepassword'
      });
      console.log('Login successful:', response.message);
    } catch (error) {
      console.error('Login failed:', error);
    }
  };

  // Email/OTP Login - Step 1: Request OTP
  const handleRequestOtp = async () => {
    try {
      const response = await login({ email: '[email protected]' });
      console.log('OTP sent:', response.message);
    } catch (error) {
      console.error('Login failed:', error);
    }
  };

  // Email/OTP Login - Step 2: Verify OTP
  const handleVerifyOtp = async () => {
    try {
      const response = await login({ 
        email: '[email protected]', 
        otp: '123456' 
      });
      console.log('Verification successful:', response.message);
    } catch (error) {
      console.error('Verification failed:', error);
    }
  };

  if (isAuthenticated) {
    return (
      <div>
        <h1>Welcome, {user?.name}!</h1>
        <button onClick={logout}>Logout</button>
      </div>
    );
  }

  return (
    <div>
      <button onClick={handleRegister}>Register</button>
      <button onClick={handlePasswordLogin}>Login with Password</button>
      <button onClick={handleRequestOtp}>Request OTP</button>
      <button onClick={handleVerifyOtp}>Verify OTP</button>
    </div>
  );
}

Node.js Integration

import { node } from '@auth/sdk';
const { AuthClient } = node;

const authClient = new AuthClient({
  baseUrl: 'http://localhost:7000'
});

async function register() {
  try {
    const response = await authClient.register({ 
      name: 'John Doe',
      email: '[email protected]',
      password: 'securepassword',
      frontendBaseUrl: 'https://myapp.com' // Optional: custom base URL for email verification links
    });
    console.log('Registration successful:', response.message);
  } catch (error) {
    console.error('Registration failed:', error);
  }
}

// Email/Password Login
async function passwordLogin() {
  try {
    const response = await authClient.login({ 
      email: '[email protected]',
      password: 'securepassword'
    });
    console.log('Login successful:', response.message);
    // Save token manually in Node.js environment
    const token = response.token;
  } catch (error) {
    console.error('Login failed:', error);
  }
}

// Email/OTP Login - Step 1: Request OTP
async function requestOtp() {
  try {
    const response = await authClient.login({ email: '[email protected]' });
    console.log('OTP sent:', response.message);
  } catch (error) {
    console.error('Login failed:', error);
  }
}

// Email/OTP Login - Step 2: Verify OTP
async function verifyOtp() {
  try {
    const response = await authClient.login({ 
      email: '[email protected]', 
      otp: '123456' 
    });
    
    if (response.success) {
      console.log('Verification successful:', response.message);
      // Save token manually in Node.js environment
      const token = response.token;
    }
  } catch (error) {
    console.error('Verification failed:', error);
  }
}

Pre-built UI Components

The SDK includes pre-built UI components for common authentication flows with embedded styling:

import { react } from '@auth/sdk';
const { AuthFlow } = react;

function LoginPage() {
  const handleAuthComplete = () => {
    // Redirect to dashboard
    console.log('Authentication complete!');
  };

  return (
    <AuthFlow onAuthComplete={handleAuthComplete} />
  );
}

You can also use individual components:

import { react } from '@auth/sdk';
const { LoginForm, RegisterForm, OtpForm } = react;

function LoginPage() {
  return (
    <div>
      <LoginForm 
        onLoginSuccess={(email) => console.log('OTP sent to:', email)}
        onRegisterClick={() => console.log('Navigate to registration')}
      />
    </div>
  );
}

Note: As of version 1.2.0, all styling is embedded directly in the components. No separate CSS imports are required!