Catalog npm
PACKAGE EXPLORERView in registry

2fauth

npm

A plug-and-play authentication system with JWT, 2FA, and OAuth.

2faauthenticationexpressjwtoauth
Versions collected4
Direct dependencies10From release 1.0.3
Last observed20 Oct, 19:13 UTC

README

Current package documentation

2FAuth - Secure Authentication with JWT & 2FA

npm license downloads

🚀 2FAuth is a plug-and-play authentication system for Node.js/Express apps, featuring:
✅ User Registration & Login
✅ JWT Authentication
✅ Email Verification
✅ Two-Factor Authentication (2FA)
✅ Password Reset


🏗️ Installation

Install 2FAuth via NPM:

npm install 2fauth

🚀 Usage

Import and initialize authentication in your Express app:

const express = require("express");
const { initAuth } = require("2fauth");

const app = express();

app.use(
  initAuth({
    mongoUrl: "mongodb+srv://your-mongo-db",
    jwtSecretKey: "your-secret-key",
    emailConfig: {
      fromEmail: "noreply@example.com",
      transportOptions: {
        service: "gmail",
        auth: {
          user: process.env.EMAIL_USER,
          pass: process.env.EMAIL_PASSWORD,
        },
      },
    },
  })
);

app.listen(5000, () => console.log("Auth system running!"));

📡 API Endpoints

MethodEndpointDescription
POST/auth/registerRegister a new user
GET/auth/verify-emailVerify user email
GET/auth/resend-verificationVerify user email
POST/auth/loginUser Login
POST/auth/enable-2faEnable 2FA (Generates QR code)
POST/auth/disable-2faDisable 2FA
POST/auth/verify-2faVerify OTP for 2FA
POST/auth/logoutLogout the user
POST/auth/forgot-passwordInitiate password reset
POST/auth/reset-passwordReset password
PUT/auth/change-passwordChange the current password
GET/auth/current-userFetch Current User
PUT/auth/update-user/:userIdUpdate the current user

🚀 Usage Examples

🔹 Register a New User

curl -X POST http://localhost:8000/auth/register \
     -H "Content-Type: application/json" \
     -d '{
           "name": "John Doe",
           "email": "johndoe@example.com",
           "password": "securepassword"
         }'

📌 Response (Success)

{
  "success": true,
  "message": "User registered successfully. Please verify your email"
}

🔹 Login a User

curl -X POST http://localhost:8000/auth/login \
     -H "Content-Type: application/json" \
     -d '{
           "email": "johndoe@example.com",
           "password": "securepassword"
         }'

📌 Response (Success)

{
  "success": true,
  "message": "Login Successful"
}

🤝 Contributing

Contributions are welcome! If you find a bug or want to add a feature, feel free to open an issue or submit a PR.

⚖️ License

MIT License - Free to use and modify!

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 4

Collected releases
VersionPublishedDirect dependenciesOpen version
1.0.3Registry latest21 Feb 202510
1.0.221 Feb 202510
1.0.120 Feb 202510
1.0.020 Feb 202510

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
hemantbhatiahb/npm-2fa

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:13 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:d5f36c1e7b79e9fd2ff56d7144ef81168040b1901ff6740d5149aa302e8db6ea