Catalog npm
Back to packageRELEASE DETAILS

1.0.0

npm

2fauth

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

2faauthenticationexpressjwtoauth
Published20 Feb 2025
Direct dependencies10
Transitive dependenciesNot calculated

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.

Declared dependencies 10

Native requirements
10 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
cors
Environment
{
  "local_name": "cors",
  "alias": false,
  "peer_metadata": null
}
^2.8.5runtime
dotenv
Environment
{
  "local_name": "dotenv",
  "alias": false,
  "peer_metadata": null
}
^16.4.7runtime
qrcode
Environment
{
  "local_name": "qrcode",
  "alias": false,
  "peer_metadata": null
}
^1.5.4runtime
express
Environment
{
  "local_name": "express",
  "alias": false,
  "peer_metadata": null
}
^4.18.2runtime
bcryptjs
Environment
{
  "local_name": "bcryptjs",
  "alias": false,
  "peer_metadata": null
}
^2.4.3runtime
mongoose
Environment
{
  "local_name": "mongoose",
  "alias": false,
  "peer_metadata": null
}
^7.5.0runtime
speakeasy
Environment
{
  "local_name": "speakeasy",
  "alias": false,
  "peer_metadata": null
}
^2.0.0runtime
nodemailer
Environment
{
  "local_name": "nodemailer",
  "alias": false,
  "peer_metadata": null
}
^6.9.7runtime
jsonwebtoken
Environment
{
  "local_name": "jsonwebtoken",
  "alias": false,
  "peer_metadata": null
}
^9.0.0runtime
cookie-parser
Environment
{
  "local_name": "cookie-parser",
  "alias": false,
  "peer_metadata": null
}
^1.4.7runtime

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "ca233d7b53c2178278f5707aeaa81a3aceb99647",
  "tarball": "https://registry.npmjs.org/2fauth/-/2fauth-1.0.0.tgz",
  "fileCount": 7,
  "integrity": "sha512-d6EArc9VYYPpFYKxqnhCJG5Fr4qDe6wveqmJqqfI4Hzal9Md+BbIgRkE61GvAyvB9+7j0CYlCa+w+NFso6l8fA==",
  "signatures": [
    {
      "sig": "MEUCIQCdBFwewzFkP2npAChQI01O97LFrkdKSqAiXFrZ3jtHSQIgIpMY2thKQekBpW7ROURGaZIXRw3G2hUoKmnTO8q5zUA=",
      "keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"
    }
  ],
  "unpackedSize": 11698
}

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_version:10fd4ff3cc8bbcd1e2d52fe4fb0f434861a68586797aa76fcab50a1a1f0f6bc2

Other collected versions

1.0.321 Feb1.0.221 Feb1.0.120 FebView all collected versions →