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

auth-pro

v2.1.0

Published

This package contains different authentication methods.

Readme

auth-pro

A comprehensive TypeScript authentication package providing multiple authentication methods including basic password-based authentication, OTP verification, and OAuth social authentication.

Table of Contents

Features

  • 🔐 Secure Password Handling

    • PBKDF2-based password hashing
    • Configurable digest algorithm
    • Secure salt generation
  • 📧 OTP Authentication

    • 6-digit OTP generation
    • Email-based OTP delivery
    • Configurable OTP expiry (default: 5 minutes)
    • In-memory OTP storage with auto-expiry
  • 🔑 Social Authentication

    • Support for multiple OAuth providers
    • Customizable user data extraction
    • Access and refresh token handling
    • Built-in error handling
  • 🎟️ JWT Token Management

    • Token generation with customizable expiry
    • Token verification
    • Secure JWT secret key handling

Installation

npm install auth-pro

Environment Variables

Create a .env file with the following variables:

# JWT Configuration
JWT_SECRET_KEY=your_jwt_secret_key
DIGEST_ALGORITHM=sha512

# Email Configuration (for OTP)
MAIL_HOST=your_smtp_host
MAIL_USER=your_smtp_username
MAIL_PASS=your_smtp_password
MAIL_FROM=your_sender_email

# OAuth Configuration (for each provider)
PROVIDER_CLIENT_ID=your_oauth_client_id
PROVIDER_CLIENT_SECRET=your_oauth_client_secret
PROVIDER_REDIRECT_URI=your_oauth_redirect_uri
PROVIDER_TOKEN_URL=your_oauth_token_url
PROVIDER_USER_INFO_URL=your_oauth_user_info_url

Usage

Basic Authentication

import { hashUtil } from 'auth-pro';

// Generate salt for new user
const salt = hashUtil.createSalt();

// Hash password for storage
const hashedPassword = hashUtil.createHash('userPassword', salt);

// Verify password during login
const isValid = hashUtil.verifyHash(
  'inputPassword',
  hashedPassword,
  salt
);

OTP Authentication

import { otpService } from 'auth-pro';

// Generate and send OTP
await otpService.sendOTP('[email protected]');

// Verify OTP
const isValid = otpService.verifyOTP('[email protected]', '123456');

Social Authentication

import { authenticateOAuth } from 'auth-pro';

// Configure data extraction
const config = {
  extractUserData: (profile: any) => ({
    id: profile.id,
    email: profile.email,
    name: profile.name
  })
};

// Authenticate with OAuth provider
try {
  const authResponse = await authenticateOAuth(
    'authorization_code',
    config,
    'GITHUB' // or other provider
  );
  
  const { user, accessToken, refreshToken } = authResponse;
} catch (error) {
  if (error.code === 'TOKEN_ERROR') {
    // Handle token error
  }
}

Token Management

import { tokenUtil } from 'auth-pro';

// Generate JWT token
const token = tokenUtil.generateToken(
  { userId: '123', email: '[email protected]' },
  3600 // expires in 1 hour
);

// Verify token
try {
  const payload = tokenUtil.verifyToken(token);
} catch (error) {
  // Handle invalid token
}

Utilities

import { validator } from 'auth-pro';

// Validate email
const isValidEmail = validator.validateEmail('[email protected]');

API Reference

Hash Utilities

  • createSalt(): string - Generates a cryptographically secure random salt
  • createHash(value: string, salt: string): string - Creates a hash using PBKDF2
  • verifyHash(value: string, storedHash: string, salt: string): boolean - Verifies a value against stored hash

OTP Services

  • sendOTP(email: string): Promise<string> - Generates and sends OTP via email
  • verifyOTP(email: string, otp: string): boolean - Verifies provided OTP
  • generateOTP(): string - Generates a 6-digit OTP

Token Utilities

  • generateToken(payload: object, expiresIn?: number): string - Generates JWT token
  • verifyToken(token: string): object | string - Verifies and decodes JWT token

Social Authentication

  • authenticateOAuth(code: string, config: OAuthConfig, provider: string): Promise<OAuthResponse> - Handles OAuth authentication flow

Validators

  • validateEmail(email: string): boolean - Validates email format

License

ISC License


Created with ❤️ by Jay Vekariya