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 🙏

© 2025 – Pkg Stats / Ryan Hefner

cca-auth-module

v0.2.1

Published

A TypeScript project using pnpm as the package manager.

Readme

Auth Module Documentation

This module provides endpoints and methods for user authentication, including login, logout, registration, and token refresh operations. It also includes a helper function to verify tokens.

Note: This module expects proper request payloads and uses DTOs (LoginDTO and RegisterDTO) to enforce data structure. Custom error handling is assumed to be in place.


Endpoints

Auth API Documentation


1. Login

POST /auth/login

Request Body

{
  "email": "[email protected]",
  "password": "yourPassword"
}

Success Response

Status: 200 OK

{
  "success": true,
  "message": "Login successful",
  "data": {
    "accessToken": "string",
    "userId": "string",
    "expiresAt": "2025-08-06T12:00:00.000Z",
    "auth": {
      "hasAccessToken": true,
      "enable": false,
      "status": "BASIC_AUTH",
      "verified": false
    }
  },
  "meta": {
    "timestamp": "2025-08-06T11:59:59.999Z"
  }
}

2. Admin Login

POST /auth/admin-login

Request Body

{
  "email": "[email protected]",
  "password": "adminPassword",
  "adminPassword": "superSecretAdminPassword"
}

Success Response

Status: 201 Created

{
  "success": true,
  "message": "Admin login successful",
  "data": {
    "message": "Admin authenticated",
    "auth": {
      "hasAccessToken": true,
      "enable": false,
      "status": "BASIC_AUTH",
      "verified": false
    }
  }
}

3. Logout

POST /auth/logout

Request Body

{
  "id": "userId"
}

Success Response

Status: 200 OK

{
  "success": true,
  "message": "Logout successful",
  "data": {
    "auth": {
      "hasAccessToken": false,
      "enable": false,
      "status": "LOGGED_OUT",
      "verified": false
    }
  }
}

4. Register

POST /auth/register

Request Body

{
  "email": "[email protected]",
  "name": "New User",
  "password": "userPassword",
  "role": "user",
  "adminPassword": "optionalAdminPassword"
}

Success Response

Status: 200 OK

{
  "success": true,
  "message": "Registration successful",
  "data": {
    "auth": {
      "hasAccessToken": false,
      "enable": false,
      "status": "REGISTERED",
      "verified": false
    }
  },
  "meta": {
    "status": true
  }
}

5. Refresh Token

POST /auth/refresh-token

Request Body

{
  "refreshToken": "yourRefreshToken"
}

Success Response

Status: 200 OK

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

6. 2FA Setup

POST /auth/2fa/setup

Headers

Authorization: Bearer <accessToken>

Request Body

None

Success Response

Status: 200 OK

{
  "success": true,
  "message": "2FA setup successful",
  "data": {
    "qrCode": "data:image/png;base64,...",
    "auth": {
      "hasAccessToken": true,
      "enable": 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 Body

{
  "userId": "userId",
  "token": "2faToken"
}

Success Response

Status: 200 OK

{
  "success": true,
  "message": "2FA enabled successfully",
  "data": {
    "isEnabled": true,
    "enabledAt": "2025-08-06T12:00:00.000Z",
    "auth": {
      "hasAccessToken": true,
      "enable": true,
      "status": "PENDING_VERIFICATION"
    }
  },
  "meta": {
    "nextStep": "Proceed to verify with a valid 2FA token",
    "redirectTo": "/verify-2fa"
  }
}

8. Verify 2FA

POST /auth/2fa/verify

Request Body

{
  "userId": "userId",
  "token": "2faVerificationToken"
}

Success Response

Status: 200 OK

{
  "success": true,
  "message": "2FA verification successful",
  "data": {
    "token": "accessToken",
    "refreshToken": "refreshToken",
    "user": {
      "id": "userId",
      "email": "[email protected]",
      "name": "User Name",
      "role": "user"
    },
    "auth": {
      "hasAccessToken": true,
      "enable": 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 Body

{
  "token": "current2faToken"
}

Success Response

Status: 200 OK

{
  "success": true,
  "message": "2FA disabled successfully",
  "data": {
    "disabledAt": "2025-08-06T12:00:00.000Z",
    "auth": {
      "hasAccessToken": true,
      "enable": false,
      "status": "BASIC_AUTH",
      "verified": false
    }
  },
  "meta": {
    "securityNote": "Account now relies only on password. Re-enable 2FA for better security.",
    "redirectTo": "/login"
  }
}

Notes

  • All endpoints returning tokens require secure HTTPS connections.
  • 2FA setup, enable, verify, and disable require authentication with a valid access token (sent in the Authorization header).
  • Request bodies use DTOs as defined in the controller (LoginDTO, RegisterDTO, ITwoFactorEnable, ITwoFactorVerify, etc.).
  • Error responses will follow the format:
{
  "success": false,
  "error": "Error message"
}

License

This module is released under the MIT License.


This documentation provides an overview of the available endpoints and helper methods for authentication. For further details on business logic and DTO structures, please refer to the inline comments and source code within the module.