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

authlite

v0.0.3

Published

Lightweight authentication library with 2FA (TOTP/Email) and Google OAuth support

Downloads

376

Readme

AuthLite

Lightweight authentication library with 2FA (TOTP) and Google OAuth support for Node.js applications.

Installation

yarn add authlite
# or
npm install authlite

Quick Start

import { AuthLite } from 'authlite';

const auth = new AuthLite({
  appName: 'MyApp',
  encryptionKey: process.env.MFA_ENCRYPTION_KEY!, // Must be exactly 32 characters
  google: {
    webClientId: process.env.GOOGLE_WEB_CLIENT_ID,
    iosClientId: process.env.GOOGLE_IOS_CLIENT_ID,
    androidClientId: process.env.GOOGLE_ANDROID_CLIENT_ID,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET || '',
    redirectUri: process.env.GOOGLE_REDIRECT_URI || '',
  },
});

Google OAuth

// For Web clients (pass the Access Token):
const googleUser = await auth.google.verify(accessToken, 'web');

// For Mobile clients (pass the ID Token):
const googleUser = await auth.google.verify(idToken, 'ios'); // or 'android'

// Returns:
// {
//   email: string,
//   name: string,
//   picture: string,
//   googleId: string
// }

MFA (Two-Factor Authentication)

Enrollment

const { encryptedSecret, qrCode, backupCodes } = await auth.mfa.createEnrollment(user.email);

// Save to database
user.mfaSecret = encryptedSecret;
user.mfaBackupCodes = backupCodes; // Hash these before storing
await user.save();

// Send qrCode (data URL) to frontend for display

Verification

const isValid = auth.mfa.verifyTotp({
  token: userInputCode,
  secret: user.mfaSecret, // Pass encrypted secret directly
});

if (!isValid) {
  throw new Error('Invalid code');
}

Backup Codes

// Generate backup codes
const { plainCodes, hashedCodes } = auth.mfa.generateBackupCodes();

// Store hashedCodes in database, show plainCodes to user once

// Verify a backup code
const codeIndex = auth.mfa.verifyBackupCode(userInputCode, user.hashedBackupCodes);
if (codeIndex !== -1) {
  // Valid - remove used code
  user.hashedBackupCodes.splice(codeIndex, 1);
  await user.save();
}

Configuration

| Option | Type | Required | Description | | ------------------------ | -------- | -------- | ---------------------------------------------- | | appName | string | Yes | Application name (shown in authenticator apps) | | encryptionKey | string | Yes | 32-character key for AES-256-GCM encryption | | google.webClientId | string | No | Google OAuth client ID for web | | google.iosClientId | string | No | Google OAuth client ID for iOS | | google.androidClientId | string | No | Google OAuth client ID for Android |

Error Handling

import {
  AuthLiteError,
  ConfigurationError,
  EncryptionError,
  VerificationError,
  GoogleAuthError,
} from 'authlite';

try {
  await auth.google.verify(token, 'web');
} catch (error) {
  if (error instanceof GoogleAuthError) {
    // Handle Google auth failure
  }
}

Advanced Usage

Access Individual Services

import { MfaModule, TotpService, EncryptionService } from 'authlite';

// Create standalone services if needed
const encryption = new EncryptionService('your-32-character-key-here!!!');
const encrypted = encryption.encrypt('secret-data');
const decrypted = encryption.decrypt(encrypted);

Constants

import { TOTP_CONFIG, ENCRYPTION_CONFIG, BACKUP_CODES_CONFIG } from 'authlite';

console.log(TOTP_CONFIG.DIGITS); // 6
console.log(BACKUP_CODES_CONFIG.COUNT); // 10

License

MIT