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

cca-auth-module

v0.2.22

Published

A TypeScript project using pnpm as the package manager.

Readme

CCA Auth Module

Authentication + 2FA module for CCA applications. Provides a controller, use cases, and container wiring for login, registration, refresh, and 2FA flows.

Features

  • Login and admin login
  • Registration with role support
  • Refresh token rotation
  • Two-factor setup, enable, verify, disable
  • Middleware to require completed 2FA

Installation

pnpm add cca-auth-module

Quick Start

import { authConfig, createAuthContainer } from "cca-auth-module";

authConfig(async () => ({
  accessTokenSecret: process.env.ACCESS_TOKEN_SECRET!,
  refreshTokenSecret: process.env.REFRESH_TOKEN_SECRET!,
  accessTokenExpiry: "15m",
  refreshTokenExpiry: "30d",
  adminSecretPassword: process.env.ADMIN_SECRET_PASSWORD!,
  app_name: "MyApp",
  secretLength: "20",
  tokenWindow: "1",
  isDevelopment: false,
}));

const { authController, requireComplete2FA } = await createAuthContainer(database);

Configuration

The module reads configuration via authConfig and ConfigSource.

export interface IConfig {
  accessTokenSecret: string;
  refreshTokenSecret: string;
  accessTokenExpiry: string;
  refreshTokenExpiry: string;
  adminSecretPassword: string;
  app_name: string;
  secretLength: string;
  tokenWindow: string;
  isDevelopment: boolean;
}

API Endpoints

1) Login

POST /auth/login

Request:

{
  "email": "[email protected]",
  "password": "Password1!"
}

Response:

{
  "success": true,
  "message": "Login successful",
  "data": {
    "accessToken": "string",
    "userId": "string",
    "expiresAt": 1738166400,
    "auth": {
      "hasAccessToken": true,
      "enabled": false,
      "status": "pending_verification",
      "verified": false
    }
  },
  "meta": {
    "timestamp": "2026-01-29T10:00:00.000Z"
  }
}

2) Admin Login

POST /auth/admin-login

Request:

{
  "email": "[email protected]",
  "password": "Password1!",
  "adminPassword": "AdminSecret"
}

Response:

{
  "success": true,
  "message": "Admin login successful",
  "data": {
    "accessToken": "string",
    "userId": "string",
    "expiresAt": 1738166400,
    "auth": {
      "hasAccessToken": true,
      "enabled": true,
      "status": "pending_verification",
      "verified": false
    }
  }
}

3) Logout

POST /auth/logout

Headers:

Authorization: Bearer <accessToken>

Request:

{}

Response:

{
  "success": true,
  "message": "Logged out successfully",
  "data": {
    "auth": {
      "hasAccessToken": false,
      "enabled": false,
      "status": "logged_out",
      "verified": false
    }
  }
}

4) Register

POST /auth/register

Request:

{
  "email": "[email protected]",
  "name": "New User",
  "password": "Password1!",
  "role": "USER",
  "adminPassword": "optional-if-role-admin"
}

Response:

{
  "success": true,
  "message": "User registered successfully",
  "data": {
    "auth": {
      "hasAccessToken": false,
      "enabled": false,
      "status": "registered",
      "verified": false
    }
  },
  "meta": {
    "status": true
  }
}

5) Refresh Token

POST /auth/refresh-token

Request:

{
  "refreshToken": "yourRefreshToken"
}

Response:

{
  "success": true,
  "message": "Token refreshed successfully",
  "data": {
    "accessToken": "newAccessToken",
    "refreshToken": "newRefreshToken",
    "auth": {
      "hasAccessToken": true,
      "enabled": false,
      "status": "basic_auth",
      "verified": false
    }
  }
}

6) 2FA Setup

POST /auth/2fa/setup

Headers:

Authorization: Bearer <accessToken>

Response:

{
  "success": true,
  "message": "Two-factor authentication setup initiated",
  "data": {
    "qrCode": "data:image/png;base64,...",
    "auth": {
      "hasAccessToken": true,
      "enabled": false,
      "status": "needs_setup"
    }
  },
  "meta": {
    "nextStep": "Scan the QR code and enter your first code to verify",
    "redirectTo": "/2fa-enable"
  }
}

7) Enable 2FA

POST /auth/2fa/enable

Headers:

Authorization: Bearer <accessToken>

Request:

{
  "token": "2faToken"
}

Response:

{
  "success": true,
  "message": "Two-factor authentication enabled",
  "data": {
    "enabledAt": "2026-01-29T10:00:00.000Z",
    "auth": {
      "hasAccessToken": true,
      "enabled": true,
      "status": "pending_verification"
    }
  },
  "meta": {
    "nextStep": "Proceed to verify with a valid 2FA token",
    "redirectTo": "/verify-2fa"
  }
}

8) Verify 2FA

POST /auth/2fa/verify

Headers:

Authorization: Bearer <accessToken>

Request:

{
  "token": "2faVerificationToken"
}

Response:

{
  "success": true,
  "message": "Two-factor authentication verified successfully",
  "data": {
    "token": "accessToken",
    "refreshToken": "refreshToken",
    "user": {
      "id": "userId",
      "email": "[email protected]",
      "name": "User Name",
      "role": "USER"
    },
    "auth": {
      "hasAccessToken": true,
      "enabled": true,
      "status": "full_auth",
      "verified": true
    }
  },
  "meta": {
    "recommendation": "You're fully authenticated",
    "redirectTo": "/"
  }
}

9) Disable 2FA

POST /auth/2fa/disable

Headers:

Authorization: Bearer <accessToken>

Request:

{
  "token": "current2faToken"
}

Response:

{
  "success": true,
  "message": "Two-factor authentication disabled",
  "data": {
    "disabledAt": "2026-01-29T10:00:00.000Z",
    "auth": {
      "hasAccessToken": true,
      "enabled": false,
      "status": "basic_auth",
      "verified": false
    }
  },
  "meta": {
    "securityNote": "Account now relies only on password. Re-enable 2FA for better security.",
    "redirectTo": "/login"
  }
}

Middleware

Use RequireComplete2FA to block routes until the user completes 2FA. It expects a JWT with twoFactorAuthenticated: true.

app.get("/secure", requireComplete2FA.execute, handler);

Status Codes and Messages

  • Status codes are defined in src/presentation/constants/constants.ts
  • Error handling uses module errors from src/utils/Errors.ts

Notes

  • All token endpoints must be served over HTTPS in production.
  • Refresh tokens are rotated and validated against stored values.
  • Admin registration requires a valid adminSecretPassword.

License

MIT