How harshit977/user-authentication-system-with-nodejs works
Project type and purpose
• This is a standalone backend service (no separate frontend) providing user authentication APIs (signup, login, logout)
• It is built on Node.js/Express and uses MongoDB for persistence
• All token handling is home-grown: custom expirable tokens encrypted with the Node.js crypto module
File structure
• app.js: Express application entry point, wires up routes and middleware
• authenticate.js: authentication middleware that decrypts & validates tokens on protected endpoints
• encryption.js: module responsible for creating and decrypting expirable tokens
• routes/: Express routers
• user.js → public endpoints for register/login/logout
• protected.js → endpoints that require a valid token
• controllers/: business-logic handlers
• user.js → signup/login/logout workflows
• loggedin.js → logic for protected routes once authentication passes
• models/user.js: Mongoose schema & data-access for User collection
README for additional insights
• Custom tokens (not JWT) that embed an expiry, encrypted with a secret key
• No external auth libraries, everything built from scratch
• Uses ExpressJS middleware pattern, Mongoose for MongoDB
Detailed component breakdown
• “HTTP POST /user/signup” and “POST /user/login”
• “GET /protected/...” with Authorization header
1. ROUTES layer: /user, /protected
2. AUTH MIDDLEWARE: authenticate.js
3. CONTROLLERS: user.js, loggedin.js
4. ENCRYPTION SERVICE: encryption.js
5. MODELS (Mongoose): models/user.js
• User collection documents
• Client → Routes
• Routes → Controllers
• Controllers → Encryption Service (for token)
• Controllers → Models → DB
• Middleware → Encryption Service (token validation) → Controllers
• OPTIONAL: annotate token format (encrypted payload + expiry)