Skip to content

Conversation

@AnirudhPhophalia
Copy link
Contributor

Backend Authentication & User Management

This update adds a secure authentication system and user management to the IdeaVault backend, making it ready for production use.

Features Implemented

  • User Model: Mongoose schema for users with name, email, password, and timestamps. Passwords are hashed using bcrypt.
  • Authentication Routes:
    • POST /auth/register: Register a new user, validate input, hash password, and set JWT cookie.
    • POST /auth/login: Authenticate user, validate input, compare password, and set JWT cookie.
    • GET /auth/logout: Clear JWT cookie to log out user.
    • GET /auth/me: Fetch current logged-in user data (protected route).
  • Security:
    • JWT tokens stored in HTTP-only cookies for secure session management.
    • Passwords hashed with bcrypt before saving to the database.
    • Auth middleware to protect private routes and verify JWT tokens.
    • Input validation using express-validator for all auth endpoints.
  • MongoDB Integration: All user data is stored and managed using MongoDB via Mongoose.

Security Best Practices

  • Passwords are never stored in plain text.
  • JWT tokens are sent as HTTP-only cookies.
  • All user input is validated before processing.

@vinit105 vinit105 merged commit 41abc7a into vinit105:main Aug 17, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants