Skip to content

Conversation

@RUBY1232003
Copy link

πŸš€ Project Title
Authentication System for Trading Platform

Role: Backend Intern
Contributor: Ruby Rana


πŸ› οΈ Technologies Used

Stack Description
Node.js JavaScript runtime environment
Express.js web framework for Node.js
MongoDB NoSQL database to store user data
Mongoose ODM for MongoDB
JWT Authentication via token
dotenv Manages environment variables
express-validator Validates incoming request payloads

βš™οΈ Core Features

βœ… User Registration

  • Users can register by submitting:
    • fullName
    • email (must be unique)
    • password

πŸ” User Login

  • Validates credentials (email + password)
  • If valid, returns a JWT token valid for 1 hour
  • The token is used to authenticate future requests

πŸ”‘ Token-Based Authentication

  • JWT is used to manage sessions
  • Token is generated at login and sent in the Authorization header
  • Middleware verifies token validity

πŸ”’ Protected Route: /api/user/profile

  • Requires a valid JWT
  • Returns the authenticated user's profile (excluding password)
  • Ensures only logged-in users access their info

πŸ” Password Reset Flow

Step 1: POST /api/auth/reset-password

  • User submits email
  • Backend generates a short-lived reset token
  • Token is returned (in real apps, it would be emailed)

Step 2: POST /api/auth/new-password

  • User submits reset token and new password
  • Backend verifies token, updates password

πŸšͺ Logout Endpoint

  • Clears or invalidates token on frontend (for stateless JWT)
  • No token is returned on logout

πŸ§ͺ Testing Instructions

  • Use Postman, Thunder Client, or cURL
  • Set method and URL (e.g., POST http://localhost:3000/api/auth/register)
  • Set header: Content-Type: application/json
  • Pass body as raw JSON

πŸ§ͺ API Testing with Postman

βœ… Register API

register png

βœ… Login API

login png

βœ… Profile API

profile png

βœ… Reset Password API

resetpassword png

βœ… New password API

newpassword png

βœ… Logout API

logout png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant