Skip to content

Feature/implement backend auth#149

Open
udaykiran243 wants to merge 3 commits intoBDutta18:mainfrom
udaykiran243:feature/implement-backend-auth
Open

Feature/implement backend auth#149
udaykiran243 wants to merge 3 commits intoBDutta18:mainfrom
udaykiran243:feature/implement-backend-auth

Conversation

@udaykiran243
Copy link
Contributor

@udaykiran243 udaykiran243 commented Feb 25, 2026

[FEATURE] Implement Backend with MongoDB and Authentication

closes #148

Description

This PR addresses issue #148 by introducing a dedicated Node.js/Express backend connected to a MongoDB database. It implements secure user authentication (JWT-based) and fully integrates it with the frontend React application, providing a robust foundation for user management and future scalability.

Changes Made

  • Backend Setup:
    • Initialized an Express server in server/index.js with MongoDB connection via Mongoose.
    • Configured strict environment checks using .env file.
  • Database & Models:
    • Created User model (server/models/User.js) with comprehensive schema validation.
    • Implemented secure password hashing using bcryptjs.
  • Authentication API:
    • Developed RESTful endpoints for user registration, login, and profile retrieval (/api/auth/register, /api/auth/login, /api/auth/me).
    • Added JWT-based authentication middleware (server/middleware/authMiddleware.js) to protect routes.
  • Frontend Integration:
    • Completely refactored AuthContext.jsx to communicate with the new backend API endpoints.
    • Enhanced Auth.jsx (Sign Up/Login page) with modern UI feedback (success messages, automatic redirection).
    • Updated Profile.jsx to include a functional Logout button that redirects to the home page.
    • Secured routes (Profile, Orders, Checkout) using ProtectedRoute to prevent unauthorized access.
  • Documentation:
    • Updated README.md with clear instructions on how to set up and run the backend server alongside the frontend.

Getting Started (How to Run)

To run this PR locally, please follow these steps:

1. Install Dependencies

Make sure you are in the root directory and install all required packages:

npm install

2. Environment Configuration

Create a .env file in the root directory and add your MongoDB connection string and a secret key for JWT:

MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
PORT=3001

3. Run the Application

npm run dev:all

@vercel
Copy link

vercel bot commented Feb 25, 2026

@udaykiran243 is attempting to deploy a commit to the bdutta18's projects Team on Vercel.

A member of the Team first needs to authorize it.

@udaykiran243
Copy link
Contributor Author

https://drive.google.com/file/d/1Fr_VAneWI3fpzxBvkiDWoV7_8xU4U559/view?usp=sharing
The video is bit long so i uploaded the drive link.

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.

Implement Backend with MongoDB and Authentication

1 participant